@visactor/vrender-core
Version:
```typescript import { xxx } from '@visactor/vrender-core'; ```
38 lines (34 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: !0
}), exports.ContributionRegistry = void 0;
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();
}
}
exports.ContributionRegistry = ContributionRegistry;
//# sourceMappingURL=contribution-registry.js.map