Function respo::render_node

source ·
pub fn render_node<T, U>(
    mount_target: Node,
    get_store: Box<dyn Fn() -> U>,
    renderer: Box<dyn FnMut() -> Result<RespoNode<T>, String>>,
    dispatch_action: DispatchFn<T>,
    interval: Option<i32>
) -> Result<(), JsValue>where
    T: 'static + Debug + Clone,
    U: Debug + Clone + PartialEq + 'static,
Expand description

render elements

Examples found in repository?
src/respo/app_template.rs (lines 52-62)
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  fn render_loop(&self) -> Result<(), String> {
    let mount_target = self.get_mount_target();
    let global_store = self.get_store();
    let memo_caches = self.get_memo_caches();

    let store_to_action = global_store.clone();
    let store_to_action2 = global_store.clone();
    let dispatch_action = move |op: Self::Action| -> Result<(), String> {
      // util::log!("action {:?} store, {:?}", op, store_to_action.borrow());
      let mut store = store_to_action.borrow_mut();

      Self::dispatch(&mut store, op)?;
      // util::log!("store after action {:?}", store);
      Ok(())
    };

    render_node(
      mount_target.to_owned(),
      Box::new(move || store_to_action2.borrow().clone()),
      Box::new(move || -> Result<RespoNode<Self::Action>, String> {
        // util::log!("global store: {:?}", store);

        Self::view(global_store.borrow(), memo_caches.clone())
      }),
      DispatchFn::new(dispatch_action),
      Self::get_loop_delay(),
    )
    .expect("rendering node");

    Ok(())
  }