UPDATE: VERSION-20260327

This commit is contained in:
libertyspy
2026-03-27 10:35:23 +08:00
parent 168ced6b27
commit cb1019b7d7
3 changed files with 68 additions and 25 deletions

View File

@@ -1,7 +1,7 @@
/*
* This file is part of the kernelstudio package.
*
* (c) 2014-2025 zlin <admin@kernelstudio.com>
* (c) 2014-2026 zlin <admin@kernelstudio.com>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
@@ -23,14 +23,14 @@ export class EventError {
export class EventListener {
private readonly _listeners: Record<string, Function[]>;
private _listeners: Record<string, Function[]>;
constructor(listeners: Record<string, Function[]> = {}) {
this._listeners = listeners;
}
all(): Record<string, Function[]> {
return {...this._listeners}; // 返回副本,避免外部直接修改
return { ...this._listeners }; // 返回副本,避免外部直接修改
}
has(name: string): boolean {
@@ -55,16 +55,24 @@ export class EventListener {
[...listeners].forEach(f => f(options));
}
}
clear(){
for (const key in this._listeners) {
if (this._listeners.hasOwnProperty(key)) {
delete this._listeners[key];
}
}
}
}
export const safePreventDefault = (event: any) => {
if (event && typeof event.preventDefault === 'function') {
event.preventDefault();
}
}
};
export const safeStopPropagation = (event: any) => {
if (event && typeof event.stopPropagation === 'function') {
event.stopPropagation();
}
}
};