diff --git a/Cargo.toml b/Cargo.toml index e109ffc..242bf96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,8 @@ name = "livevue-rs" version = "0.1.0" edition = "2021" +# Run the todo example with: cargo run --example todo + [dependencies] axum = { version = "0.7", features = ["macros"] } tokio = { version = "1", features = ["full"] } diff --git a/src/app/about.rs b/examples/todo/about.rs similarity index 97% rename from src/app/about.rs rename to examples/todo/about.rs index c696b5b..10edea8 100644 --- a/src/app/about.rs +++ b/examples/todo/about.rs @@ -1,4 +1,4 @@ -use crate::framework::context::RenderContext; +use livevue_rs::RenderContext; use maud::{html, Markup}; /// Second page component: a simple "About" page. diff --git a/src/app/mod.rs b/examples/todo/app.rs similarity index 78% rename from src/app/mod.rs rename to examples/todo/app.rs index 20d8894..554fa0f 100644 --- a/src/app/mod.rs +++ b/examples/todo/app.rs @@ -1,37 +1,15 @@ -pub mod about; -pub mod queries; -pub mod todo_list; - -use crate::framework::connection::{ConnectionManager, SubscriptionRegistry}; -use crate::framework::context::{ComponentTree, RenderContext}; -use crate::framework::signal::SignalStore; -use crate::framework::sse::{format_patch_elements, format_patch_signals}; +use livevue_rs::{ + AppState, CacheKey, ComponentTree, RenderContext, SharedState, SignalStore, + format_patch_elements, format_patch_signals, sse_handler, +}; use axum::extract::{Query as AxumQuery, State}; use axum::http::header; -use axum::response::sse::{Event, KeepAlive, Sse}; use axum::response::{Html, IntoResponse}; use axum::routing::{get, post}; use axum::{Json, Router}; -use std::convert::Infallible; -use std::sync::Arc; -use tokio::sync::mpsc; -use tokio_stream::wrappers::ReceiverStream; use uuid::Uuid; -// --------------------------------------------------------------------------- -// Shared application state -// --------------------------------------------------------------------------- - -/// All shared state, wrapped in Arc for axum's State extractor. -pub struct AppState { - pub db: sqlx::SqlitePool, - pub connections: ConnectionManager, - pub subscriptions: SubscriptionRegistry, -} - -pub type SharedState = Arc; - // --------------------------------------------------------------------------- // Router // --------------------------------------------------------------------------- @@ -83,7 +61,7 @@ fn document_shell(conn_id: Uuid, initial_signals: &str, inner_html: &str) -> Str - LiveVue.rs Demo + LiveVue.rs — Todo