Hook

Trait Hook 

Source
pub trait Hook: Unpin + Send {
    // Provided methods
    fn poll_change(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()> { ... }
    fn pre_component_update(&mut self, _updater: &mut ComponentUpdater<'_, '_>) { ... }
    fn post_component_update(&mut self, _updater: &mut ComponentUpdater<'_, '_>) { ... }
    fn pre_component_draw(&mut self, _drawer: &mut ComponentDrawer<'_, '_>) { ... }
    fn post_component_draw(&mut self, _drawer: &mut ComponentDrawer<'_, '_>) { ... }
    fn on_drop(&mut self) { ... }
}
Expand description

所有自定义 hook 的 trait 基础,定义生命周期相关回调。

  • poll_change:异步/响应式副作用轮询,适合 use_future/use_effect 等。
  • pre_component_update/post_component_update:组件更新前后钩子。
  • pre_component_draw/post_component_draw:组件渲染前后钩子。

通常无需手动实现,除非自定义复杂 hook。

Provided Methods§

Source

fn poll_change(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()>

Source

fn pre_component_update(&mut self, _updater: &mut ComponentUpdater<'_, '_>)

Source

fn post_component_update(&mut self, _updater: &mut ComponentUpdater<'_, '_>)

Source

fn pre_component_draw(&mut self, _drawer: &mut ComponentDrawer<'_, '_>)

Source

fn post_component_draw(&mut self, _drawer: &mut ComponentDrawer<'_, '_>)

Source

fn on_drop(&mut self)

Implementations on Foreign Types§

Source§

impl Hook for Vec<Box<dyn AnyHook>>

Source§

fn poll_change(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<()>

Source§

fn pre_component_update(&mut self, _updater: &mut ComponentUpdater<'_, '_>)

Source§

fn post_component_update(&mut self, _updater: &mut ComponentUpdater<'_, '_>)

Source§

fn pre_component_draw(&mut self, _updater: &mut ComponentDrawer<'_, '_>)

Source§

fn post_component_draw(&mut self, _updater: &mut ComponentDrawer<'_, '_>)

Source§

fn on_drop(&mut self)

Implementors§