[][src]Struct mogwai::gizmo::Gizmo

pub struct Gizmo<T: Component> {
    pub trns: Transmitter<T::ModelMsg>,
    pub recv: Receiver<T::ViewMsg>,
    pub state: Rc<RefCell<T>>,
}

A user interface component that can spawn views.

Fields

trns: Transmitter<T::ModelMsg>

This gizmo's Component::ModelMsg transmitter. Sending on this Transmitter causes its Component::update function to run.

recv: Receiver<T::ViewMsg>

This gizmo's Component::ViewMsg receiver. Clones of this receiver are owned by all of this gizmo's views.

state: Rc<RefCell<T>>

This gizmo's internal state.

Implementations

impl<T> Gizmo<T> where
    T: Component + 'static,
    T::ViewMsg: Clone,
    T::DomNode: JsCast + AsRef<Node> + Clone
[src]

pub fn from_parts(
    init: T,
    tx_in: Transmitter<T::ModelMsg>,
    rx_out: Receiver<T::ViewMsg>
) -> Self
[src]

Create a new Gizmo from an initial state using a view and the Transmitter + Receiver used to create that view.

pub fn new(init: T) -> Gizmo<T>[src]

Create a new Gizmo from a stateful Component. This will create a 'fresh' view.

pub fn view_builder(&self) -> ViewBuilder<T::DomNode>[src]

Use the Gizmo to spawn a ViewBuilder<T::DomNode>. This allows you to send the builder (or subsequent view) somewhere else while still maintaining the ability to update the view from afar.

pub fn send(&self, msg: &T::ModelMsg)[src]

Update the component with the given message. This how a parent component communicates down to its child components.

pub fn visit<F, A>(&self, f: F) -> A where
    A: 'static,
    F: FnOnce(&T) -> A, 
[src]

Visit the wrapped value with a function that produces a value.

pub fn with_state<F, N>(&self, f: F) -> N where
    F: Fn(&T) -> N, 
[src]

Access the underlying state.

pub fn set_state(&mut self, t: T)[src]

Set this gizmo's state.

This silently updates the state and doesn't trigger any messages and does not update the view.

pub fn state_ref(&self) -> Ref<'_, T>[src]

Borrow a reference to the inner state.

Trait Implementations

impl<T: Clone + Component> Clone for Gizmo<T> where
    T::ModelMsg: Clone,
    T::ViewMsg: Clone
[src]

impl<T> From<Gizmo<T>> for View<<T as Component>::DomNode> where
    T: Component,
    <T as Component>::DomNode: JsCast + AsRef<Node>, 
[src]

impl<T: Component> From<T> for Gizmo<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Gizmo<T>[src]

impl<T> !Send for Gizmo<T>[src]

impl<T> !Sync for Gizmo<T>[src]

impl<T> Unpin for Gizmo<T>[src]

impl<T> !UnwindSafe for Gizmo<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.