UNPKG

@ui-schema/react

Version:

Schema-driven UI generator for React using JSON Schema. Build powerful form and interface generators with headless components and hooks.

33 lines (32 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scopeUpdaterValues = void 0; var _UIStore = require("@ui-schema/react/UIStore"); var _immutable = require("immutable"); var _storeScopeUpdater = require("@ui-schema/react/storeScopeUpdater"); var _storeBuildScopeTree = require("@ui-schema/react/storeBuildScopeTree"); var scopeUpdaterValues = exports.scopeUpdaterValues = function scopeUpdaterValues(store, storeKeys, newValue, op) { var storeBuild = (0, _storeBuildScopeTree.storeBuildScopeTree)(storeKeys, 'values', store, op === 'set' ? function (key) { return typeof key === 'number' ? (0, _immutable.List)() : (0, _immutable.OrderedMap)(); } : undefined); if (op === 'delete') { if (storeBuild.incomplete) { return store; } store = storeBuild.store; if (storeKeys.size) { var parentStore = store.getIn((0, _UIStore.prependKey)(storeKeys.slice(0, -1), 'values')); if (_immutable.List.isList(parentStore)) { store = store.setIn((0, _UIStore.prependKey)(storeKeys, 'values'), null); } else if (_immutable.Map.isMap(parentStore) || _immutable.Record.isRecord(parentStore)) { store = store.deleteIn((0, _UIStore.prependKey)(storeKeys, 'values')); } } else { store = store.deleteIn(['values']); } return store; } return (0, _storeScopeUpdater.updateStoreScope)(storeBuild.store, 'values', storeKeys, newValue); };