Compare commits

...

2 Commits

Author SHA1 Message Date
1ab8e6424b handle cache cleanup in db
Some checks failed
Build / Build NPM Project (push) Successful in 40s
Build / Publish Documentation (push) Failing after 5s
Build / Tag Version (push) Successful in 8s
2025-07-14 01:00:34 -04:00
035a1d35cb 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
2025-07-14 00:31:11 -04:00
4 changed files with 13 additions and 10 deletions

View File

@ -1,11 +1,9 @@
<html> <html>
<body> <body>
<script type="module"> <script type="module">
import {PathEventEmitter} from './dist/index.mjs'; import {PE} from './dist/index.mjs';
const emitter = new PathEventEmitter('data'); console.log('data/Ts:n', PE`${'data/Ts'}:n`.methods);
emitter.on('*', console.log);
emitter.emit('data/asd', {});
</script> </script>
</body> </body>
</html> </html>

View File

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

View File

@ -80,7 +80,9 @@ export class Cache<K extends string | number | symbol, T> {
if(persists.storage?.database != undefined) { if(persists.storage?.database != undefined) {
(<Database>persists.storage).createTable({name: persists.key, key: <string>this.key}).then(table => { (<Database>persists.storage).createTable({name: persists.key, key: <string>this.key}).then(table => {
if(key) { if(key) {
table.set(this.get(key), key); const value = this.get(key);
if(value != null) table.set(value, key);
else table.delete(key);
} else { } else {
table.clear(); table.clear();
this.all().forEach(row => table.add(row)); this.all().forEach(row => table.add(row));

View File

@ -325,10 +325,13 @@ export class PathEventEmitter implements IPathEventEmitter{
} }
on(event: Event | Event[], listener: PathListener): PathUnsubscribe { on(event: Event | Event[], listener: PathListener): PathUnsubscribe {
makeArray(event).forEach(e => this.listeners.push([ makeArray(event).forEach(e => {
e instanceof PathEvent ? e : new PathEvent(`${this.prefix}/${e}`), if(typeof e == 'string' && e[0] == '*' && this.prefix) e = e.slice(1);
listener this.listeners.push([
])); e instanceof PathEvent ? e : new PathEvent(`${this.prefix}/${e}`),
listener
])
});
return () => this.off(listener); return () => this.off(listener);
} }