UNPKG

rxdeep

Version:
51 lines 1.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Watcher = void 0; var Watcher = /** @class */ (function () { function Watcher(initial, keyFunc) { this.keyFunc = keyFunc; this._keymap = {}; this.changes(initial); } Watcher.prototype.changes = function (list) { var _this = this; if (list === void 0) { list = []; } var changes = { additions: [], deletions: [], moves: [], }; var keymap = list.reduce(function (map, item, index) { var _key = _this.keyFunc(item); map[_key] = { index: index, item: item }; if (!(_key in _this._keymap)) changes.additions.push({ index: index, item: item }); return map; }, {}); Object.entries(this._keymap).forEach(function (_a) { var _key = _a[0], entry = _a[1]; if (!(_key in keymap)) changes.deletions.push(entry); else { var _newEntry = keymap[_key]; if (_newEntry.index !== entry.index) { changes.moves.push({ oldIndex: entry.index, newIndex: _newEntry.index, item: entry.item }); } } }); this._keymap = keymap; return changes; }; Object.defineProperty(Watcher.prototype, "keymap", { get: function () { return this._keymap; }, enumerable: false, configurable: true }); return Watcher; }()); exports.Watcher = Watcher; //# sourceMappingURL=watcher.js.map