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,

source

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.

source

pub fn mount_node(&self) -> Node

return the node where the app is mounted into

source

pub fn append_to_mount(app: APP, mount_node: &Node) -> Self

Instantiage an app and append the view to the root_node

Example
struct App{}
let mount = document().query_selector("#app").ok().flatten().unwrap();
Program::append_to_mount(App{}, &mount);
source

pub fn replace_mount(app: APP, mount_node: &Node) -> Self

Creates an Rc wrapped instance of Program and replace the root_node with the app view

Example
struct App{}
let mount = document().query_selector(".container").ok().flatten().unwrap();
Program::replace_mount(App{}, &mount);
source

pub fn clear_append_to_mount(app: APP, mount_node: &Node) -> Self

clear the existing children of the mount first before appending

source

pub fn mount_to_body(app: APP) -> Self

Instantiate the app and then append it to the document body

Example
struct App{}
Program::mount_to_body(App{});
source

pub fn mount(&self)

each element and it’s descendant in the vdom is created into an actual DOM node.

source

pub fn update_dom(&self) -> Result<Measurements, JsValue>

update the browser DOM to reflect the APP’s view

source

pub fn update_dom_with_vdom( &self, new_vdom: Node<MSG> ) -> Result<usize, JsValue>

patch the DOM to reflect the App’s view

source

pub fn set_current_dom(&self, new_vdom: Node<MSG>)

replace the current vdom with the new_vdom.

source

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,

This will be called when the actual event is triggered. Defined in the DomUpdater::create_closure_wrap function

source

pub fn dispatch_multiple(&self, msgs: impl IntoIterator<Item = MSG>)

dispatch multiple MSG

source

pub fn dispatch(&self, msg: MSG)

dispatch a single msg

Trait Implementations§

source§

impl<APP, MSG> Clone for Program<APP, MSG>where MSG: 'static,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<APP, MSG> !RefUnwindSafe for Program<APP, MSG>

§

impl<APP, MSG> !Send for Program<APP, MSG>

§

impl<APP, MSG> !Sync for Program<APP, MSG>

§

impl<APP, MSG> Unpin for Program<APP, MSG>

§

impl<APP, MSG> !UnwindSafe for Program<APP, MSG>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.