@@ -21,7 +21,7 @@ use std::rc::Rc;
2121cfg_if ! {
2222 if #[ cfg( feature = "std_web" ) ] {
2323 use crate :: html:: EventListener ;
24- use stdweb:: web:: { Element , Node } ;
24+ use stdweb:: web:: { Element , INode , Node } ;
2525 } else if #[ cfg( feature = "web_sys" ) ] {
2626 use gloo:: events:: EventListener ;
2727 use web_sys:: { Element , Node } ;
@@ -256,23 +256,47 @@ pub(crate) trait VDiff {
256256 ) -> Node ;
257257}
258258
259- fn insert_node ( node : & Node , parent : & Node , node_position : & VDiffNodePosition ) -> Node {
259+ #[ cfg( feature = "web_sys" ) ]
260+ fn insert_node ( node : & Node , parent : & Element , node_position : & VDiffNodePosition ) -> Node {
260261 match node_position {
261262 VDiffNodePosition :: FirstChild => parent
262263 . insert_before ( & node, parent. first_child ( ) . as_ref ( ) )
263- . expect ( "can't insert tag before next sibling" ) ,
264+ . expect ( "failed to insert tag before next sibling" ) ,
264265 VDiffNodePosition :: Before ( next_sibling) => parent
265266 . insert_before ( & node, Some ( next_sibling) )
266- . expect ( "can't insert tag before next sibling" ) ,
267+ . expect ( "failed to insert tag before next sibling" ) ,
267268 VDiffNodePosition :: After ( previous_sibling) => parent
268269 . insert_before ( & node, previous_sibling. next_sibling ( ) . as_ref ( ) )
269- . expect ( "can't insert tag before next sibling" ) ,
270- VDiffNodePosition :: LastChild => parent
271- . append_child ( & node)
272- . expect ( "can't insert tag before next sibling" ) ,
270+ . expect ( "failed to insert tag before next sibling" ) ,
271+ VDiffNodePosition :: LastChild => parent. append_child ( node) . expect ( "failed to append tag" ) ,
273272 }
274273}
275274
275+ #[ cfg( feature = "std_web" ) ]
276+ fn insert_node ( node : & impl INode , parent : & impl INode , node_position : & VDiffNodePosition ) -> Node {
277+ fn insert_before ( node : & impl INode , parent : & impl INode , reference : Option < & Node > ) {
278+ if let Some ( reference) = reference {
279+ parent
280+ . insert_before ( node, reference)
281+ . expect ( "failed to insert tag before next sibling" ) ;
282+ } else {
283+ parent. append_child ( node) ;
284+ }
285+ }
286+
287+ match node_position {
288+ VDiffNodePosition :: FirstChild => {
289+ insert_before ( node, parent, parent. first_child ( ) . as_ref ( ) )
290+ }
291+ VDiffNodePosition :: Before ( next_sibling) => insert_before ( node, parent, Some ( next_sibling) ) ,
292+ VDiffNodePosition :: After ( previous_sibling) => {
293+ insert_before ( node, parent, previous_sibling. next_sibling ( ) . as_ref ( ) )
294+ }
295+ VDiffNodePosition :: LastChild => parent. append_child ( node) ,
296+ }
297+ node. as_node ( ) . clone ( )
298+ }
299+
276300/// Transform properties to the expected type.
277301pub trait Transformer < FROM , TO > {
278302 /// Transforms one type to another.
0 commit comments