nxkit
Version:
This is a collection of tools, independent of any other libraries
218 lines (217 loc) • 7.54 kB
TypeScript
export declare class ListItem<T> {
private _host;
private _prev;
private _next;
private _value;
constructor(host: List<T>, prev: ListItem<T> | null, next: ListItem<T> | null, value: T);
get host(): List<T> | null;
get prev(): ListItem<T> | null;
get next(): ListItem<T> | null;
get value(): T | null;
set value(value: T | null);
}
/**
* @class List linked
*/
export declare class List<T> {
private _first;
private _last;
private _length;
get first(): ListItem<T> | null;
get last(): ListItem<T> | null;
get length(): number;
del(item: ListItem<T>): ListItem<T> | null;
unshift(value: T): ListItem<T>;
push(value: T): ListItem<T>;
pop(): T | null;
shift(): T | null;
insert(prev: ListItem<T>, value: T): ListItem<T>;
clear(): void;
}
/**
* @class Event
*/
export declare class Event<Data = any, Sender extends object = object> {
private m_data;
protected m_noticer: EventNoticer<Event<Data, Sender>> | null;
private m_return_value;
private m_origin;
get name(): string;
get data(): Data;
get sender(): Sender;
get origin(): any;
set origin(value: any);
get noticer(): EventNoticer<Event<Data, Sender>> | null;
get returnValue(): number;
set returnValue(value: number);
/**
* @constructor
*/
constructor(data: Data, returnValue?: number);
}
declare type DefaultEvent = Event;
export interface Listen<Event = DefaultEvent, Scope extends object = object> {
(this: Scope, evt: Event): any;
}
export interface Listen2<Event = DefaultEvent, Scope extends object = object> {
(scope: Scope, evt: Event): any;
}
/**
* @class EventNoticer
*/
export declare class EventNoticer<E = Event> {
private m_name;
private m_sender;
private m_listens;
private m_listens_map;
private m_length;
private m_enable;
private _add;
/**
* @get enable {bool} # 获取是否已经启用
*/
get enable(): boolean;
/**
* @set enable {bool} # 设置, 启用/禁用
*/
set enable(value: boolean);
/**
* @get name {String} # 事件名称
*/
get name(): string;
/**
* @get {Object} # 事件发送者
*/
get sender(): any;
/**
*
* @get {int} # 添加的事件侦听数量
*/
get length(): number;
/**
* @constructor
* @arg name {String} # 事件名称
* @arg sender {Object} # 事件发起者
*/
constructor(name: string, sender: object);
/**
* @fun on # 绑定一个事件侦听器(函数)
* @arg listen {Function} # 侦听函数
* @arg [scope] {Object} # 重新指定侦听函数this
* @arg [id] {String} # 侦听器别名,可通过id删除
*/
on<Scope extends object>(listen: Listen<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
/**
* @fun once # 绑定一个侦听器(函数),且只侦听一次就立即删除
* @arg listen {Function} # 侦听函数
* @arg [scope] {Object} # 重新指定侦听函数this
* @arg [id] {String} # 侦听器别名,可通过id删除
*/
once<Scope extends object>(listen: Listen<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
/**
* Bind an event listener (function),
* and "on" the same processor of the method to add the event trigger to receive two parameters
* @fun on2
* @arg listen {Function} # 侦听函数
* @arg [scope] {Object} # 重新指定侦听函数this
* @arg [id] {String} # 侦听器别名,可通过id删除
*/
on2<Scope extends object>(listen: Listen2<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
/**
* Bind an event listener (function), And to listen only once and immediately remove
* and "on" the same processor of the method to add the event trigger to receive two parameters
* @fun once2
* @arg listen {Function} # 侦听函数
* @arg [scope] {Object} # 重新指定侦听函数this
* @arg [id] {String} # 侦听器id,可通过id删除
*/
once2<Scope extends object>(listen: Listen2<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
forward(noticer: EventNoticer<E>, id?: string): string;
forwardOnce(noticer: EventNoticer<E>, id?: string): string;
/**
* @fun trigger # 通知所有观察者
* @arg data {Object} # 要发送的数据
* @ret {Object}
*/
trigger(data?: any): number;
/**
* @fun triggerWithEvent # 通知所有观察者
* @arg data {Object} 要发送的event
* @ret {Object}
*/
triggerWithEvent(evt: E): number;
/**
* @fun off # 卸载侦听器(函数)
* @arg [func] {Object} # 可以是侦听函数,id,如果不传入参数卸载所有侦听器
* @arg [scope] {Object} # scope
*/
off(listen?: string | Function | object, scope?: object): number;
}
/**
* @class Notification
*/
export declare class Notification<E = Event> {
/**
* @func getNoticer
*/
getNoticer(name: string): EventNoticer<E>;
/**
* @func hasNoticer
*/
hasNoticer(name: string): boolean;
/**
* @func addDefaultListener
*/
addDefaultListener(name: string, listen: Listen<E> | null): void;
/**
* @func addEventListener(name, listen[,scope[,id]])
*/
addEventListener<Scope extends object>(name: string, listen: Listen<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
/**
* @func addEventListenerOnce(name, listen[,scope[,id]])
*/
addEventListenerOnce<Scope extends object>(name: string, listen: Listen<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
/**
* @func addEventListener2(name, listen[,scope[,id]])
*/
addEventListener2<Scope extends object>(name: string, listen: Listen2<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
/**
* @func addEventListenerOnce2(name, listen[,scope[,id]])
*/
addEventListenerOnce2<Scope extends object>(name: string, listen: Listen2<E, Scope>, scopeOrId?: Scope | string, id?: string): string;
addEventForward(name: string, noticer: EventNoticer<E>, id?: string): string;
addEventForwardOnce(noticer: EventNoticer<E>, id?: string): string;
/**
* @func trigger 通知事监听器
* @arg name {String} 事件名称
* @arg data {Object} 要发送的消数据
*/
trigger(name: string, data?: any): number;
/**
* @func triggerWithEvent 通知事监听器
* @arg name {String} 事件名称
* @arg event {Event} Event
*/
triggerWithEvent(name: string, event: E): number;
/**
* @func removeEventListener(name,[func[,scope]])
*/
removeEventListener(name: string, listen?: string | Function | object, scope?: object): void;
/**
* @func removeEventListenerWithScope(scope) 卸载notification上所有与scope相关的侦听器
* @arg scope {Object}
*/
removeEventListenerWithScope(scope: object): void;
/**
* @func allNoticers() # Get all event noticer
* @ret {Array}
*/
allNoticers(): EventNoticer<E>[];
/**
* @func triggerListenerChange
*/
triggerListenerChange(name: string, count: number, change: number): void;
}
export declare function event(target: any, name: string): void;
declare const _default: (target: any, name: string) => void;
export default _default;