Struct kobold::stateful::Hook

source ·
#[repr(transparent)]
pub struct Hook<S> { /* private fields */ }
Expand description

A hook into some state S. A reference to Hook is obtained by using the stateful function.

Hook can be read from though its Deref implementation, and it allows for mutations either by binding closures to it.

Implementations§

source§

impl<S> Hook<S>

source

pub fn bind<E, F, O>(&self, callback: F) -> Bound<'_, S, F>where S: 'static, E: EventCast, F: Fn(&mut S, E) -> O + 'static, O: ShouldRender,

Binds a closure to a mutable reference of the state. While this method is public it’s recommended to use the bind! macro instead.

source

pub fn bind_async<E, F, T>(&self, callback: F) -> impl Listener<E>where S: 'static, E: EventCast, F: Fn(Signal<S>, E) -> T + 'static, T: Future<Output = ()> + 'static,

source

pub fn get(&self) -> Swhere S: Copy,

Get the value of state if state implements Copy. This is equivalent to writing **hook but conveys intent better.

Trait Implementations§

source§

impl<S> Deref for Hook<S>

§

type Target = S

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'a, V> View for &'a Hook<V>where &'a V: View + 'a,

§

type Product = <&'a V as View>::Product

The product should contain a DOM reference to this View and any data it needs to update itself.
source§

fn build(self, p: In<'_, Self::Product>) -> Out<'_, Self::Product>

Build a product that can be mounted in the DOM from this type.
source§

fn update(self, p: &mut Self::Product)

Update the product and apply changes to the DOM if necessary.
source§

fn on_mount<F>(self, handler: F) -> OnMount<Self, F>where F: FnOnce(&<Self::Product as Mountable>::Js), Self: Sized,

Once this view is built, do something once.
source§

fn on_render<F>(self, handler: F) -> OnRender<Self, F>where F: FnOnce(&<Self::Product as Mountable>::Js), Self: Sized,

Similar to on_mount but triggers on every update, not just initial render.

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Hook<S>

§

impl<S> !Send for Hook<S>

§

impl<S> !Sized for Hook<S>

§

impl<S> !Sync for Hook<S>

§

impl<S> !Unpin for Hook<S>

§

impl<S> !UnwindSafe for Hook<S>

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