Struct sauron_core::dom::Program
source · pub struct Program<APP, MSG>where
MSG: 'static,{
pub app: Rc<RefCell<APP>>,
pub active_closures: Rc<RefCell<BTreeMap<usize, Vec<(&'static str, Closure<dyn FnMut(Event)>)>>>>,
/* private fields */
}
Expand description
Program handle the lifecycle of the APP
Fields§
§app: Rc<RefCell<APP>>
holds the user application
active_closures: Rc<RefCell<BTreeMap<usize, Vec<(&'static str, Closure<dyn FnMut(Event)>)>>>>
The closures that are currently attached to elements in the page.
We keep these around so that they don’t get dropped (and thus stop working);
Implementations§
source§impl<APP, MSG> Program<APP, MSG>where
MSG: 'static,
APP: Application<MSG> + 'static,
impl<APP, MSG> Program<APP, MSG>where MSG: 'static, APP: Application<MSG> + 'static,
sourcepub fn new(
app: APP,
mount_node: &Node,
action: MountAction,
target: MountTarget
) -> Self
pub fn new( app: APP, mount_node: &Node, action: MountAction, target: MountTarget ) -> Self
Create an Rc wrapped instance of program, initializing DomUpdater with the initial view and root node, but doesn’t mount it yet.
sourcepub fn mount_node(&self) -> Node
pub fn mount_node(&self) -> Node
return the node where the app is mounted into
sourcepub fn append_to_mount(app: APP, mount_node: &Node) -> Self
pub fn append_to_mount(app: APP, mount_node: &Node) -> Self
sourcepub fn replace_mount(app: APP, mount_node: &Node) -> Self
pub fn replace_mount(app: APP, mount_node: &Node) -> Self
sourcepub fn clear_append_to_mount(app: APP, mount_node: &Node) -> Self
pub fn clear_append_to_mount(app: APP, mount_node: &Node) -> Self
clear the existing children of the mount first before appending
sourcepub fn mount_to_body(app: APP) -> Self
pub fn mount_to_body(app: APP) -> Self
sourcepub fn mount(&self)
pub fn mount(&self)
each element and it’s descendant in the vdom is created into an actual DOM node.
sourcepub fn update_dom(&self) -> Result<Measurements, JsValue>
pub fn update_dom(&self) -> Result<Measurements, JsValue>
update the browser DOM to reflect the APP’s view
sourcepub fn update_dom_with_vdom(
&self,
new_vdom: Node<MSG>
) -> Result<usize, JsValue>
pub fn update_dom_with_vdom( &self, new_vdom: Node<MSG> ) -> Result<usize, JsValue>
patch the DOM to reflect the App’s view
sourcepub fn set_current_dom(&self, new_vdom: Node<MSG>)
pub fn set_current_dom(&self, new_vdom: Node<MSG>)
replace the current vdom with the new_vdom
.
sourcepub fn inject_style_to_mount(&self, style: &str)
pub fn inject_style_to_mount(&self, style: &str)
inject style element to the mount node
source§impl<APP, MSG> Program<APP, MSG>where
MSG: 'static,
APP: Application<MSG> + 'static,
impl<APP, MSG> Program<APP, MSG>where MSG: 'static, APP: Application<MSG> + 'static,
This will be called when the actual event is triggered. Defined in the DomUpdater::create_closure_wrap function
sourcepub fn dispatch_multiple(&self, msgs: impl IntoIterator<Item = MSG>)
pub fn dispatch_multiple(&self, msgs: impl IntoIterator<Item = MSG>)
dispatch multiple MSG