UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

30 lines (29 loc) 1.06 kB
export class ContributionRegistry { constructor() { this.entries = new Map; } register(key, contribution) { var _a; const current = null !== (_a = this.entries.get(key)) && void 0 !== _a ? _a : []; current.push(contribution), this.entries.set(key, current); } unregister(key, contribution) { if (void 0 === contribution) return void this.entries.delete(key); const current = this.entries.get(key); if (!current) return; const next = current.filter((entry => entry !== contribution)); next.length ? this.entries.set(key, next) : this.entries.delete(key); } get(key) { var _a; return [ ...null !== (_a = this.entries.get(key)) && void 0 !== _a ? _a : [] ]; } getAll() { return Array.from(this.entries.values()).reduce(((all, current) => (all.push(...current), all)), []); } clear(key) { null != key ? this.entries.delete(key) : this.entries.clear(); } } //# sourceMappingURL=contribution-registry.js.map