Skip to content

Commit e96bcec

Browse files
committed
use list-bundle in tag-bundle
1 parent 5339f49 commit e96bcec

10 files changed

Lines changed: 142 additions & 92 deletions

File tree

packages/yew/src/dom_bundle/bcomp.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,38 @@ impl Reconcilable for VComp {
8383
)
8484
}
8585

86-
fn reconcile(
86+
fn reconcile_node(
8787
self,
8888
parent_scope: &AnyScope,
8989
parent: &Element,
9090
next_sibling: NodeRef,
9191
bundle: &mut BNode,
9292
) -> NodeRef {
93-
let bcomp = match bundle {
93+
match bundle {
9494
// If the existing bundle is the same type, reuse it and update its properties
9595
BNode::BComp(ref mut bcomp)
9696
if self.type_id == bcomp.type_id && self.key == bcomp.key =>
9797
{
98-
bcomp
99-
}
100-
_ => {
101-
return self.replace(parent_scope, parent, next_sibling, bundle);
98+
self.reconcile(parent_scope, parent, next_sibling, bcomp)
10299
}
103-
};
100+
_ => self.replace(parent_scope, parent, next_sibling, bundle),
101+
}
102+
}
103+
104+
fn reconcile(
105+
self,
106+
_parent_scope: &AnyScope,
107+
_parent: &Element,
108+
next_sibling: NodeRef,
109+
bcomp: &mut Self::Bundle,
110+
) -> NodeRef {
104111
let VComp {
105112
mountable,
106113
node_ref,
107114
key,
108115
type_id: _,
109116
} = self;
117+
110118
bcomp.key = key;
111119
let old_ref = std::mem::replace(&mut bcomp.node_ref, node_ref.clone());
112120
bcomp.node_ref.reuse(old_ref);
@@ -246,7 +254,7 @@ impl ComponentRenderState {
246254
if let Some(ref parent) = self.parent {
247255
let next_sibling = self.next_sibling.clone();
248256

249-
root.reconcile(scope, parent, next_sibling, &mut self.root_node)
257+
root.reconcile_node(scope, parent, next_sibling, &mut self.root_node)
250258
} else {
251259
#[cfg(feature = "ssr")]
252260
if let Some(tx) = self.html_sender.take() {
@@ -336,7 +344,7 @@ mod tests {
336344

337345
for _ in 0..10000 {
338346
let node = html! { <Comp></Comp> };
339-
node.reconcile(
347+
node.reconcile_node(
340348
&parent_scope,
341349
&parent_element,
342350
NodeRef::default(),

packages/yew/src/dom_bundle/blist.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'s> NodeWriter<'s> {
6868
self.next_sibling
6969
);
7070
// Advance the next sibling reference (from right to left)
71-
let next = node.reconcile(self.parent_scope, self.parent, self.next_sibling, bundle);
71+
let next = node.reconcile_node(self.parent_scope, self.parent, self.next_sibling, bundle);
7272
test_log!(" next_position: {:?}", next);
7373
Self {
7474
next_sibling: next,
@@ -317,21 +317,30 @@ impl Reconcilable for VList {
317317
parent: &Element,
318318
next_sibling: NodeRef,
319319
) -> (NodeRef, Self::Bundle) {
320-
let mut self_ = BNode::BList(BList::new());
320+
let mut self_ = BList::new();
321321
let node_ref = self.reconcile(parent_scope, parent, next_sibling, &mut self_);
322-
let self_ = match self_ {
323-
BNode::BList(self_) => self_,
324-
_ => unreachable!("applying list should leave a VList in bundle ref"),
325-
};
326322
(node_ref, self_)
327323
}
328324

325+
fn reconcile_node(
326+
self,
327+
parent_scope: &AnyScope,
328+
parent: &Element,
329+
next_sibling: NodeRef,
330+
bundle: &mut BNode,
331+
) -> NodeRef {
332+
// 'Forcefully' create a pretend the existing node is a list. Creates a
333+
// singleton list if it isn't already.
334+
let blist = bundle.make_list();
335+
self.reconcile(parent_scope, parent, next_sibling, blist)
336+
}
337+
329338
fn reconcile(
330339
mut self,
331340
parent_scope: &AnyScope,
332341
parent: &Element,
333342
next_sibling: NodeRef,
334-
bundle: &mut BNode,
343+
blist: &mut BList,
335344
) -> NodeRef {
336345
// Here, we will try to diff the previous list elements with the new
337346
// ones we want to insert. For that, we will use two lists:
@@ -350,9 +359,6 @@ impl Reconcilable for VList {
350359
}
351360

352361
let lefts = self.children;
353-
// 'Forcefully' create a pretend the existing node is a list. Creates a
354-
// singleton list if it isn't already.
355-
let blist = bundle.make_list();
356362
let rights = &mut blist.rev_children;
357363
test_log!("lefts: {:?}", lefts);
358364
test_log!("rights: {:?}", rights);

packages/yew/src/dom_bundle/bnode.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ impl Reconcilable for VNode {
117117
}
118118
}
119119

120+
fn reconcile_node(
121+
self,
122+
parent_scope: &AnyScope,
123+
parent: &Element,
124+
next_sibling: NodeRef,
125+
bundle: &mut BNode,
126+
) -> NodeRef {
127+
self.reconcile(parent_scope, parent, next_sibling, bundle)
128+
}
129+
120130
fn reconcile(
121131
self,
122132
parent_scope: &AnyScope,
@@ -125,10 +135,10 @@ impl Reconcilable for VNode {
125135
bundle: &mut BNode,
126136
) -> NodeRef {
127137
match self {
128-
VNode::VTag(vtag) => vtag.reconcile(parent_scope, parent, next_sibling, bundle),
129-
VNode::VText(vtext) => vtext.reconcile(parent_scope, parent, next_sibling, bundle),
130-
VNode::VComp(vcomp) => vcomp.reconcile(parent_scope, parent, next_sibling, bundle),
131-
VNode::VList(vlist) => vlist.reconcile(parent_scope, parent, next_sibling, bundle),
138+
VNode::VTag(vtag) => vtag.reconcile_node(parent_scope, parent, next_sibling, bundle),
139+
VNode::VText(vtext) => vtext.reconcile_node(parent_scope, parent, next_sibling, bundle),
140+
VNode::VComp(vcomp) => vcomp.reconcile_node(parent_scope, parent, next_sibling, bundle),
141+
VNode::VList(vlist) => vlist.reconcile_node(parent_scope, parent, next_sibling, bundle),
132142
VNode::VRef(node) => {
133143
let _existing = match bundle {
134144
BNode::BRef(ref n) if &node == n => n,
@@ -144,10 +154,10 @@ impl Reconcilable for VNode {
144154
NodeRef::new(node)
145155
}
146156
VNode::VPortal(vportal) => {
147-
vportal.reconcile(parent_scope, parent, next_sibling, bundle)
157+
vportal.reconcile_node(parent_scope, parent, next_sibling, bundle)
148158
}
149159
VNode::VSuspense(vsuspsense) => {
150-
vsuspsense.reconcile(parent_scope, parent, next_sibling, bundle)
160+
vsuspsense.reconcile_node(parent_scope, parent, next_sibling, bundle)
151161
}
152162
}
153163
}

packages/yew/src/dom_bundle/bportal.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,26 @@ impl Reconcilable for VPortal {
5656
)
5757
}
5858

59-
fn reconcile(
59+
fn reconcile_node(
6060
self,
6161
parent_scope: &AnyScope,
6262
parent: &Element,
6363
next_sibling: NodeRef,
6464
bundle: &mut BNode,
6565
) -> NodeRef {
66-
let portal = match bundle {
67-
BNode::BPortal(portal) => portal,
68-
_ => {
69-
return self.replace(parent_scope, parent, next_sibling, bundle);
70-
}
71-
};
66+
match bundle {
67+
BNode::BPortal(portal) => self.reconcile(parent_scope, parent, next_sibling, portal),
68+
_ => self.replace(parent_scope, parent, next_sibling, bundle),
69+
}
70+
}
71+
72+
fn reconcile(
73+
self,
74+
parent_scope: &AnyScope,
75+
parent: &Element,
76+
next_sibling: NodeRef,
77+
portal: &mut Self::Bundle,
78+
) -> NodeRef {
7279
let Self {
7380
host,
7481
inner_sibling,
@@ -85,7 +92,7 @@ impl Reconcilable for VPortal {
8592
.node
8693
.shift(&portal.host, portal.inner_sibling.clone());
8794
}
88-
node.reconcile(parent_scope, parent, next_sibling.clone(), &mut portal.node);
95+
node.reconcile_node(parent_scope, parent, next_sibling.clone(), &mut portal.node);
8996
next_sibling
9097
}
9198
}

packages/yew/src/dom_bundle/bsuspense.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,25 +91,32 @@ impl Reconcilable for VSuspense {
9191
}
9292
}
9393

94-
fn reconcile(
94+
fn reconcile_node(
9595
self,
9696
parent_scope: &AnyScope,
9797
parent: &Element,
9898
next_sibling: NodeRef,
9999
bundle: &mut BNode,
100100
) -> NodeRef {
101-
let suspense = match bundle {
101+
match bundle {
102102
// We only preserve the child state if they are the same suspense.
103103
BNode::BSuspense(m)
104104
if m.key == self.key
105105
&& self.detached_parent.as_ref() == Some(&m.detached_parent) =>
106106
{
107-
m
108-
}
109-
_ => {
110-
return self.replace(parent_scope, parent, next_sibling, bundle);
107+
self.reconcile(parent_scope, parent, next_sibling, m)
111108
}
112-
};
109+
_ => self.replace(parent_scope, parent, next_sibling, bundle),
110+
}
111+
}
112+
113+
fn reconcile(
114+
self,
115+
parent_scope: &AnyScope,
116+
parent: &Element,
117+
next_sibling: NodeRef,
118+
suspense: &mut Self::Bundle,
119+
) -> NodeRef {
113120
let VSuspense {
114121
children,
115122
fallback,
@@ -127,24 +134,24 @@ impl Reconcilable for VSuspense {
127134
match (suspended, &mut suspense.fallback_bundle) {
128135
// Both suspended, reconcile children into detached_parent, fallback into the DOM
129136
(true, Some(fallback_bundle)) => {
130-
children.reconcile(
137+
children.reconcile_node(
131138
parent_scope,
132139
&detached_parent,
133140
NodeRef::default(),
134141
children_bundle,
135142
);
136143

137-
fallback.reconcile(parent_scope, parent, next_sibling, fallback_bundle)
144+
fallback.reconcile_node(parent_scope, parent, next_sibling, fallback_bundle)
138145
}
139146
// Not suspended, just reconcile the children into the DOM
140147
(false, None) => {
141-
children.reconcile(parent_scope, parent, next_sibling, children_bundle)
148+
children.reconcile_node(parent_scope, parent, next_sibling, children_bundle)
142149
}
143150
// Freshly suspended. Shift children into the detached parent, then add fallback to the DOM
144151
(true, None) => {
145152
children_bundle.shift(&detached_parent, NodeRef::default());
146153

147-
children.reconcile(
154+
children.reconcile_node(
148155
parent_scope,
149156
&detached_parent,
150157
NodeRef::default(),
@@ -160,7 +167,7 @@ impl Reconcilable for VSuspense {
160167
suspense.fallback_bundle.take().unwrap().detach(parent);
161168

162169
children_bundle.shift(parent, next_sibling.clone());
163-
children.reconcile(parent_scope, parent, next_sibling, children_bundle)
170+
children.reconcile_node(parent_scope, parent, next_sibling, children_bundle)
164171
}
165172
}
166173
}

0 commit comments

Comments
 (0)