UNPKG

fluidstate

Version:

Library for fine-grained reactivity state management

77 lines (74 loc) 2.35 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMapSetChanges = exports.getMapDeleteChanges = exports.getMapClearChanges = void 0; var _reactivePlugin = require("./reactive-plugin"); /** * Generates a list of change descriptions for a map set operation. * * @param map The reactive map proxy. * @param key The key being set. * @param previousValue The previous value associated with the key. * @param nextValue The new value being set for the key. * @returns An array of ReactiveChange objects, or null if no reportable changes occurred (though for set, it always reports if called). */ const getMapSetChanges = (map, key, previousValue, nextValue) => { const mapChange = { type: _reactivePlugin.MapChangeType.SetValue, key, previousValue, nextValue }; return [{ type: _reactivePlugin.ReactiveChangeType.Map, map, mapChange }]; }; /** * Generates a list of change descriptions for a map delete operation. * * @param map The reactive map proxy. * @param key The key being deleted. * @param previousValue The value associated with the key before deletion. * @returns An array of ReactiveChange objects, or null if no reportable changes occurred. */ exports.getMapSetChanges = getMapSetChanges; const getMapDeleteChanges = (map, key, previousValue) => { const mapChange = { type: _reactivePlugin.MapChangeType.DeleteValue, key, previousValue }; return [{ type: _reactivePlugin.ReactiveChangeType.Map, map, mapChange }]; }; /** * Generates a list of change descriptions for a map clear operation. * * @param map The reactive map proxy. * @param entries The array of [key, value] pairs representing the map's content before clearing. * @returns An array of ReactiveChange objects, or null if the map was already empty. */ exports.getMapDeleteChanges = getMapDeleteChanges; const getMapClearChanges = (map, entries) => { const changes = entries.map(([key, previousValue]) => { const mapChange = { type: _reactivePlugin.MapChangeType.DeleteValue, key, previousValue }; return { type: _reactivePlugin.ReactiveChangeType.Map, map, mapChange }; }); return changes; }; exports.getMapClearChanges = getMapClearChanges; //# sourceMappingURL=reactive-plugin-map.js.map