Skip to main content

EventDispatcher

Struct EventDispatcher 

Source
pub struct EventDispatcher { /* private fields */ }

Implementations§

Source§

impl EventDispatcher

Source

pub fn new() -> Self

Source

pub fn get_listeners(&self) -> &HashMap<String, Vec<Sender<Option<Value>>>>

@description: 获取事件列表 @author: tgy3300 @Date: 2025-03-29 12:20:36 @param {} self @return {}

Source

pub fn add_event_listener( &mut self, name: &str, listener: Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>, )

@description: 订阅事件 @author: tgy3300 @Date: 2025-03-29 12:20:08 @param {} name 事件名 @param {Option} listener 事件方法 @return {}

Source

pub fn has_event_listener( &self, name: &str, listener: Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>, ) -> bool

@description: 判断事件名下指定事件方法是否存在,这里有问题,无法通过listener区分判断 @author: tgy3300 @Date: 2025-03-29 12:19:38 @param {} name @param {EventListener} listener @return {}

Source

pub fn has_event(&self, name: &str) -> bool

@description: 判断事件是否存在 @author: tgy3300 @Date: 2025-03-29 12:19:11 @param {} name @return {}

Source

pub fn remove_event_listener( &mut self, name: &str, listener: Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>, )

@description: 移除事件下指定事件方法(包括该事件对应的节流事件和防抖事件) @author: tgy3300 @Date: 2025-03-29 12:17:39 @param {} name 事件名 @param {EventListener} listener 事件方法 @return {}

Source

pub fn remove_event(&mut self, name: &str)

@description: 移除事件 @author: tgy3300 @Date: 2025-03-29 12:17:00 @param {} name 事件名 @return {}

Source

pub fn dispatch_event(&self, event: Event)

@description: 触发事件 @author: tgy3300 @Date: 2025-03-29 12:15:47 @param {Event} event 事件数据 @return {*}

Source

pub fn once( &self, _name: &str, _listener: Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>, )

@description: 一次性触发,触发之后会自动移除,再次触发无效果 @author: tgy3300 @Date: 2025-03-29 12:13:34 @param {} self @param {} _name @param {Option} _listener @return {*}

Source

pub fn emit(&self, name: &str, params: Option<Value>)

@description: 触发事件 @author: tgy3300 @Date: 2025-03-29 12:13:05 @param {} name 事件名 @param {Option} params 事件参数 @return {}

Source

pub fn on<F, Fut>(&mut self, name: &str, listener: F)
where F: Fn(Option<Value>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + Sync + 'static,

@description: 订阅事件 @author: tgy3300 @Date: 2025-03-29 12:12:40 @param {} name 事件名 @param {Option} listener 事件方法 @return {}

Source

pub fn has( &self, name: &str, listener: Option<Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>>, ) -> bool

@description: 判断事件名、事件名下指定事件方法是否存在,通过listener区分判断 @author: tgy3300 @Date: 2025-03-29 12:10:06 @param {} name 事件名 @param {Option} listener 事件方法 @return {}

Source

pub fn off( &mut self, name: &str, listener: Option<Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>>, )

@description: 移除事件,如果不传listener就会移除整个name事件 @author: tgy3300 @Date: 2025-03-29 12:09:22 @param {} name 事件名 @param {Option} listener 事件方法 @return {}

Source

pub fn event_count(&self, name: &str) -> usize

@description: 获取该事件类型下的事件数量 @author: tgy3300 @Date: 2025-03-29 12:06:55 @param {} name 事件名 @return {}

Source

pub fn pop_latest_event(&mut self, name: &str) -> bool

@description: 销毁该类型的最后一个事件 @author: tgy3300 @Date: 2025-03-29 12:05:38 @param {} name 事件名 @return {}

Source

pub fn clear(&mut self)

@description: 清空所有事件类型的事件 @author: tgy3300 @Date: 2025-03-29 12:05:14 @return {*}

Source

pub fn useful(&self) -> bool

@description: 当前派发器是否使用 @author: tgy3300 @Date: 2025-03-29 12:04:43 @return {*}

Source

pub fn on_throttle( &self, _name: &str, _listener: Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>, _time: u64, )

@description: 节流触发 @author: tgy3300 @Date: 2025-03-29 12:06:04 @param {} name 事件名 @param {Option} listener 事件方法 @param {u64} time 节流时间 @return {}

Source

pub fn on_anti_shake( &self, _name: &str, _listener: Box<dyn Fn(Option<Value>) -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync>, _time: u64, )

@description: 防抖触发 @author: tgy3300 @Date: 2025-03-29 12:06:23 @param {} name 事件名 @param {Option} listener 事件方法 @param {u64} time 防抖时间 @return {}

Trait Implementations§

Source§

impl Clone for EventDispatcher

Source§

fn clone(&self) -> EventDispatcher

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EventDispatcher

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.