Clearing up some of the flood of warnings for unused imports etc. that have come up as I've shifted around implementations
This commit is contained in:
parent
fc5ef03c30
commit
3f7e7193ea
|
@ -9,6 +9,6 @@ crate-type = ["cdylib", "rlib"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
console_log = "0.2"
|
console_log = "0.2"
|
||||||
hackernews-app = { path = "../hackernews-app", default-features = false, features = ["hydrate"] }
|
hackernews-app = { path = "../hackernews-app", default-features = false, features = ["hydrate"] }
|
||||||
leptos = { path = "../../../leptos", features = ["hydrate"] }
|
leptos = { path = "../../../leptos", default-features = false, features = ["hydrate"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
wee_alloc = "0.4"
|
wee_alloc = "0.4"
|
|
@ -1,12 +1,11 @@
|
||||||
use actix_files::{Files, NamedFile};
|
use actix_files::{Files, NamedFile};
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use futures::{stream::FuturesUnordered, StreamExt};
|
use futures::StreamExt;
|
||||||
use hackernews_app::*;
|
use hackernews_app::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use leptos_meta::*;
|
use leptos_meta::*;
|
||||||
use leptos_router::*;
|
use leptos_router::*;
|
||||||
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod};
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
struct ActixIntegration {
|
struct ActixIntegration {
|
||||||
|
@ -27,7 +26,7 @@ impl History for ActixIntegration {
|
||||||
.0
|
.0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn navigate(&self, loc: &LocationChange) {}
|
fn navigate(&self, _loc: &LocationChange) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/static/style.css")]
|
#[get("/static/style.css")]
|
||||||
|
|
|
@ -8,7 +8,7 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
console_log::init_with_level(log::Level::Debug);
|
_ = console_log::init_with_level(log::Level::Debug);
|
||||||
log::debug!("initialized logging");
|
log::debug!("initialized logging");
|
||||||
|
|
||||||
leptos::hydrate(body().unwrap(), |cx| {
|
leptos::hydrate(body().unwrap(), |cx| {
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::{cell::RefCell, rc::Rc};
|
|
||||||
|
|
||||||
use actix_files::{Directory, Files, NamedFile};
|
use actix_files::{Directory, Files, NamedFile};
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
|
@ -173,7 +173,7 @@ pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
|
||||||
.map(TodoSerialized::from)
|
.map(TodoSerialized::from)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let json = json::to_string(&objs);
|
let json = json::to_string(&objs);
|
||||||
if let Err(e) = storage.set_item(STORAGE_KEY, &json) {
|
if storage.set_item(STORAGE_KEY, &json).is_err() {
|
||||||
log::error!("error while trying to set item in localStorage");
|
log::error!("error while trying to set item in localStorage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -189,12 +189,12 @@ pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
|
||||||
<section class="main" class:hidden={move || todos.with(|t| t.is_empty())}>
|
<section class="main" class:hidden={move || todos.with(|t| t.is_empty())}>
|
||||||
<input id="toggle-all" class="toggle-all" type="checkbox"
|
<input id="toggle-all" class="toggle-all" type="checkbox"
|
||||||
prop:checked={move || todos.with(|t| t.remaining() > 0)}
|
prop:checked={move || todos.with(|t| t.remaining() > 0)}
|
||||||
on:input={move |_| set_todos.update(|t| t.toggle_all())}
|
on:input=move |_| set_todos.update(|t| t.toggle_all())
|
||||||
/>
|
/>
|
||||||
<label for="toggle-all">"Mark all as complete"</label>
|
<label for="toggle-all">"Mark all as complete"</label>
|
||||||
<ul class="todo-list">
|
<ul class="todo-list">
|
||||||
<For each={filtered_todos} key={|todo| todo.id}>
|
<For each=filtered_todos key=|todo| todo.id>
|
||||||
{move |cx, todo: &Todo| view! { cx, <Todo todo={todo.clone()} /> }}
|
{move |cx, todo: &Todo| view! { cx, <Todo todo=todo.clone() /> }}
|
||||||
</For>
|
</For>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
@ -216,7 +216,7 @@ pub fn TodoMVC(cx: Scope, todos: Todos) -> Element {
|
||||||
<button
|
<button
|
||||||
class="clear-completed hidden"
|
class="clear-completed hidden"
|
||||||
class:hidden={move || todos.with(|t| t.completed() == 0)}
|
class:hidden={move || todos.with(|t| t.completed() == 0)}
|
||||||
on:click={move |_| set_todos.update(|t| t.clear_completed())}
|
on:click=move |_| set_todos.update(|t| t.clear_completed())
|
||||||
>
|
>
|
||||||
"Clear completed"
|
"Clear completed"
|
||||||
</button>
|
</button>
|
||||||
|
@ -264,10 +264,10 @@ pub fn Todo(cx: Scope, todo: Todo) -> Element {
|
||||||
(todo.set_completed)(checked);
|
(todo.set_completed)(checked);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<label on:dblclick={move |_| set_editing(true)}>
|
<label on:dblclick=move |_| set_editing(true)>
|
||||||
{move || todo.title.get()}
|
{move || todo.title.get()}
|
||||||
</label>
|
</label>
|
||||||
<button class="destroy" on:click={move |_| set_todos.update(|t| t.remove(todo.id))}/>
|
<button class="destroy" on:click=move |_| set_todos.update(|t| t.remove(todo.id))/>
|
||||||
</div>
|
</div>
|
||||||
{move || editing().then(|| view! { cx,
|
{move || editing().then(|| view! { cx,
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -9,14 +9,14 @@ description = "Leptos is a full-stack, isomorphic Rust web framework leveraging
|
||||||
readme = "../README.md"
|
readme = "../README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
leptos_core = { path = "../leptos_core", version = "0.0.8" }
|
leptos_core = { path = "../leptos_core", default-features = false, version = "0.0.8" }
|
||||||
leptos_dom = { path = "../leptos_dom", version = "0.0.8" }
|
leptos_dom = { path = "../leptos_dom", default-features = false, version = "0.0.8" }
|
||||||
leptos_macro = { path = "../leptos_macro", version = "0.0.7" }
|
leptos_macro = { path = "../leptos_macro", default-features = false, version = "0.0.7" }
|
||||||
leptos_reactive = { path = "../leptos_reactive", default-features = false, version = "0.0.8" }
|
leptos_reactive = { path = "../leptos_reactive", default-features = false, version = "0.0.8" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["resource"]
|
default = ["resource"]
|
||||||
csr = ["leptos_core/csr", "leptos_macro/csr", "leptos_reactive/csr"]
|
csr = ["leptos_core/csr", "leptos_dom/csr", "leptos_macro/csr", "leptos_reactive/csr"]
|
||||||
hydrate = ["leptos_core/hydrate", "leptos_macro/hydrate", "leptos_reactive/hydrate"]
|
hydrate = ["leptos_core/hydrate", "leptos_dom/hydrate", "leptos_macro/hydrate", "leptos_reactive/hydrate"]
|
||||||
ssr = ["leptos_core/ssr", "leptos_macro/ssr", "leptos_reactive/ssr"]
|
ssr = ["leptos_core/ssr", "leptos_dom/ssr", "leptos_macro/ssr", "leptos_reactive/ssr"]
|
||||||
resource = ["leptos_reactive/resource"]
|
resource = ["leptos_reactive/resource"]
|
|
@ -1,6 +1,6 @@
|
||||||
use leptos_dom::Element;
|
use leptos_dom::Element;
|
||||||
use leptos_macro::*;
|
use leptos_macro::*;
|
||||||
use leptos_reactive::{create_effect, Memo, ReadSignal, Scope};
|
use leptos_reactive::{Memo, Scope};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use leptos_reactive::{
|
use leptos_reactive::{create_memo, queue_microtask, Memo, Scope, ScopeDisposer};
|
||||||
create_effect, create_memo, create_signal, queue_microtask, Memo, ReadSignal, Scope,
|
|
||||||
ScopeDisposer,
|
|
||||||
};
|
|
||||||
use std::{collections::HashMap, fmt::Debug, hash::Hash, ops::IndexMut};
|
use std::{collections::HashMap, fmt::Debug, hash::Hash, ops::IndexMut};
|
||||||
|
|
||||||
/// Function that maps a `Vec` to another `Vec` via a map function. The mapped `Vec` is lazy
|
/// Function that maps a `Vec` to another `Vec` via a map function. The mapped `Vec` is lazy
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate as leptos;
|
use crate as leptos;
|
||||||
use leptos_dom::{Child, IntoAttribute, IntoChild};
|
use leptos_dom::{Child, IntoChild};
|
||||||
use leptos_macro::Props;
|
use leptos_macro::Props;
|
||||||
use leptos_reactive::{debug_warn, provide_context, Scope, SuspenseContext};
|
use leptos_reactive::{provide_context, Scope, SuspenseContext};
|
||||||
|
|
||||||
#[derive(Props)]
|
#[derive(Props)]
|
||||||
pub struct SuspenseProps<F, E, G>
|
pub struct SuspenseProps<F, E, G>
|
||||||
|
@ -102,7 +102,7 @@ where
|
||||||
});
|
});
|
||||||
|
|
||||||
// return the fallback for now, wrapped in fragment identifer
|
// return the fallback for now, wrapped in fragment identifer
|
||||||
Child::Node(view! { cx, <div data-fragment-id={key}>{fallback.into_child(cx)}</div> })
|
Child::Node(view! { cx, <div data-fragment-id=key>{fallback.into_child(cx)}</div> })
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
move || initial.clone()
|
move || initial.clone()
|
||||||
|
|
|
@ -238,6 +238,11 @@ pub fn add_event_listener(
|
||||||
event_delegation::add_event_listener(event_name);
|
event_delegation::add_event_listener(event_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn ssr_event_listener(_cb: impl FnMut(web_sys::Event) + 'static) {
|
||||||
|
// this function exists only for type inference in templates for SSR
|
||||||
|
}
|
||||||
|
|
||||||
pub fn window_event_listener(event_name: &str, cb: impl Fn(web_sys::Event) + 'static) {
|
pub fn window_event_listener(event_name: &str, cb: impl Fn(web_sys::Event) + 'static) {
|
||||||
if !is_server!() {
|
if !is_server!() {
|
||||||
let handler = Box::new(cb) as Box<dyn FnMut(web_sys::Event)>;
|
let handler = Box::new(cb) as Box<dyn FnMut(web_sys::Event)>;
|
||||||
|
|
|
@ -66,7 +66,7 @@ pub fn reconcile_arrays(parent: &web_sys::Element, a: &mut [web_sys::Node], b: &
|
||||||
// Remove.
|
// Remove.
|
||||||
for node in &a[a_start..a_end] {
|
for node in &a[a_start..a_end] {
|
||||||
if map.is_none() || !map.as_ref().unwrap().contains_key(&NodeWrapper(node)) {
|
if map.is_none() || !map.as_ref().unwrap().contains_key(&NodeWrapper(node)) {
|
||||||
parent.remove_child(node);
|
_ = parent.remove_child(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a_start = a_end;
|
a_start = a_end;
|
||||||
|
@ -122,7 +122,7 @@ pub fn reconcile_arrays(parent: &web_sys::Element, a: &mut [web_sys::Node], b: &
|
||||||
b_start += 1;
|
b_start += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parent.replace_child(&a[a_start], &b[b_start]);
|
_ = parent.replace_child(&a[a_start], &b[b_start]);
|
||||||
a_start += 1;
|
a_start += 1;
|
||||||
b_start += 1;
|
b_start += 1;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ pub fn reconcile_arrays(parent: &web_sys::Element, a: &mut [web_sys::Node], b: &
|
||||||
a_start += 1;
|
a_start += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
parent.remove_child(&a[a_start]);
|
_ = parent.remove_child(&a[a_start]);
|
||||||
a_start += 1;
|
a_start += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,7 +184,7 @@ pub fn insert(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_expression(
|
pub fn insert_expression(
|
||||||
cx: Scope,
|
_cx: Scope,
|
||||||
parent: web_sys::Element,
|
parent: web_sys::Element,
|
||||||
new_value: &Child,
|
new_value: &Child,
|
||||||
mut current: Child,
|
mut current: Child,
|
||||||
|
@ -433,7 +433,7 @@ fn clean_children(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_nodes(parent: &web_sys::Element) -> Vec<web_sys::Node> {
|
/* fn child_nodes(parent: &web_sys::Element) -> Vec<web_sys::Node> {
|
||||||
let children = parent.children();
|
let children = parent.children();
|
||||||
let mut nodes = Vec::new();
|
let mut nodes = Vec::new();
|
||||||
for idx in 0..children.length() {
|
for idx in 0..children.length() {
|
||||||
|
@ -443,3 +443,4 @@ fn child_nodes(parent: &web_sys::Element) -> Vec<web_sys::Node> {
|
||||||
}
|
}
|
||||||
nodes
|
nodes
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -125,7 +125,7 @@ impl ToTokens for InlinePropsBody {
|
||||||
quote! { #[derive(Props, PartialEq, Eq)] }
|
quote! { #[derive(Props, PartialEq, Eq)] }
|
||||||
}; */
|
}; */
|
||||||
|
|
||||||
let (scope_lifetime, fn_generics, struct_generics) = if let Some(lt) = first_lifetime {
|
let (_scope_lifetime, fn_generics, struct_generics) = if let Some(lt) = first_lifetime {
|
||||||
let struct_generics: Punctuated<_, token::Comma> = generics
|
let struct_generics: Punctuated<_, token::Comma> = generics
|
||||||
.params
|
.params
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -108,7 +108,7 @@ fn root_element_to_tokens(
|
||||||
},
|
},
|
||||||
// for hydration, use get_next_element(), which will either draw from an SSRed node or clone the template
|
// for hydration, use get_next_element(), which will either draw from an SSRed node or clone the template
|
||||||
Mode::Hydrate => {
|
Mode::Hydrate => {
|
||||||
let name = node.name_as_string().unwrap();
|
//let name = node.name_as_string().unwrap();
|
||||||
quote! {
|
quote! {
|
||||||
let root = #template_uid.with(|template| #cx.get_next_element(template));
|
let root = #template_uid.with(|template| #cx.get_next_element(template));
|
||||||
// //log::debug!("root = {}", root.node_name());
|
// //log::debug!("root = {}", root.node_name());
|
||||||
|
@ -152,7 +152,7 @@ fn root_element_to_tokens(
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
enum PrevSibChange {
|
enum PrevSibChange {
|
||||||
Sib(Ident),
|
Sib(Ident),
|
||||||
Parent,
|
//Parent,
|
||||||
Skip,
|
Skip,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ fn element_to_tokens(
|
||||||
|
|
||||||
prev_sib = match curr_id {
|
prev_sib = match curr_id {
|
||||||
PrevSibChange::Sib(id) => Some(id),
|
PrevSibChange::Sib(id) => Some(id),
|
||||||
PrevSibChange::Parent => None,
|
//PrevSibChange::Parent => None,
|
||||||
PrevSibChange::Skip => prev_sib,
|
PrevSibChange::Skip => prev_sib,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -457,15 +457,22 @@ fn attr_to_tokens(
|
||||||
}
|
}
|
||||||
// Event Handlers
|
// Event Handlers
|
||||||
else if name.starts_with("on:") {
|
else if name.starts_with("on:") {
|
||||||
if mode != Mode::Ssr {
|
let handler = node
|
||||||
let event_name = name.replacen("on:", "", 1);
|
|
||||||
let handler = node
|
|
||||||
.value
|
.value
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("event listener attributes need a value");
|
.expect("event listener attributes need a value");
|
||||||
|
|
||||||
|
if mode != Mode::Ssr {
|
||||||
|
let event_name = name.replacen("on:", "", 1);
|
||||||
expressions.push(quote_spanned! {
|
expressions.push(quote_spanned! {
|
||||||
span => add_event_listener(#el_id.unchecked_ref(), #event_name, #handler);
|
span => add_event_listener(#el_id.unchecked_ref(), #event_name, #handler);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// this is here to avoid warnings about unused signals
|
||||||
|
// that are used in event listeners. I'm open to better solutions.
|
||||||
|
expressions.push(quote_spanned! {
|
||||||
|
span => let _ = ssr_event_listener(#handler);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Properties
|
// Properties
|
||||||
|
@ -556,7 +563,7 @@ fn child_to_tokens(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
parent: &Ident,
|
parent: &Ident,
|
||||||
prev_sib: Option<Ident>,
|
prev_sib: Option<Ident>,
|
||||||
mut next_sib: Option<Ident>,
|
next_sib: Option<Ident>,
|
||||||
next_el_id: &mut usize,
|
next_el_id: &mut usize,
|
||||||
next_co_id: &mut usize,
|
next_co_id: &mut usize,
|
||||||
template: &mut String,
|
template: &mut String,
|
||||||
|
@ -609,7 +616,7 @@ fn child_to_tokens(
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
let mut current: Option<Ident> = None;
|
let current: Option<Ident> = None;
|
||||||
|
|
||||||
// code to navigate to this text node
|
// code to navigate to this text node
|
||||||
let span = node
|
let span = node
|
||||||
|
@ -687,7 +694,7 @@ fn child_to_tokens(
|
||||||
let el = child_ident(*next_el_id, node);
|
let el = child_ident(*next_el_id, node);
|
||||||
*next_co_id += 1;
|
*next_co_id += 1;
|
||||||
let co = comment_ident(*next_co_id, node);
|
let co = comment_ident(*next_co_id, node);
|
||||||
next_sib = Some(el.clone());
|
//next_sib = Some(el.clone());
|
||||||
|
|
||||||
template.push_str("<!#><!/>");
|
template.push_str("<!#><!/>");
|
||||||
navigations.push(quote! {
|
navigations.push(quote! {
|
||||||
|
@ -706,7 +713,7 @@ fn child_to_tokens(
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
current = Some(el);
|
//current = Some(el);
|
||||||
}
|
}
|
||||||
// in SSR, it needs to insert the value, wrapped in comments
|
// in SSR, it needs to insert the value, wrapped in comments
|
||||||
Mode::Ssr => expressions.push(quote::quote_spanned! {
|
Mode::Ssr => expressions.push(quote::quote_spanned! {
|
||||||
|
@ -729,7 +736,7 @@ fn component_to_tokens(
|
||||||
node: &Node,
|
node: &Node,
|
||||||
parent: Option<&Ident>,
|
parent: Option<&Ident>,
|
||||||
prev_sib: Option<Ident>,
|
prev_sib: Option<Ident>,
|
||||||
mut next_sib: Option<Ident>,
|
next_sib: Option<Ident>,
|
||||||
template: &mut String,
|
template: &mut String,
|
||||||
expressions: &mut Vec<TokenStream>,
|
expressions: &mut Vec<TokenStream>,
|
||||||
navigations: &mut Vec<TokenStream>,
|
navigations: &mut Vec<TokenStream>,
|
||||||
|
@ -764,12 +771,12 @@ fn component_to_tokens(
|
||||||
|
|
||||||
});
|
});
|
||||||
} else if mode == Mode::Hydrate {
|
} else if mode == Mode::Hydrate {
|
||||||
let name = child_ident(*next_el_id, node);
|
//let name = child_ident(*next_el_id, node);
|
||||||
*next_el_id += 1;
|
*next_el_id += 1;
|
||||||
let el = child_ident(*next_el_id, node);
|
let el = child_ident(*next_el_id, node);
|
||||||
*next_co_id += 1;
|
*next_co_id += 1;
|
||||||
let co = comment_ident(*next_co_id, node);
|
let co = comment_ident(*next_co_id, node);
|
||||||
next_sib = Some(el.clone());
|
//next_sib = Some(el.clone());
|
||||||
|
|
||||||
let starts_at = if let Some(prev_sib) = prev_sib {
|
let starts_at = if let Some(prev_sib) = prev_sib {
|
||||||
quote::quote! {{
|
quote::quote! {{
|
||||||
|
@ -958,10 +965,10 @@ fn debug_name(node: &Node) -> String {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn span(node: &Node) -> Span {
|
/* fn span(node: &Node) -> Span {
|
||||||
node.name_span()
|
node.name_span()
|
||||||
.unwrap_or_else(|| node.value.as_ref().unwrap().span())
|
.unwrap_or_else(|| node.value.as_ref().unwrap().span())
|
||||||
}
|
} */
|
||||||
|
|
||||||
fn child_ident(el_id: usize, node: &Node) -> Ident {
|
fn child_ident(el_id: usize, node: &Node) -> Ident {
|
||||||
let id = format!("_el{el_id}");
|
let id = format!("_el{el_id}");
|
||||||
|
|
|
@ -42,13 +42,19 @@ use std::fmt::Debug;
|
||||||
/// # assert_eq!(b(), 2);
|
/// # assert_eq!(b(), 2);
|
||||||
/// # }).dispose();
|
/// # }).dispose();
|
||||||
/// ```
|
/// ```
|
||||||
|
#[cfg(not(feature = "ssr"))]
|
||||||
pub fn create_effect<T>(cx: Scope, f: impl FnMut(Option<T>) -> T + 'static)
|
pub fn create_effect<T>(cx: Scope, f: impl FnMut(Option<T>) -> T + 'static)
|
||||||
where
|
where
|
||||||
T: Debug + 'static,
|
T: Debug + 'static,
|
||||||
{
|
{
|
||||||
#[cfg(not(feature = "ssr"))]
|
|
||||||
create_isomorphic_effect(cx, f);
|
create_isomorphic_effect(cx, f);
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
pub fn create_effect<T>(_cx: Scope, _f: impl FnMut(Option<T>) -> T + 'static)
|
||||||
|
where
|
||||||
|
T: Debug + 'static,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// Creates an effect; unlike effects created by [create_effect], isomorphic effects will run on
|
/// Creates an effect; unlike effects created by [create_effect], isomorphic effects will run on
|
||||||
/// the server as well as the client.
|
/// the server as well as the client.
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#[cfg(any(feature = "hydrate"))]
|
use std::collections::HashMap;
|
||||||
use std::collections::{HashMap, HashSet};
|
#[cfg(feature = "hydrate")]
|
||||||
#[cfg(any(feature = "ssr"))]
|
use std::collections::HashSet;
|
||||||
use std::{collections::HashMap, future::Future, pin::Pin};
|
#[cfg(feature = "ssr")]
|
||||||
|
use std::{future::Future, pin::Pin};
|
||||||
|
|
||||||
#[cfg(any(feature = "hydrate"))]
|
#[cfg(any(feature = "hydrate"))]
|
||||||
use crate::{ResourceId, Scope};
|
use crate::ResourceId;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct SharedContext {
|
pub struct SharedContext {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{create_isomorphic_effect, create_signal, ReadSignal, Scope};
|
use crate::{ReadSignal, Scope};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
/// Creates an efficient derived reactive value based on other reactive values.
|
/// Creates an efficient derived reactive value based on other reactive values.
|
||||||
|
|
|
@ -163,7 +163,6 @@ where
|
||||||
r.trigger.update(|n| *n += 1);
|
r.trigger.update(|n| *n += 1);
|
||||||
|
|
||||||
let resolve = {
|
let resolve = {
|
||||||
let runtime = cx.runtime;
|
|
||||||
let resolved = r.resolved.clone();
|
let resolved = r.resolved.clone();
|
||||||
let set_value = r.set_value;
|
let set_value = r.set_value;
|
||||||
let set_loading = r.set_loading;
|
let set_loading = r.set_loading;
|
||||||
|
@ -184,7 +183,7 @@ where
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let id = serde_json::to_string(&id).unwrap();
|
let id = serde_json::to_string(&id).unwrap();
|
||||||
js_sys::Reflect::set(
|
_ = js_sys::Reflect::set(
|
||||||
&resource_resolvers,
|
&resource_resolvers,
|
||||||
&wasm_bindgen::JsValue::from_str(&id),
|
&wasm_bindgen::JsValue::from_str(&id),
|
||||||
resolve.as_ref().unchecked_ref(),
|
resolve.as_ref().unchecked_ref(),
|
||||||
|
|
|
@ -158,7 +158,6 @@ impl Runtime {
|
||||||
|
|
||||||
#[cfg(feature = "hydrate")]
|
#[cfg(feature = "hydrate")]
|
||||||
pub fn start_hydration(&self, element: &web_sys::Element) {
|
pub fn start_hydration(&self, element: &web_sys::Element) {
|
||||||
use std::collections::HashMap;
|
|
||||||
use wasm_bindgen::{JsCast, UnwrapThrowExt};
|
use wasm_bindgen::{JsCast, UnwrapThrowExt};
|
||||||
|
|
||||||
// gather hydratable elements
|
// gather hydratable elements
|
||||||
|
|
|
@ -1,17 +1,9 @@
|
||||||
use crate::{
|
|
||||||
hydration::SharedContext, AnyEffect, AnyResource, EffectId, ResourceId, ResourceState, Runtime,
|
|
||||||
SignalId,
|
|
||||||
};
|
|
||||||
use serde::{de::DeserializeOwned, Serialize};
|
|
||||||
use std::{
|
|
||||||
any::{Any, TypeId},
|
|
||||||
cell::RefCell,
|
|
||||||
collections::HashMap,
|
|
||||||
fmt::Debug,
|
|
||||||
rc::Rc,
|
|
||||||
};
|
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
use std::{future::Future, pin::Pin};
|
use crate::SuspenseContext;
|
||||||
|
use crate::{hydration::SharedContext, EffectId, ResourceId, Runtime, SignalId};
|
||||||
|
use std::fmt::Debug;
|
||||||
|
#[cfg(feature = "ssr")]
|
||||||
|
use std::{collections::HashMap, future::Future, pin::Pin};
|
||||||
|
|
||||||
#[must_use = "Scope will leak memory if the disposer function is never called"]
|
#[must_use = "Scope will leak memory if the disposer function is never called"]
|
||||||
/// Creates a child reactive scope and runs the function within it. This is useful for applications
|
/// Creates a child reactive scope and runs the function within it. This is useful for applications
|
||||||
|
@ -331,20 +323,20 @@ impl Scope {
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub fn register_suspense(
|
pub fn register_suspense(
|
||||||
&self,
|
&self,
|
||||||
context: crate::SuspenseContext,
|
context: SuspenseContext,
|
||||||
key: &str,
|
key: &str,
|
||||||
resolver: impl FnOnce() -> String + 'static,
|
resolver: impl FnOnce() -> String + 'static,
|
||||||
) {
|
) {
|
||||||
use crate::{create_isomorphic_effect, SuspenseContext};
|
use crate::create_isomorphic_effect;
|
||||||
use futures::{future::join_all, FutureExt, StreamExt};
|
use futures::StreamExt;
|
||||||
|
|
||||||
if let Some(ref mut shared_context) = *self.runtime.shared_context.borrow_mut() {
|
if let Some(ref mut shared_context) = *self.runtime.shared_context.borrow_mut() {
|
||||||
let (mut tx, mut rx) = futures::channel::mpsc::channel::<()>(1);
|
let (mut tx, mut rx) = futures::channel::mpsc::channel::<()>(1);
|
||||||
|
|
||||||
create_isomorphic_effect(*self, move |fut| {
|
create_isomorphic_effect(*self, move |_| {
|
||||||
let pending = context.pending_resources.get();
|
let pending = context.pending_resources.get();
|
||||||
if pending == 0 {
|
if pending == 0 {
|
||||||
tx.try_send(());
|
_ = tx.try_send(());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{Runtime, Scope, ScopeId, ScopeProperty};
|
use crate::{Runtime, Scope, ScopeProperty};
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::{fmt::Debug, marker::PhantomData};
|
use std::{fmt::Debug, marker::PhantomData};
|
||||||
|
|
||||||
/// Creates a signal, the basic reactive primitive.
|
/// Creates a signal, the basic reactive primitive.
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#[cfg(feature = "ssr")]
|
|
||||||
use std::{cell::RefCell, future::Future, pin::Pin, rc::Rc};
|
|
||||||
|
|
||||||
use crate::{create_signal, spawn::queue_microtask, ReadSignal, Scope, WriteSignal};
|
use crate::{create_signal, spawn::queue_microtask, ReadSignal, Scope, WriteSignal};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{cell::RefCell, fmt::Debug, rc::Rc};
|
use std::fmt::Debug;
|
||||||
|
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{use_head, MetaContext};
|
use crate::use_head;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::{use_head, MetaContext, TextProp};
|
use crate::{use_head, TextProp};
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct TitleContext {
|
pub struct TitleContext {
|
||||||
|
#[cfg(not(feature = "ssr"))]
|
||||||
el: Rc<RefCell<Option<web_sys::HtmlTitleElement>>>,
|
el: Rc<RefCell<Option<web_sys::HtmlTitleElement>>>,
|
||||||
formatter: Rc<RefCell<Option<Formatter>>>,
|
formatter: Rc<RefCell<Option<Formatter>>>,
|
||||||
text: Rc<RefCell<Option<TextProp>>>,
|
text: Rc<RefCell<Option<TextProp>>>,
|
||||||
|
|
|
@ -30,7 +30,6 @@ where
|
||||||
children,
|
children,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
#[cfg(any(feature = "csr", feature = "hydrate"))]
|
|
||||||
let on_submit = move |ev: web_sys::Event| {
|
let on_submit = move |ev: web_sys::Event| {
|
||||||
if ev.default_prevented() {
|
if ev.default_prevented() {
|
||||||
return;
|
return;
|
||||||
|
@ -142,7 +141,7 @@ where
|
||||||
|
|
||||||
let children = children().into_vec();
|
let children = children().into_vec();
|
||||||
|
|
||||||
view! { cx,
|
view! { cx,
|
||||||
<form
|
<form
|
||||||
method=method
|
method=method
|
||||||
action=action
|
action=action
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use leptos::leptos_dom::IntoChild;
|
use leptos::leptos_dom::IntoChild;
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use typed_builder::TypedBuilder;
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ssr"))]
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
use crate::{use_location, use_resolved_path, State};
|
use crate::{use_location, use_resolved_path, State};
|
||||||
|
@ -87,7 +89,7 @@ where
|
||||||
}
|
}
|
||||||
let child = children.remove(0);
|
let child = children.remove(0);
|
||||||
|
|
||||||
view! { cx,
|
view! { cx,
|
||||||
<a
|
<a
|
||||||
href=move || href().unwrap_or_default()
|
href=move || href().unwrap_or_default()
|
||||||
prop:state={props.state.map(|s| s.to_js_value())}
|
prop:state={props.state.map(|s| s.to_js_value())}
|
||||||
|
|
|
@ -12,12 +12,13 @@ use wasm_bindgen::JsCast;
|
||||||
use leptos_reactive::use_transition;
|
use leptos_reactive::use_transition;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
create_location,
|
create_location, matching::resolve_path, History, Location, LocationChange, RouteContext,
|
||||||
matching::{get_route_matches, resolve_path, Branch, RouteMatch},
|
RouterIntegrationContext, State,
|
||||||
unescape, History, Location, LocationChange, RouteContext, RouterIntegrationContext, State,
|
|
||||||
Url,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(not(feature = "ssr"))]
|
||||||
|
use crate::{unescape, Url};
|
||||||
|
|
||||||
#[derive(TypedBuilder)]
|
#[derive(TypedBuilder)]
|
||||||
pub struct RouterProps {
|
pub struct RouterProps {
|
||||||
#[builder(default, setter(strip_option))]
|
#[builder(default, setter(strip_option))]
|
||||||
|
|
Loading…
Reference in New Issue