UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

64 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeltaSet = void 0; const delta_map_observable_1 = require("./delta-map.observable"); class DeltaSet extends delta_map_observable_1.DeltaMap { constructor(itemsOrSettings, settings) { super(itemsOrSettings, settings); } /** * Process constructor content, can be overriden and extended in subclasses */ initializeContent(entries) { Array.from(entries).forEach((entry) => this.doSet(entry.id, entry)); } /** * Adds or modifies an entry and notifies changes through _delta$_. * * If an existing entry is the same according to the _isEqual_ function, nothing is changed. */ add(entry) { super.set(entry.id, entry); return this; } /** * Adds or modifies multiple entries at once and notifies changes through _delta$_. * * If an existing entry is the same according to the _isEqual_ function, nothing is changed. */ addMultiple(entries) { Array.from(entries).forEach((newEntry) => this.doSet(newEntry.id, newEntry)); this.publishDelta(); } /** * Redirect to _entry.add_ to guarantee integrity of the IdObject Map. * @override * @deprecated use _add(entry)_ instead */ set(_id, entry) { return this.add(entry); } /** * Replaces all existing entries with new entries. * - Adds _newEntries_ not existing in the current entries. * - Updates existing entries where _newEntries_ have changed (_isEqual_ function). * - Deletes entries not existing in _newEntries_. */ replace(entries) { const newEntriesSet = new Set(); // update additions and modifications Array.from(entries).forEach((newEntry) => { newEntriesSet.add(newEntry.id); this.doSet(newEntry.id, newEntry); }); // update deletions Array.from(this.values()).forEach((oldEntry) => { if (!newEntriesSet.has(oldEntry.id)) { this.doDelete(oldEntry.id); } }); this.publishDelta(); } } exports.DeltaSet = DeltaSet; //# sourceMappingURL=delta-set.observable.js.map