Compare commits

...

5 Commits

Author SHA1 Message Date
Greg Johnston
99139ac505 starting work on committing adds and moves 2023-05-27 07:21:29 -04:00
Jose Quesada
2e2d500610 saving changes 2023-05-26 13:39:34 -04:00
Jose Quesada
694e94db97 only one thing left to do with apply_cmds 2023-05-26 13:39:34 -04:00
Jose Quesada
7e0bf3514f applied [C, A, B] optimization, along with fixing another one 2023-05-26 13:39:34 -04:00
Jose Quesada
010bd8c05e reworked impl of diff for the Each component 2023-05-26 13:39:34 -04:00
3 changed files with 820 additions and 298 deletions

View File

@@ -28,75 +28,66 @@ fn main() {
}
fn view_fn(cx: Scope) -> impl IntoView {
let view = view! { cx,
<For
each=|| vec![0, 1, 2, 3, 4, 5, 6, 7]
key=|i| *i
view=|cx, i| view! { cx, {i} }
/>
}
.into_view(cx);
let (list, set_list) = create_signal(cx, vec![2]);//vec![1, 2, 3, 4, 5]);
let (a, set_a) = create_signal(cx, view.clone());
let (b, set_b) = create_signal(cx, view);
let (is_a, set_is_a) = create_signal(cx, true);
let handle_toggle = move |_| {
trace!("toggling");
if is_a() {
set_b(a());
set_is_a(false);
} else {
set_a(a());
set_is_a(true);
}
};
let a_tag = view! { cx, <svg::a/> };
view! { cx,
<>
<div>
<button on:click=handle_toggle>"Toggle"</button>
</div>
<svg>{a_tag}</svg>
<Example/>
<A child=Signal::from(a) />
<A child=Signal::from(b) />
</>
}
}
#[component]
fn A(cx: Scope, child: Signal<View>) -> impl IntoView {
move || child()
}
#[component]
fn Example(cx: Scope) -> impl IntoView {
trace!("rendering <Example/>");
let (value, set_value) = create_signal(cx, 10);
let memo = create_memo(cx, move |_| value() * 2);
let derived = Signal::derive(cx, move || value() * 3);
create_effect(cx, move |_| {
trace!("logging value of derived..., {}", derived.get());
request_animation_frame(move || {
set_list(vec![1, 2]);//vec![0, 1, 3, 6, 4, 5, 2, 7])
});
set_timeout(
move || set_value.update(|v| *v += 1),
std::time::Duration::from_millis(50),
);
view! { cx,
<h1>"Example"</h1>
<button on:click=move |_| set_value.update(|value| *value += 1)>
"Click me"
</button>
<ul>
/* These work! */
/* <Test from=&[1] to=&[]/>
<Test from=&[1, 2] to=&[]/>
<Test from=&[1, 2, 3] to=&[]/>
<Test from=&[] to=&[1]/>
<Test from=&[1, 2] to=&[1]/>
<Test from=&[2, 1] to=&[1]/>
<Test from=&[1] to=&[1, 2]/>
<Test from=&[2] to=&[1, 2]/>
<Test from=&[1, 2, 3] to=&[1, 2]/>
<Test from=&[] to=&[1, 2, 3]/>
<Test from=&[2] to=&[1, 2, 3]/>
<Test from=&[1] to=&[1, 2, 3]/>
<Test from=&[3] to=&[1, 2, 3]/>
<Test from=&[1, 3, 2] to=&[1, 2, 3]/>
<Test from=&[2, 1, 3] to=&[1, 2, 3]/>*/
// TODO diffing broken
// <Test from=&[3, 2, 1] to=&[1, 2, 3]/>
<Test from=&[3, 1] to=&[1, 2, 3]/>
</ul>
}
}
#[component]
fn Test(cx: Scope, from: &'static [usize], to: &'static [usize]) -> impl IntoView {
let (list, set_list) = create_signal(cx, from.to_vec());
request_animation_frame(move || {
set_list(to.to_vec());
});
view! { cx,
<li>
<For
each=list
key=|i| *i
view=|cx, i| {
view! { cx, <span>{i}</span> }
}
/>
/* <p>
"Pre | "
<For
each=list
key=|i| *i
view=|cx, i| {
view! { cx, <span>{i}</span> }
}
/>
" | Post"
</p> */
</li>
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -218,7 +218,9 @@ pub fn render_to_stream_with_prefix_undisposed_with_context_and_block_replacemen
let mut blocking_fragments = FuturesUnordered::new();
let fragments = FuturesUnordered::new();
eprintln!("\n\n");
for (fragment_id, data) in pending_fragments {
eprintln!("pending fragment {fragment_id:?}");
if data.should_block {
blocking_fragments
.push(async move { (fragment_id, data.out_of_order.await) });