Split setup_el to 2 functions
@@ -369,14 +369,14 @@ impl<Ms: Clone, Mdl> App<Ms, Mdl> {
}
}
-fn setup_el<Ms>(document: &Document, el: &mut El<Ms>)
+/// Set up controlled components: Input, Select, and TextArea elements must stay in sync with the
+/// model; don't let them get out of sync from typing or other events, which can occur if a change
+/// doesn't trigger a re-render, or if something else modifies them using a side effect.
+/// Handle controlled inputs: Ie force sync with the model.
+fn setup_input_listener<Ms>(el: &mut El<Ms>)
where
Ms: Clone + 'static,
{
- // Set up controlled components: Input, Select, and TextArea elements must stay in sync with the model;
- // don't let them get out of sync from typing or other events, which can occur if a change
- // doesn't trigger a re-render, or if something else modifies them using a side effect.
- // Handle controlled inputs: Ie force sync with the model.
if el.tag == dom_types::Tag::Input || el.tag == dom_types::Tag::Select || el.tag == dom_types::Tag::TextArea {
let listener = if let Some(checked) = el.attrs.vals.get(&dom_types::At::Checked) {
let checked_bool = match checked.as_ref() {
@@ -393,23 +393,27 @@ where
};
el.listeners.push(listener); // Add to the El, so we can deattach later.
}
+}
- // Create the web_sys element; add it to the working tree; store it in
- // its corresponding vdom El.
- let el_ws = websys_bridge::make_websys_el(el, document);
-
- el.el_ws = Some(el_ws);
+// Create the web_sys element; add it to the working tree; store it in its corresponding vdom El.
+fn setup_websys_el<Ms>(document: &Document, el: &mut El<Ms>)
+where
+ Ms: Clone + 'static,
+{
+ el.el_ws = Some(websys_bridge::make_websys_el(el, document));
}
/// Populate the attached web_sys elements. Run this after creating a vdom, but before using it to
/// process the web_sys dom. Does not attach children in the DOM. Run this on the top-level
/// element.
-pub(crate) fn setup_els<Ms>(document: &Document, el_vdom: &mut El<Ms>)
-// pub for tests.
+fn setup_els<Ms>(document: &Document, el_vdom: &mut El<Ms>)
where
Ms: Clone + 'static,
{
- el_vdom.walk_tree_mut(|el| setup_el(document, el));
+ el_vdom.walk_tree_mut(|el| {
+ setup_input_listener(el);
+ setup_websys_el(document, el);
+ });
}
impl<Ms: Clone, Mdl> Clone for App<Ms, Mdl> {
