Struct sauron_core::dom::Program  
source · pub struct Program<APP, MSG>where
    MSG: 'static,{
    pub node_closures: Rc<RefCell<BTreeMap<usize, BTreeMap<&'static str, Closure<dyn FnMut(Event)>>>>>,
    /* private fields */
}Expand description
Program handle the lifecycle of the APP
Fields§
§node_closures: Rc<RefCell<BTreeMap<usize, BTreeMap<&'static str, Closure<dyn FnMut(Event)>>>>>The closures that are currently attached to all the nodes used in the Application 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,
A node along with all of the closures that were created for that node’s events and all of it’s child node’s events.
sourcepub fn create_text_node(txt: &str) -> Text
 
pub fn create_text_node(txt: &str) -> Text
create a text node
sourcepub fn create_dom_node(&self, vnode: &Node<MSG>) -> Node
 
pub fn create_dom_node(&self, vnode: &Node<MSG>) -> Node
Create and return a CreatedNode instance (containing a DOM Node
together with potentially related closures) for this virtual node.
sourcepub fn dispatch_mount_event(node: &Node)
 
pub fn dispatch_mount_event(node: &Node)
dispatch the mount event, call the listener since browser don’t allow asynchronous execution of dispatching custom events (non-native browser events)
sourcepub fn append_child_and_dispatch_mount_event(parent: &Node, child_node: &Node)
 
pub fn append_child_and_dispatch_mount_event(parent: &Node, child_node: &Node)
a helper method to append a node to its parent and trigger a mount event if there is any
sourcepub fn set_element_attributes(
    &self,
    element: &Element,
    attrs: &[&Attribute<MSG>]
)
 
pub fn set_element_attributes( &self, element: &Element, attrs: &[&Attribute<MSG>] )
set the element attribute
sourcepub fn set_element_attribute(&self, element: &Element, attr: &Attribute<MSG>)
 
pub fn set_element_attribute(&self, element: &Element, attr: &Attribute<MSG>)
set the element attribute
Note: this is called in a loop, so setting the attributes, and style will not be on the same call, but on a subsequent call to each other. Using the if-else-if here for attributes, style, function_call.
sourcepub fn add_event_listeners(
    &self,
    target: &EventTarget,
    event_listeners: Vec<Attribute<MSG>>
) -> Result<(), JsValue>
 
pub fn add_event_listeners( &self, target: &EventTarget, event_listeners: Vec<Attribute<MSG>> ) -> Result<(), JsValue>
attach and event listener to an event target
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,
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) -> ManuallyDrop<Self>
 
pub fn append_to_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
sourcepub fn replace_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
 
pub fn replace_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
sourcepub fn clear_append_to_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
 
pub fn clear_append_to_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
clear the existing children of the mount before mounting the app
sourcepub fn clear_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
 
pub fn clear_mount(app: APP, mount_node: &Node) -> ManuallyDrop<Self>
clear the existing children of the mount before mounting the app
sourcepub fn clear_mount_to_body(app: APP) -> ManuallyDrop<Self>
 
pub fn clear_mount_to_body(app: APP) -> ManuallyDrop<Self>
clear the existing children of the document body before mounting the app
sourcepub fn mount_to_body(app: APP) -> ManuallyDrop<Self>
 
pub fn mount_to_body(app: APP) -> ManuallyDrop<Self>
sourcepub fn mount(&mut self)
 
pub fn mount(&mut self)
each element and it’s descendant in the vdom is created into an actual DOM node.
sourcepub fn update_dom(
    &mut self,
    modifier: &Modifier
) -> Result<Measurements, JsValue>
 
pub fn update_dom( &mut self, modifier: &Modifier ) -> Result<Measurements, JsValue>
update the browser DOM to reflect the APP’s view
sourcepub fn update_dom_with_vdom(
    &mut self,
    new_vdom: Node<MSG>
) -> Result<usize, JsValue>
 
pub fn update_dom_with_vdom( &mut self, new_vdom: Node<MSG> ) -> Result<usize, JsValue>
patch the DOM to reflect the App’s view
Note: This is in another function so as to allow tests to use this shared code
sourcepub fn inject_style_to_mount(&mut self, style: &str)
 
pub fn inject_style_to_mount(&mut self, style: &str)
inject style element to the mount node
sourcepub fn dispatch_multiple(&mut self, msgs: impl IntoIterator<Item = MSG>)
 
pub fn dispatch_multiple(&mut self, msgs: impl IntoIterator<Item = MSG>)
dispatch multiple MSG
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 add_window_event_listeners(&self, event_listeners: Vec<Attribute<MSG>>)
 
pub fn add_window_event_listeners(&self, event_listeners: Vec<Attribute<MSG>>)
attach event listeners to the window
sourcepub fn on_resize<F>(&self, cb: F)where
    F: FnMut(i32, i32) -> MSG + Clone + 'static,
 
pub fn on_resize<F>(&self, cb: F)where F: FnMut(i32, i32) -> MSG + Clone + 'static,
Creates a Cmd in which the MSG will be emitted whenever the browser is resized
sourcepub fn on_resize_task<F>(cb: F) -> Task<MSG>where
    F: FnMut(i32, i32) -> MSG + Clone + 'static,
 
pub fn on_resize_task<F>(cb: F) -> Task<MSG>where F: FnMut(i32, i32) -> MSG + Clone + 'static,
TODO: only executed once, since the Task Future is droped once done TODO: this should be a stream, instead of just one-time future a variant of resize task, but instead of returning Cmd, it is returning Task
sourcepub fn on_hashchange<F>(&self, cb: F)where
    F: FnMut(String) -> MSG + 'static,
 
pub fn on_hashchange<F>(&self, cb: F)where F: FnMut(String) -> MSG + 'static,
attached a callback and will be triggered when the hash portion of the window location url is changed