UNPKG

@ng-doc/builder

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

45 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObservableSet = void 0; const core_1 = require("@ng-doc/core"); const rxjs_1 = require("rxjs"); const operators_1 = require("rxjs/operators"); class ObservableSet { constructor(values) { this.collection = new Set(); this.changes$ = new rxjs_1.ReplaySubject(); this.collection = new Set(values); } get size() { return this.collection.size; } asArray() { return (0, core_1.asArray)(this.collection); } changes() { return this.changes$.pipe((0, operators_1.map)(() => this.asArray())); } add(...values) { if (values.some((value) => !this.collection.has(value))) { values.forEach((value) => this.collection.add(value)); values && this.changes$.next(); } return () => { values.forEach((v) => this.delete(v)); }; } fill(...values) { this.collection.clear(); this.add(...values); } delete(value) { this.collection.delete(value); this.changes$.next(); } clear() { this.collection.clear(); this.changes$.next(); } } exports.ObservableSet = ObservableSet; //# sourceMappingURL=observable-set.js.map