PathEventEmitter handles wildcards while prefixed
Some checks failed
Build / Build NPM Project (push) Successful in 52s
Build / Publish Documentation (push) Failing after 5s
Build / Tag Version (push) Successful in 8s

This commit is contained in:
2025-07-14 00:31:11 -04:00
parent e78120b067
commit 035a1d35cb
3 changed files with 10 additions and 9 deletions

View File

@ -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>

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.26.5",
"version": "0.26.6",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -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);
}