PathEventEmitter handles wildcards while prefixed
This commit is contained in:
@ -1,11 +1,9 @@
|
||||
<html>
|
||||
<body>
|
||||
<script type="module">
|
||||
import {PathEventEmitter} from './dist/index.mjs';
|
||||
import {PE} from './dist/index.mjs';
|
||||
|
||||
const emitter = new PathEventEmitter('data');
|
||||
emitter.on('*', console.log);
|
||||
emitter.emit('data/asd', {});
|
||||
console.log('data/Ts:n', PE`${'data/Ts'}:n`.methods);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.26.5",
|
||||
"version": "0.26.6",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -325,10 +325,13 @@ export class PathEventEmitter implements IPathEventEmitter{
|
||||
}
|
||||
|
||||
on(event: Event | Event[], listener: PathListener): PathUnsubscribe {
|
||||
makeArray(event).forEach(e => this.listeners.push([
|
||||
e instanceof PathEvent ? e : new PathEvent(`${this.prefix}/${e}`),
|
||||
listener
|
||||
]));
|
||||
makeArray(event).forEach(e => {
|
||||
if(typeof e == 'string' && e[0] == '*' && this.prefix) e = e.slice(1);
|
||||
this.listeners.push([
|
||||
e instanceof PathEvent ? e : new PathEvent(`${this.prefix}/${e}`),
|
||||
listener
|
||||
])
|
||||
});
|
||||
return () => this.off(listener);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user