Struct titik::Callback[][src]

pub struct Callback<EVENT, MSG>(_);

A generic sized representation of a function that can be attached to a Node. The callback will essentially be owned by the element

Limitations: The callback takes an Fn instead of FnMut, therefore it can not mutate the environment variables

In effect callbacks attached to DOM events are limited to only passing an MSG to the program and not complex statements.

Note: It would have been nice to have the inner value be Rc<FnMut(EVENT) -> MSG> +'a but there are a lot of issues that this becomes infeasible: 1 - wasm_bindgen::Closure requires that ’static references to the closure 2 - Accessing Rc::get_mut requires that there is no other Rc or Weak references else where. - We could be iterating on the elements for recursively setting the attributes which is not allowed to have recursive mutable iteration - Attributes of the same name are merged therefore cloning the attributes, hence the callback is necessary.

Implementations

impl<EVENT, MSG> Callback<EVENT, MSG> where
    EVENT: 'static,
    MSG: 'static, 
[src]

pub fn emit<T>(&self, value: T) -> MSG where
    T: Into<EVENT>, 
[src]

This method calls the actual callback.

pub fn map_callback<MSG2>(
    self,
    cb: Callback<MSG, MSG2>
) -> Callback<EVENT, MSG2> where
    MSG2: 'static, 
[src]

map this callback using another callback such that MSG becomes MSG2

Trait Implementations

impl<EVENT, MSG> Clone for Callback<EVENT, MSG>[src]

Note: using the #[derive(Clone)] needs EVENT and MSG to also be Clone

The reason this is manually implemented is, so that EVENT and MSG doesn’t need to be Clone as it is part of the Callback objects and cloning here is just cloning the pointer of the actual callback function

impl<EVENT, MSG> Debug for Callback<EVENT, MSG>[src]

Note: using the #[derive(Debug)] needs EVENT and MSG to also be Debug

The reason this is manually implemented is, so that EVENT and MSG doesn’t need to be Debug as it is part of the Callback objects and are not shown.

impl<EVENT, F, MSG> From<F> for Callback<EVENT, MSG> where
    F: Fn(EVENT) -> MSG + 'static, 
[src]

impl<EVENT, MSG> PartialEq<Callback<EVENT, MSG>> for Callback<EVENT, MSG>[src]

Note: using the #[derive(PartialEq)] needs EVENT and MSG to also be PartialEq.

The reason this is manually implemented is, so that EVENT and MSG doesn’t need to be PartialEq as it is part of the Callback objects and are not compared

Note: There is no 2 closures are equal, even if they are logically the same. We return true here so as to not make a diff for the callback attribute. Replacing the callback function for each view call is in-efficient.

Auto Trait Implementations

impl<EVENT, MSG> !RefUnwindSafe for Callback<EVENT, MSG>

impl<EVENT, MSG> !Send for Callback<EVENT, MSG>

impl<EVENT, MSG> !Sync for Callback<EVENT, MSG>

impl<EVENT, MSG> Unpin for Callback<EVENT, MSG>

impl<EVENT, MSG> !UnwindSafe for Callback<EVENT, MSG>

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<T> for T[src]

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

impl<T> Pointable for T

type Init = T

The type for initializers.

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.