1use crate::*;
2
3pub fn create_dynamic_node<F>(mut render_fn: F) -> VirtualNode
15where
16 F: FnMut() -> VirtualNode + 'static,
17{
18 let hook_context: HookContext = create_hook_context();
19 let mut hook_context_for_closure: HookContext = hook_context.clone();
20 let inner: Rc<RefCell<RenderFnInner>> =
21 Rc::new(RefCell::new(RenderFnInner::new(Box::new(move || {
22 hook_context_for_closure.reset_hook_index();
23 render_fn()
24 }))));
25 let dynamic_node: DynamicNode = DynamicNode::new(inner, hook_context);
26 VirtualNode::Dynamic(dynamic_node)
27}
28
29pub fn create_dynamic_node_with_context<F>(mut render_fn: F) -> VirtualNode
43where
44 F: FnMut(&mut HookContext) -> VirtualNode + 'static,
45{
46 let hook_context: HookContext = create_hook_context();
47 let mut hook_context_for_closure: HookContext = hook_context.clone();
48 let inner: Rc<RefCell<RenderFnInner>> =
49 Rc::new(RefCell::new(RenderFnInner::new(Box::new(move || {
50 hook_context_for_closure.reset_hook_index();
51 render_fn(&mut hook_context_for_closure)
52 }))));
53 let dynamic_node: DynamicNode = DynamicNode::new(inner, hook_context);
54 VirtualNode::Dynamic(dynamic_node)
55}