@@ -41,25 +41,11 @@ impl ScopeState {
4141 }
4242 }
4343
44- pub fn fragment_from_iter < ' a , ' c , I , J > (
44+ pub fn fragment_from_iter < ' a , ' c , I > (
4545 & ' a self ,
46- node_iter : impl IntoVNode < ' a , I , J > + ' c ,
46+ node_iter : impl IntoDynNode < ' a , I > + ' c ,
4747 ) -> DynamicNode {
4848 node_iter. into_vnode ( self )
49-
50- // let mut bump_vec = bumpalo::vec![in self.bump();];
51-
52- // for item in it {
53- // bump_vec.push(item.into_vnode(self));
54- // }
55-
56- // match bump_vec.len() {
57- // 0 => DynamicNode::Placeholder(Cell::new(ElementId(0))),
58- // _ => DynamicNode::Fragment {
59- // inner: false,
60- // nodes: bump_vec.into_bump_slice(),
61- // },
62- // }
6349 }
6450
6551 /// Create a new [`Attribute`]
@@ -155,46 +141,65 @@ impl<'a> RenderReturn<'a> {
155141 }
156142}
157143
158- pub trait IntoVNode < ' a , A = ( ) , J = ( ) > {
144+ pub trait IntoDynNode < ' a , A = ( ) > {
159145 fn into_vnode ( self , cx : & ' a ScopeState ) -> DynamicNode < ' a > ;
160146}
161147
162- impl < ' a , ' b > IntoVNode < ' a > for VNode < ' a > {
148+ impl < ' a , ' b > IntoDynNode < ' a > for ( ) {
163149 fn into_vnode ( self , _cx : & ' a ScopeState ) -> DynamicNode < ' a > {
164150 todo ! ( )
165151 // self
166152 }
167153}
154+ impl < ' a , ' b > IntoDynNode < ' a > for VNode < ' a > {
155+ fn into_vnode ( self , _cx : & ' a ScopeState ) -> DynamicNode < ' a > {
156+ // DynamicNode::Fragment { nodes: cx., inner: () }
157+ todo ! ( )
158+ }
159+ }
168160
169- impl < ' a , ' b > IntoVNode < ' a > for LazyNodes < ' a , ' b > {
170- fn into_vnode ( self , cx : & ' a ScopeState ) -> DynamicNode < ' a > {
161+ impl < ' a , ' b , T : IntoDynNode < ' a > > IntoDynNode < ' a > for Option < T > {
162+ fn into_vnode ( self , _cx : & ' a ScopeState ) -> DynamicNode < ' a > {
163+ // DynamicNode::Fragment { nodes: cx., inner: () }
171164 todo ! ( )
172- // self.call(cx)
173165 }
174166}
175167
176- impl < ' b > IntoVNode < ' _ > for & ' b str {
177- fn into_vnode ( self , cx : & ScopeState ) -> DynamicNode {
178- // cx.text(format_args!("{}", self))
168+ impl < ' a , ' b , T : IntoDynNode < ' a > > IntoDynNode < ' a > for & Option < T > {
169+ fn into_vnode ( self , _cx : & ' a ScopeState ) -> DynamicNode < ' a > {
170+ // DynamicNode::Fragment { nodes: cx., inner: () }
179171 todo ! ( )
180172 }
181173}
182174
183- impl IntoVNode < ' _ > for String {
175+ impl < ' a , ' b > IntoDynNode < ' a > for LazyNodes < ' a , ' b > {
176+ fn into_vnode ( self , cx : & ' a ScopeState ) -> DynamicNode < ' a > {
177+ DynamicNode :: Fragment {
178+ nodes : cx. bump ( ) . alloc ( [ self . call ( cx) ] ) ,
179+ inner : false ,
180+ }
181+ }
182+ }
183+
184+ impl < ' b > IntoDynNode < ' _ > for & ' b str {
184185 fn into_vnode ( self , cx : & ScopeState ) -> DynamicNode {
185- // cx.text(format_args!("{}", self))
186- todo ! ( )
186+ cx. text ( format_args ! ( "{}" , self ) )
187187 }
188188}
189189
190- impl < ' b > IntoVNode < ' b > for Arguments < ' _ > {
190+ impl IntoDynNode < ' _ > for String {
191+ fn into_vnode ( self , cx : & ScopeState ) -> DynamicNode {
192+ cx. text ( format_args ! ( "{}" , self ) )
193+ }
194+ }
195+
196+ impl < ' b > IntoDynNode < ' b > for Arguments < ' _ > {
191197 fn into_vnode ( self , cx : & ' b ScopeState ) -> DynamicNode < ' b > {
192- // cx.text(self)
193- todo ! ( )
198+ cx. text ( self )
194199 }
195200}
196201
197- impl < ' a , ' b > IntoVNode < ' a > for & VNode < ' a > {
202+ impl < ' a , ' b > IntoDynNode < ' a > for & VNode < ' a > {
198203 fn into_vnode ( self , _cx : & ' a ScopeState ) -> DynamicNode < ' a > {
199204 todo ! ( )
200205 // VNode {
@@ -209,46 +214,43 @@ impl<'a, 'b> IntoVNode<'a> for &VNode<'a> {
209214 }
210215}
211216
217+ pub trait IntoTemplate < ' a > {
218+ fn into_template ( self , _cx : & ' a ScopeState ) -> VNode < ' a > ;
219+ }
220+ impl < ' a , ' b > IntoTemplate < ' a > for VNode < ' a > {
221+ fn into_template ( self , _cx : & ' a ScopeState ) -> VNode < ' a > {
222+ self
223+ }
224+ }
225+ impl < ' a , ' b > IntoTemplate < ' a > for LazyNodes < ' a , ' b > {
226+ fn into_template ( self , cx : & ' a ScopeState ) -> VNode < ' a > {
227+ self . call ( cx)
228+ }
229+ }
230+
212231// Note that we're using the E as a generic but this is never crafted anyways.
213232pub struct FromNodeIterator ;
214- impl < ' a , T , I , E > IntoVNode < ' a , FromNodeIterator , E > for T
233+ impl < ' a , T , I > IntoDynNode < ' a , FromNodeIterator > for T
215234where
216- T : IntoIterator < Item = I > ,
217- I : IntoVNode < ' a , E > ,
235+ T : Iterator < Item = I > ,
236+ I : IntoTemplate < ' a > ,
218237{
219238 fn into_vnode ( self , cx : & ' a ScopeState ) -> DynamicNode < ' a > {
220239 let mut nodes = bumpalo:: collections:: Vec :: new_in ( cx. bump ( ) ) ;
221240
222241 for node in self {
223- nodes. push ( node. into_vnode ( cx) ) ;
242+ nodes. push ( node. into_template ( cx) ) ;
224243 }
225244
226245 let children = nodes. into_bump_slice ( ) ;
227246
228- // if cfg!(debug_assertions) && children.len() > 1 && children.last().unwrap().key().is_none()
229- // {
230- // let bt = backtrace::Backtrace::new();
231- // let bt = "no backtrace available";
232-
233- // // todo: make the backtrace prettier or remove it altogether
234- // log::error!(
235- // r#"
236- // Warning: Each child in an array or iterator should have a unique "key" prop.
237- // Not providing a key will lead to poor performance with lists.
238- // See docs.rs/dioxus for more information.
239- // -------------
240- // {:?}
241- // "#,
242- // bt
243- // );
244- // }
245-
246- todo ! ( )
247- // VNode::Fragment(cx.bump.alloc(VFragment {
248- // children,
249- // placeholder: Default::default(),
250- // key: None,
251- // }))
247+ match children. len ( ) {
248+ 0 => DynamicNode :: Placeholder ( Cell :: new ( ElementId ( 0 ) ) ) ,
249+ _ => DynamicNode :: Fragment {
250+ inner : false ,
251+ nodes : children,
252+ } ,
253+ }
252254 }
253255}
254256
0 commit comments