|
@@ -5,20 +5,20 @@ use pretty_assertions::assert_eq;
|
|
#[test]
|
|
#[test]
|
|
fn list_creates_one_by_one() {
|
|
fn list_creates_one_by_one() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- let gen = cx.generation();
|
|
|
|
|
|
+ let gen = generation();
|
|
|
|
|
|
- cx.render(rsx! {
|
|
|
|
|
|
+ render! {
|
|
div {
|
|
div {
|
|
- (0..gen).map(|i| rsx! {
|
|
|
|
|
|
+ (0..gen).map(|i| render! {
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
// load the div and then assign the empty fragment as a placeholder
|
|
// load the div and then assign the empty fragment as a placeholder
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.rebuild().santize().edits,
|
|
|
|
|
|
+ dom.rebuild_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
AssignId { path: &[0], id: ElementId(2,) },
|
|
AssignId { path: &[0], id: ElementId(2,) },
|
|
@@ -29,10 +29,10 @@ fn list_creates_one_by_one() {
|
|
// Rendering the first item should replace the placeholder with an element
|
|
// Rendering the first item should replace the placeholder with an element
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(3,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(3,) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(4,) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(4,) },
|
|
ReplaceWith { id: ElementId(2,), m: 1 },
|
|
ReplaceWith { id: ElementId(2,), m: 1 },
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -40,10 +40,10 @@ fn list_creates_one_by_one() {
|
|
// Rendering the next item should insert after the previous
|
|
// Rendering the next item should insert after the previous
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(5,) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(5,) },
|
|
InsertAfter { id: ElementId(3,), m: 1 },
|
|
InsertAfter { id: ElementId(3,), m: 1 },
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -51,10 +51,10 @@ fn list_creates_one_by_one() {
|
|
// ... and again!
|
|
// ... and again!
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(6,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(6,) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(7,) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(7,) },
|
|
InsertAfter { id: ElementId(2,), m: 1 },
|
|
InsertAfter { id: ElementId(2,), m: 1 },
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -62,10 +62,10 @@ fn list_creates_one_by_one() {
|
|
// once more
|
|
// once more
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(8,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(8,) },
|
|
- HydrateText { path: &[0], value: "3", id: ElementId(9,) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "3".to_string(), id: ElementId(9,) },
|
|
InsertAfter { id: ElementId(6,), m: 1 },
|
|
InsertAfter { id: ElementId(6,), m: 1 },
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -74,30 +74,30 @@ fn list_creates_one_by_one() {
|
|
#[test]
|
|
#[test]
|
|
fn removes_one_by_one() {
|
|
fn removes_one_by_one() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- let gen = 3 - cx.generation() % 4;
|
|
|
|
|
|
+ let gen = 3 - generation() % 4;
|
|
|
|
|
|
- cx.render(rsx! {
|
|
|
|
|
|
+ render! {
|
|
div {
|
|
div {
|
|
- (0..gen).map(|i| rsx! {
|
|
|
|
|
|
+ (0..gen).map(|i| render! {
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
// load the div and then assign the empty fragment as a placeholder
|
|
// load the div and then assign the empty fragment as a placeholder
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.rebuild().santize().edits,
|
|
|
|
|
|
+ dom.rebuild_to_vec().santize().edits,
|
|
[
|
|
[
|
|
// The container
|
|
// The container
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
|
// each list item
|
|
// each list item
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(3) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(3) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(4) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(4) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(5) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(5) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(7) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(7) },
|
|
// replace the placeholder in the template with the 3 templates on the stack
|
|
// replace the placeholder in the template with the 3 templates on the stack
|
|
ReplacePlaceholder { m: 3, path: &[0] },
|
|
ReplacePlaceholder { m: 3, path: &[0] },
|
|
// Mount the div
|
|
// Mount the div
|
|
@@ -109,14 +109,14 @@ fn removes_one_by_one() {
|
|
// Rendering the first item should replace the placeholder with an element
|
|
// Rendering the first item should replace the placeholder with an element
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[Remove { id: ElementId(6) }]
|
|
[Remove { id: ElementId(6) }]
|
|
);
|
|
);
|
|
|
|
|
|
// Remove div(2)
|
|
// Remove div(2)
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[Remove { id: ElementId(4) }]
|
|
[Remove { id: ElementId(4) }]
|
|
);
|
|
);
|
|
|
|
|
|
@@ -124,7 +124,7 @@ fn removes_one_by_one() {
|
|
// todo: this should just be a remove with no placeholder
|
|
// todo: this should just be a remove with no placeholder
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
CreatePlaceholder { id: ElementId(4) },
|
|
CreatePlaceholder { id: ElementId(4) },
|
|
ReplaceWith { id: ElementId(2), m: 1 }
|
|
ReplaceWith { id: ElementId(2), m: 1 }
|
|
@@ -135,14 +135,14 @@ fn removes_one_by_one() {
|
|
// todo: this should actually be append to, but replace placeholder is fine for now
|
|
// todo: this should actually be append to, but replace placeholder is fine for now
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(3) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(3) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(5) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(5) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(6) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(6) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(7) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(7) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(8) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(8) },
|
|
ReplaceWith { id: ElementId(4), m: 3 }
|
|
ReplaceWith { id: ElementId(4), m: 3 }
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -151,18 +151,18 @@ fn removes_one_by_one() {
|
|
#[test]
|
|
#[test]
|
|
fn list_shrink_multiroot() {
|
|
fn list_shrink_multiroot() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- cx.render(rsx! {
|
|
|
|
|
|
+ render! {
|
|
div {
|
|
div {
|
|
- (0..cx.generation()).map(|i| rsx! {
|
|
|
|
|
|
+ (0..generation()).map(|i| render! {
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.rebuild().santize().edits,
|
|
|
|
|
|
+ dom.rebuild_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
AssignId { path: &[0,], id: ElementId(2,) },
|
|
AssignId { path: &[0,], id: ElementId(2,) },
|
|
@@ -172,36 +172,36 @@ fn list_shrink_multiroot() {
|
|
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(3) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(3) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(4) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(4) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(5) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(5) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(6) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(6) },
|
|
ReplaceWith { id: ElementId(2), m: 2 }
|
|
ReplaceWith { id: ElementId(2), m: 2 }
|
|
]
|
|
]
|
|
);
|
|
);
|
|
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(7) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(7) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(8) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(8) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(9) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(9) },
|
|
InsertAfter { id: ElementId(5), m: 2 }
|
|
InsertAfter { id: ElementId(5), m: 2 }
|
|
]
|
|
]
|
|
);
|
|
);
|
|
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(10) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(10) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(11) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(11) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(12) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(12) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(13) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(13) },
|
|
InsertAfter { id: ElementId(8), m: 2 }
|
|
InsertAfter { id: ElementId(8), m: 2 }
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -210,38 +210,38 @@ fn list_shrink_multiroot() {
|
|
#[test]
|
|
#[test]
|
|
fn removes_one_by_one_multiroot() {
|
|
fn removes_one_by_one_multiroot() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- let gen = 3 - cx.generation() % 4;
|
|
|
|
|
|
+ let gen = 3 - generation() % 4;
|
|
|
|
|
|
- cx.render(rsx! {
|
|
|
|
|
|
+ render! {
|
|
div {
|
|
div {
|
|
- (0..gen).map(|i| rsx! {
|
|
|
|
|
|
+ (0..gen).map(|i| render! {
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
div { "{i}" }
|
|
})
|
|
})
|
|
}
|
|
}
|
|
- })
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
// load the div and then assign the empty fragment as a placeholder
|
|
// load the div and then assign the empty fragment as a placeholder
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.rebuild().santize().edits,
|
|
|
|
|
|
+ dom.rebuild_to_vec().santize().edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1) },
|
|
//
|
|
//
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(3) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(3) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(4) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(4) },
|
|
- HydrateText { path: &[0], value: "0", id: ElementId(5) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "0".to_string(), id: ElementId(5) },
|
|
//
|
|
//
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(6) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(7) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(7) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(8) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(8) },
|
|
- HydrateText { path: &[0], value: "1", id: ElementId(9) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "1".to_string(), id: ElementId(9) },
|
|
//
|
|
//
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(10) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(10) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(11) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(11) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(12) },
|
|
LoadTemplate { name: "template", index: 1, id: ElementId(12) },
|
|
- HydrateText { path: &[0], value: "2", id: ElementId(13) },
|
|
|
|
|
|
+ HydrateText { path: &[0], value: "2".to_string(), id: ElementId(13) },
|
|
//
|
|
//
|
|
ReplacePlaceholder { path: &[0], m: 6 },
|
|
ReplacePlaceholder { path: &[0], m: 6 },
|
|
//
|
|
//
|
|
@@ -251,19 +251,19 @@ fn removes_one_by_one_multiroot() {
|
|
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[Remove { id: ElementId(10) }, Remove { id: ElementId(12) }]
|
|
[Remove { id: ElementId(10) }, Remove { id: ElementId(12) }]
|
|
);
|
|
);
|
|
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[Remove { id: ElementId(6) }, Remove { id: ElementId(8) }]
|
|
[Remove { id: ElementId(6) }, Remove { id: ElementId(8) }]
|
|
);
|
|
);
|
|
|
|
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
assert_eq!(
|
|
assert_eq!(
|
|
- dom.render_immediate().santize().edits,
|
|
|
|
|
|
+ dom.render_immediate_to_vec().santize().edits,
|
|
[
|
|
[
|
|
CreatePlaceholder { id: ElementId(8) },
|
|
CreatePlaceholder { id: ElementId(8) },
|
|
Remove { id: ElementId(2) },
|
|
Remove { id: ElementId(2) },
|
|
@@ -275,48 +275,46 @@ fn removes_one_by_one_multiroot() {
|
|
#[test]
|
|
#[test]
|
|
fn two_equal_fragments_are_equal_static() {
|
|
fn two_equal_fragments_are_equal_static() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- cx.render(rsx! {
|
|
|
|
- (0..5).map(|_| rsx! {
|
|
|
|
|
|
+ render! {
|
|
|
|
+ (0..5).map(|_| render! {
|
|
div { "hello" }
|
|
div { "hello" }
|
|
})
|
|
})
|
|
- })
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
- _ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
|
|
|
- assert!(dom.render_immediate().edits.is_empty());
|
|
|
|
|
|
+ _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
|
|
|
|
+ assert!(dom.render_immediate_to_vec().edits.is_empty());
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
fn two_equal_fragments_are_equal() {
|
|
fn two_equal_fragments_are_equal() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- cx.render(rsx! {
|
|
|
|
- (0..5).map(|i| rsx! {
|
|
|
|
|
|
+ render! {
|
|
|
|
+ (0..5).map(|i| render! {
|
|
div { "hello {i}" }
|
|
div { "hello {i}" }
|
|
})
|
|
})
|
|
- })
|
|
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
- _ = dom.rebuild(&mut dioxus_core::NoOpMutations);
|
|
|
|
- assert!(dom.render_immediate().edits.is_empty());
|
|
|
|
|
|
+ _ = dom.rebuild_to_vec(&mut dioxus_core::NoOpMutations);
|
|
|
|
+ assert!(dom.render_immediate_to_vec().edits.is_empty());
|
|
}
|
|
}
|
|
|
|
|
|
#[test]
|
|
#[test]
|
|
fn remove_many() {
|
|
fn remove_many() {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
let mut dom = VirtualDom::new(|cx| {
|
|
- let num = match cx.generation() % 3 {
|
|
|
|
|
|
+ let num = match generation() % 3 {
|
|
0 => 0,
|
|
0 => 0,
|
|
1 => 1,
|
|
1 => 1,
|
|
2 => 5,
|
|
2 => 5,
|
|
_ => unreachable!(),
|
|
_ => unreachable!(),
|
|
};
|
|
};
|
|
|
|
|
|
- cx.render(rsx! {
|
|
|
|
- (0..num).map(|i| rsx! { div { "hello {i}" } })
|
|
|
|
- })
|
|
|
|
|
|
+ render! {(0..num).map(|i| render! { div { "hello {i}" } })}
|
|
});
|
|
});
|
|
|
|
|
|
{
|
|
{
|
|
- let edits = dom.rebuild().santize();
|
|
|
|
|
|
+ let edits = dom.rebuild_to_vec().santize();
|
|
assert!(edits.templates.is_empty());
|
|
assert!(edits.templates.is_empty());
|
|
assert_eq!(
|
|
assert_eq!(
|
|
edits.edits,
|
|
edits.edits,
|
|
@@ -329,12 +327,12 @@ fn remove_many() {
|
|
|
|
|
|
{
|
|
{
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
- let edits = dom.render_immediate().santize();
|
|
|
|
|
|
+ let edits = dom.render_immediate_to_vec().santize();
|
|
assert_eq!(
|
|
assert_eq!(
|
|
edits.edits,
|
|
edits.edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
- HydrateText { path: &[0,], value: "hello 0", id: ElementId(3,) },
|
|
|
|
|
|
+ HydrateText { path: &[0,], value: "hello 0".to_string(), id: ElementId(3,) },
|
|
ReplaceWith { id: ElementId(1,), m: 1 },
|
|
ReplaceWith { id: ElementId(1,), m: 1 },
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -342,18 +340,18 @@ fn remove_many() {
|
|
|
|
|
|
{
|
|
{
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
- let edits = dom.render_immediate().santize();
|
|
|
|
|
|
+ let edits = dom.render_immediate_to_vec().santize();
|
|
assert_eq!(
|
|
assert_eq!(
|
|
edits.edits,
|
|
edits.edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(1,) },
|
|
- HydrateText { path: &[0,], value: "hello 1", id: ElementId(4,) },
|
|
|
|
|
|
+ HydrateText { path: &[0,], value: "hello 1".to_string(), id: ElementId(4,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(5,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(5,) },
|
|
- HydrateText { path: &[0,], value: "hello 2", id: ElementId(6,) },
|
|
|
|
|
|
+ HydrateText { path: &[0,], value: "hello 2".to_string(), id: ElementId(6,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(7,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(7,) },
|
|
- HydrateText { path: &[0,], value: "hello 3", id: ElementId(8,) },
|
|
|
|
|
|
+ HydrateText { path: &[0,], value: "hello 3".to_string(), id: ElementId(8,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(9,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(9,) },
|
|
- HydrateText { path: &[0,], value: "hello 4", id: ElementId(10,) },
|
|
|
|
|
|
+ HydrateText { path: &[0,], value: "hello 4".to_string(), id: ElementId(10,) },
|
|
InsertAfter { id: ElementId(2,), m: 4 },
|
|
InsertAfter { id: ElementId(2,), m: 4 },
|
|
]
|
|
]
|
|
);
|
|
);
|
|
@@ -361,7 +359,7 @@ fn remove_many() {
|
|
|
|
|
|
{
|
|
{
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
- let edits = dom.render_immediate().santize();
|
|
|
|
|
|
+ let edits = dom.render_immediate_to_vec().santize();
|
|
assert_eq!(
|
|
assert_eq!(
|
|
edits.edits,
|
|
edits.edits,
|
|
[
|
|
[
|
|
@@ -377,12 +375,12 @@ fn remove_many() {
|
|
|
|
|
|
{
|
|
{
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
dom.mark_dirty(ScopeId::ROOT);
|
|
- let edits = dom.render_immediate().santize();
|
|
|
|
|
|
+ let edits = dom.render_immediate_to_vec().santize();
|
|
assert_eq!(
|
|
assert_eq!(
|
|
edits.edits,
|
|
edits.edits,
|
|
[
|
|
[
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
LoadTemplate { name: "template", index: 0, id: ElementId(2,) },
|
|
- HydrateText { path: &[0,], value: "hello 0", id: ElementId(3,) },
|
|
|
|
|
|
+ HydrateText { path: &[0,], value: "hello 0".to_string(), id: ElementId(3,) },
|
|
ReplaceWith { id: ElementId(11,), m: 1 },
|
|
ReplaceWith { id: ElementId(11,), m: 1 },
|
|
]
|
|
]
|
|
)
|
|
)
|