@produck/charon-events
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,1 +0,1 @@ | ||
export { SimpleEventEmitter as Simple } from './src/Simple'; | ||
export * as Simple from './src/Simple'; |
@@ -1,1 +0,3 @@ | ||
export { SimpleEventEmitter as Simple } from './src/Simple.js'; | ||
import * as Simple from './src/Simple.js'; | ||
export { Simple }; |
{ | ||
"name": "@produck/charon-events", | ||
"version": "0.1.0", | ||
"description": "event", | ||
"keywords": [ | ||
"EventEmitter" | ||
], | ||
"author": "LiuQ-Q", | ||
"homepage": "https://github.com/produck/charon/tree/main/packages/charon-event#readme", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"src" | ||
], | ||
"types": "index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/produck/charon.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"gitHead": "30076d29929b5b217297a65158207249250cfc98" | ||
"name": "@produck/charon-events", | ||
"version": "0.2.0", | ||
"description": "event", | ||
"keywords": [ | ||
"EventEmitter" | ||
], | ||
"author": "LiuQ-Q", | ||
"homepage": "https://github.com/produck/charon/tree/main/packages/charon-event#readme", | ||
"license": "MIT", | ||
"main": "index.js", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"src" | ||
], | ||
"types": "index.d.ts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/produck/charon.git" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
}, | ||
"gitHead": "68df374f9ff58ba022bc30d0bf7388162dec564c" | ||
} |
@@ -7,3 +7,3 @@ type Listener<C> = (this: C, ...args: any[]) => void; | ||
export class SimpleEventEmitter<C> { | ||
export class SimpleEventEmitter<C = void> { | ||
on(type: string, listener: Listener<C>): void; | ||
@@ -14,2 +14,6 @@ | ||
emit(type: string, ...args: any[]): void; | ||
} | ||
} | ||
export function destroy(emitter: SimpleEventEmitter): void; | ||
export const Emitter: typeof SimpleEventEmitter; |
@@ -5,3 +5,3 @@ const | ||
export class SimpleEventEmitter { | ||
class SimpleEventEmitter { | ||
constructor(context = undefined) { | ||
@@ -22,3 +22,3 @@ /** | ||
this[EVENT_LISTENER_MAP][type].push(listener); | ||
}; | ||
} | ||
@@ -35,3 +35,3 @@ off(type, listener) { | ||
} | ||
}; | ||
} | ||
@@ -44,3 +44,14 @@ emit(type, ...args) { | ||
} | ||
}; | ||
} | ||
} | ||
} | ||
/** | ||
* @param {SimpleEventEmitter} emitter | ||
* @returns | ||
*/ | ||
export const destroy = emitter => { | ||
emitter[EVENT_LISTENER_MAP] = null; | ||
emitter[CONTEXT] = null; | ||
}; | ||
export const Emitter = SimpleEventEmitter; |
3428
53