UNPKG

@selenite/graph-editor

Version:

A graph editor for visual programming, based on rete and svelte.

29 lines (28 loc) 662 B
export class Cache { onDelete; cache = new Map(); constructor(onDelete) { this.onDelete = onDelete; } get(key) { return this.cache.get(key); } add(key, data) { if (this.cache.has(key)) throw new Error('cache already exists'); this.cache.set(key, data); } patch(key, data) { this.cache.set(key, data); } delete(key) { const item = this.cache.get(key); this.cache.delete(key); this.onDelete && this.onDelete(item); } clear() { Array.from(this.cache.keys()).forEach((item) => { this.delete(item); }); } }