wip: bubbling in progress

This commit is contained in:
Jonathan Kelley committed 2021-11-11 21:34:20 -05:00
1 parent 8acdd2ea83
commit a21020ea57
15 files changed
+268 -291

No files matched your search

+47 -47
View File
@@ -36,16 +36,16 @@ fn test_original_diff() {
assert_eq!(
mutations.edits,
[
CreateElement {
root: 0,
tag: "div"
},
CreateElement {
root: 1,
tag: "div"
},
CreateTextNode {
CreateElement {
root: 2,
tag: "div"
},
CreateTextNode {
root: 3,
text: "Hello, world!"
},
AppendChildren { many: 1 },
@@ -81,32 +81,32 @@ fn create() {
assert_eq!(
mutations.edits,
[
CreateElement {
root: 0,
tag: "div"
},
CreateElement {
root: 1,
tag: "div"
},
CreateTextNode {
root: 2,
text: "Hello, world!"
},
CreateElement {
root: 3,
root: 2,
tag: "div"
},
CreateTextNode {
root: 3,
text: "Hello, world!"
},
CreateElement {
root: 4,
tag: "div"
},
CreateTextNode {
CreateElement {
root: 5,
text: "hello"
tag: "div"
},
CreateTextNode {
root: 6,
text: "hello"
},
CreateTextNode {
root: 7,
text: "world"
},
AppendChildren { many: 2 },
@@ -136,29 +136,29 @@ fn create_list() {
mutations.edits,
[
CreateElement {
root: 0,
tag: "div"
},
CreateTextNode {
root: 1,
text: "hello"
tag: "div"
},
AppendChildren { many: 1 },
CreateElement {
CreateTextNode {
root: 2,
tag: "div"
},
CreateTextNode {
root: 3,
text: "hello"
},
AppendChildren { many: 1 },
CreateElement {
root: 4,
root: 3,
tag: "div"
},
CreateTextNode {
root: 4,
text: "hello"
},
AppendChildren { many: 1 },
CreateElement {
root: 5,
tag: "div"
},
CreateTextNode {
root: 6,
text: "hello"
},
AppendChildren { many: 1 },
@@ -185,10 +185,6 @@ fn create_simple() {
assert_eq!(
mutations.edits,
[
CreateElement {
root: 0,
tag: "div"
},
CreateElement {
root: 1,
tag: "div"
@@ -201,6 +197,10 @@ fn create_simple() {
root: 3,
tag: "div"
},
CreateElement {
root: 4,
tag: "div"
},
AppendChildren { many: 4 },
]
);
@@ -234,39 +234,39 @@ fn create_components() {
assert_eq!(
mutations.edits,
[
CreateElement { root: 0, tag: "h1" },
CreateElement { root: 1, tag: "h1" },
CreateElement {
root: 1,
root: 2,
tag: "div"
},
CreateTextNode {
root: 2,
root: 3,
text: "abc1"
},
AppendChildren { many: 1 },
CreateElement { root: 3, tag: "p" },
CreateElement { root: 4, tag: "h1" },
CreateElement { root: 4, tag: "p" },
CreateElement { root: 5, tag: "h1" },
CreateElement {
root: 5,
root: 6,
tag: "div"
},
CreateTextNode {
root: 6,
root: 7,
text: "abc2"
},
AppendChildren { many: 1 },
CreateElement { root: 7, tag: "p" },
CreateElement { root: 8, tag: "h1" },
CreateElement { root: 8, tag: "p" },
CreateElement { root: 9, tag: "h1" },
CreateElement {
root: 9,
root: 10,
tag: "div"
},
CreateTextNode {
root: 10,
root: 11,
text: "abc3"
},
AppendChildren { many: 1 },
CreateElement { root: 11, tag: "p" },
CreateElement { root: 12, tag: "p" },
AppendChildren { many: 9 },
]
);
@@ -286,15 +286,15 @@ fn anchors() {
mutations.edits,
[
CreateElement {
root: 0,
root: 1,
tag: "div"
},
CreateTextNode {
root: 1,
root: 2,
text: "hello"
},
AppendChildren { many: 1 },
CreatePlaceholder { root: 2 },
CreatePlaceholder { root: 3 },
AppendChildren { many: 2 },
]
);
+3 -4
View File
@@ -18,8 +18,6 @@ type Shared<T> = Arc<Mutex<T>>;
#[test]
fn manual_diffing() {
test_logging::set_up_logging(IS_LOGGING_ENABLED);
struct AppProps {
value: Shared<&'static str>,
}
@@ -73,9 +71,9 @@ fn events_generate() {
let mut channel = dom.get_scheduler_channel();
assert!(dom.has_any_work());
let edits = dom.work_with_deadline(|| false);
let edits = dom.rebuild();
assert_eq!(
edits[0].edits,
edits.edits,
[
CreateElement {
tag: "div",
@@ -100,6 +98,7 @@ fn events_generate() {
root: 3,
},
AppendChildren { many: 2 },
AppendChildren { many: 1 },
]
)
}
-41
View File
@@ -1,41 +0,0 @@
use futures_util::StreamExt;
/*
furtures_channel provides us some batching simply due to how Rust's async works.
Any hook that uses schedule_update is simply deferring to unbounded_send. Multiple
unbounded_sends can be linked together in succession provided there isn't an "await"
between them. Our internal batching mechanism simply waits for the "schedule_update"
to fire and then pulls any messages off the unbounded_send queue.
Additionally, due to how our "time slicing" works we'll always come back and check
in for new work if the deadline hasn't expired. On average, our deadline should be
about 10ms, which is way more than enough for diffing/creating to happen.
*/
#[async_std::test]
async fn batch() {
let (sender, mut recver) = futures_channel::mpsc::unbounded::<i32>();
let _handle = async_std::task::spawn(async move {
let _msg = recver.next().await;
while let Ok(msg) = recver.try_next() {
println!("{:#?}", msg);
}
let _msg = recver.next().await;
while let Ok(msg) = recver.try_next() {
println!("{:#?}", msg);
}
});
sender.unbounded_send(1).unwrap();
sender.unbounded_send(2).unwrap();
sender.unbounded_send(3).unwrap();
sender.unbounded_send(4).unwrap();
async_std::task::sleep(std::time::Duration::from_millis(100)).await;
sender.unbounded_send(5).unwrap();
sender.unbounded_send(6).unwrap();
sender.unbounded_send(7).unwrap();
sender.unbounded_send(8).unwrap();
}
-14
View File
@@ -88,17 +88,3 @@ fn child_components() {
let edits = vdom.rebuild();
dbg!(edits);
}
#[test]
fn suspended_works() {
todo!()
// static App: FC<()> = |cx, props| {
// let title = use_suspense(cx, || async { "bob" }, move |cx, f| todo!());
// // let title = use_suspense(cx, || async { "bob" }, move |cx, f| rsx! { "{f}"});
// cx.render(rsx!("hello" { title }))
// };
// let mut vdom = VirtualDom::new(App);
// let edits = vdom.rebuild();
// dbg!(edits);
}