update: add event type
This commit is contained in:
parent
39888efa15
commit
9523789394
|
@ -262,7 +262,11 @@ class Engine implements EngineInterface {
|
|||
this.change.range.blur();
|
||||
}
|
||||
|
||||
on(eventType: string, listener: EventListener, rewrite?: boolean) {
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
) {
|
||||
this.event.on(eventType, listener, rewrite);
|
||||
return this;
|
||||
}
|
||||
|
@ -272,7 +276,7 @@ class Engine implements EngineInterface {
|
|||
return this;
|
||||
}
|
||||
|
||||
trigger(eventType: string, ...args: any) {
|
||||
trigger<R = any>(eventType: string, ...args: any): R {
|
||||
return this.event.trigger(eventType, ...args);
|
||||
}
|
||||
|
||||
|
|
|
@ -438,7 +438,10 @@ class NodeEntry implements NodeInterface {
|
|||
* @param {Function} listener 事件函数
|
||||
* @return 返回当前实例
|
||||
*/
|
||||
on(eventType: string, listener: EventListener): NodeInterface {
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
): NodeInterface {
|
||||
this.each((node, i) => {
|
||||
node.addEventListener(eventType, listener, false);
|
||||
if (this.events[i]) this.events[i].on(eventType, listener);
|
||||
|
|
|
@ -12,7 +12,11 @@ class Event implements EventInterface {
|
|||
* @param {Function} listener 事件处理方法
|
||||
* @param {boolean} rewrite 是否重写事件
|
||||
*/
|
||||
on(eventType: string, listener: EventListener, rewrite?: boolean): void {
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
): void {
|
||||
if (!this.listeners[eventType] || rewrite) {
|
||||
this.listeners[eventType] = [];
|
||||
}
|
||||
|
@ -45,18 +49,18 @@ class Event implements EventInterface {
|
|||
* @param eventType 事件类型
|
||||
* @param args 事件参数
|
||||
*/
|
||||
trigger(eventType: string, ...args: any) {
|
||||
trigger<R = any>(eventType: string, ...args: any): R {
|
||||
const listeners = this.listeners[eventType];
|
||||
if (listeners) {
|
||||
let result;
|
||||
let result: R = undefined as any;
|
||||
listeners.every((listener) => {
|
||||
result = listener(...args);
|
||||
return result !== false;
|
||||
result = listener(...args) as R;
|
||||
return typeof result !== 'boolean' || result !== false;
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
return;
|
||||
return undefined as any;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,11 @@ export interface EditorInterface {
|
|||
* @param listener 事件回调
|
||||
* @param rewrite 是否重写
|
||||
*/
|
||||
on(eventType: string, listener: EventListener, rewrite?: boolean): void;
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
): void;
|
||||
/**
|
||||
* 全选ctrl+a键按下,返回false,终止处理其它监听
|
||||
* @param eventType
|
||||
|
@ -597,7 +601,11 @@ export interface EngineInterface extends EditorInterface {
|
|||
* @param listener 事件回调
|
||||
* @param rewrite 是否重写
|
||||
*/
|
||||
on(eventType: string, listener: EventListener, rewrite?: boolean): void;
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
): void;
|
||||
/**
|
||||
* 全选ctrl+a键按下,返回false,终止处理其它监听
|
||||
* @param eventType
|
||||
|
|
|
@ -21,7 +21,11 @@ export interface EventInterface {
|
|||
* @param listener 事件处理方法
|
||||
* @param rewrite 是否重写事件
|
||||
*/
|
||||
on(eventType: string, listener: EventListener, rewrite?: boolean): void;
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
): void;
|
||||
/**
|
||||
* 解除绑定
|
||||
* @param eventType
|
||||
|
@ -33,7 +37,7 @@ export interface EventInterface {
|
|||
* @param eventType 事件类型
|
||||
* @param args 事件参数
|
||||
*/
|
||||
trigger<T = any>(eventType: string, ...args: any): T;
|
||||
trigger<R = any>(eventType: string, ...args: any): R;
|
||||
}
|
||||
export type Selector =
|
||||
| string
|
||||
|
@ -274,7 +278,10 @@ export interface NodeInterface {
|
|||
* @param {Function} listener 事件函数
|
||||
* @return {NodeInterface} 返回当前实例
|
||||
*/
|
||||
on(eventType: string, listener: EventListener): NodeInterface;
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
): NodeInterface;
|
||||
|
||||
/**
|
||||
* 移除当前元素节点事件
|
||||
|
|
|
@ -131,7 +131,11 @@ class View implements ViewInterface {
|
|||
return this.#_scrollNode;
|
||||
}
|
||||
|
||||
on(eventType: string, listener: EventListener, rewrite?: boolean) {
|
||||
on<F extends EventListener = EventListener>(
|
||||
eventType: string,
|
||||
listener: F,
|
||||
rewrite?: boolean,
|
||||
) {
|
||||
this.event.on(eventType, listener, rewrite);
|
||||
return this;
|
||||
}
|
||||
|
@ -141,8 +145,8 @@ class View implements ViewInterface {
|
|||
return this;
|
||||
}
|
||||
|
||||
trigger(eventType: string, ...args: any) {
|
||||
return this.event.trigger(eventType, ...args);
|
||||
trigger<R = any>(eventType: string, ...args: any): R {
|
||||
return this.event.trigger<R>(eventType, ...args);
|
||||
}
|
||||
|
||||
render(content: string, trigger: boolean = true) {
|
||||
|
|
Loading…
Reference in New Issue