mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
Update examples, removing unnecessary one and using new APIs
This commit is contained in:
parent
bea51d54ef
commit
2d62610288
6 changed files with 10 additions and 83 deletions
2
TODO.md
2
TODO.md
|
@ -10,7 +10,7 @@
|
|||
- [ ] Get transitions working
|
||||
- [ ] SSR
|
||||
- [x] SSR
|
||||
- [ ] Hydration
|
||||
- [x] Hydration
|
||||
- [ ] Streaming HTML from server
|
||||
- [ ] Streaming `Resource`s
|
||||
- [ ] Docs (and clippy warning to insist on docs)
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
[package]
|
||||
name = "children"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
leptos = { path = "../../leptos" }
|
||||
wee_alloc = "0.4"
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = true
|
||||
opt-level = 'z'
|
|
@ -1,7 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link data-trunk rel="rust" data-wasm-opt="z"/>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
|
@ -1,53 +0,0 @@
|
|||
use leptos::*;
|
||||
|
||||
use leptos_dom::wasm_bindgen::{JsCast, UnwrapThrowExt};
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
fn main() {
|
||||
mount_to_body(|cx| {
|
||||
view! { <Parent/> }
|
||||
})
|
||||
}
|
||||
|
||||
type CounterHolder = Vec<(usize, (ReadSignal<i32>, WriteSignal<i32>))>;
|
||||
|
||||
struct CounterUpdater {
|
||||
set_counters: WriteSignal<CounterHolder>,
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Parent(cx: Scope) -> web_sys::Element {
|
||||
let (value, _) = cx.create_signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
"regular"
|
||||
<h1>"Children should appear below"</h1>
|
||||
{|| create_text_node(&value.get().to_string())}
|
||||
<HasChildren>
|
||||
<span>"Child A"</span>
|
||||
<span>"Child B"</span>
|
||||
<span>"Child C"</span>
|
||||
</HasChildren>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn HasChildren(cx: Scope, children: Vec<Element>) -> web_sys::Element {
|
||||
view! {
|
||||
<div>
|
||||
<h2>"I have children:"</h2>
|
||||
<ul>
|
||||
{
|
||||
children.into_iter().map(|child| {
|
||||
debug_warn!("child is {:?}", child.outer_html());
|
||||
view! { <li>{child}</li> }
|
||||
}).collect::<Vec<_>>()
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
}
|
|
@ -30,8 +30,8 @@ async fn fetch_cats(count: u32) -> Result<Vec<String>, ()> {
|
|||
}
|
||||
|
||||
pub fn fetch_example(cx: Scope) -> web_sys::Element {
|
||||
let (cat_count, set_cat_count) = cx.create_signal::<u32>(1);
|
||||
let cats = cx.create_resource(cat_count, |count| fetch_cats(*count));
|
||||
let (cat_count, set_cat_count) = create_signal::<u32>(cx, 1);
|
||||
let cats = create_resource(cx, cat_count, |count| fetch_cats(*count));
|
||||
|
||||
view! {
|
||||
<div>
|
||||
|
|
|
@ -28,12 +28,12 @@ impl Display for Tab {
|
|||
}
|
||||
|
||||
pub fn transition_tabs(cx: Scope) -> web_sys::Element {
|
||||
let (tab, set_tab) = cx.create_signal(Tab::A);
|
||||
let (progress, set_progress) = cx.create_signal(0);
|
||||
let (tab, set_tab) = create_signal(cx, Tab::A);
|
||||
let (progress, set_progress) = create_signal(cx, 0);
|
||||
|
||||
let transition = cx.use_transition();
|
||||
let transition = use_transition(cx);
|
||||
|
||||
cx.create_effect(move |handle: Option<Option<IntervalHandle>>| {
|
||||
create_effect(cx, move |handle: Option<Option<IntervalHandle>>| {
|
||||
if let Some(Some(handle)) = handle {
|
||||
if transition.pending() {
|
||||
Some(handle)
|
||||
|
@ -80,11 +80,11 @@ pub fn transition_tabs(cx: Scope) -> web_sys::Element {
|
|||
|
||||
#[component]
|
||||
pub fn Child(cx: Scope, page: ReadSignal<Tab>) -> Element {
|
||||
let data = cx.create_resource(page, |page| fake_data_load(*page));
|
||||
let data = create_resource(cx, page, |page| fake_data_load(page));
|
||||
|
||||
let (counter, set_counter) = cx.create_signal(0);
|
||||
let (counter, set_counter) = create_signal(cx, 0);
|
||||
|
||||
cx.create_effect(move |prev_handle: Option<IntervalHandle>| {
|
||||
create_effect(cx, move |prev_handle: Option<IntervalHandle>| {
|
||||
log::debug!("resetting counter for Child #{}", page());
|
||||
set_counter(|n| *n = 0);
|
||||
if let Some(handle) = prev_handle {
|
||||
|
|
Loading…
Reference in a new issue