@webkrafters/react-observable-context 4.0.0 → 4.1.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ export function $clear(state: T, stateKey: K, stats: Stats, changes: (import("../../../types").ClearCommand | import("../../../types").BaseType)[] | (T & { [K_1 in K]: import("../../../types").ClearCommand & {
2
+ [x: string]: any;
3
+ }; })): void;
4
+ export const $delete: TagFunction<T, K, import("../../../types").DeleteCommand<T[K]>>;
5
+ export const $move: TagFunction<T, K, import("../../../types").MoveCommand>;
6
+ export const $push: TagFunction<T, K, import("../../../types").PushCommand>;
7
+ export const $replace: TagFunction<T, K, import("../../../types").ReplaceCommand>;
8
+ export function $set(state: T, stateKey: K, stats: Stats, changes: (import("../../../types").BaseType | import("../../../types").SetCommand<T[K]>)[] | (T & { [K_1 in K]: import("../../../types").SetCommand<T[K]> & {
9
+ [x: string]: any;
10
+ }; })): void;
11
+ export const $splice: TagFunction<T, K, import("../../../types").SpliceCommand>;
12
+ export default tagMap;
13
+ export const isClosedTag: (tag: TagKey | BaseType) => boolean;
14
+ export type TagKey = keyof typeof tagMap;
15
+ export type TagFunction<T extends any[] | import("../../../types").State, K extends keyof T, TAG extends {
16
+ "@@CLEAR"?: any;
17
+ "@@DELETE"?: any;
18
+ "@@MOVE"?: any;
19
+ "@@PUSH"?: any;
20
+ "@@REPLACE"?: any;
21
+ "@@SET"?: any;
22
+ "@@SPLICE"?: any;
23
+ }> = (state: T, stateKey: K, stats: Stats, changes?: (import("../../../types").BaseType | TAG)[] | (T & { [K_1 in K]: TAG & {
24
+ [x: string]: any;
25
+ }; })) => void;
26
+ export type State = import("../../../types").State;
27
+ export type Stats = import("../../../types").UpdateStats;
28
+ export type BaseType = import("../../../types").BaseType;
29
+ declare const tagMap: {
30
+ "@@CLEAR": TagFunction<T, K, import("../../../types").ClearCommand>;
31
+ "@@DELETE": TagFunction<T_1, K_1, import("../../../types").DeleteCommand<T_1[K_1]>>;
32
+ "@@MOVE": TagFunction<T_2, K_2, import("../../../types").MoveCommand>;
33
+ "@@PUSH": TagFunction<T_3, K_3, import("../../../types").PushCommand>;
34
+ "@@REPLACE": TagFunction<T_4, K_4, import("../../../types").ReplaceCommand>;
35
+ "@@SET": TagFunction<T_5, K_5, import("../../../types").SetCommand<T_5[K_5]>>;
36
+ "@@SPLICE": TagFunction<T_6, K_6, import("../../../types").SpliceCommand>;
37
+ };
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isClosedTag = exports["default"] = exports.$splice = exports.$set = exports.$replace = exports.$push = exports.$move = exports.$delete = exports.$clear = void 0;
7
+ var _lodash = _interopRequireDefault(require("lodash.isempty"));
8
+ var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
9
+ var _lodash3 = _interopRequireDefault(require("lodash.isplainobject"));
10
+ var _constants = require("../../../constants");
11
+ var _utils = require("../../../utils");
12
+ var _tagMap;
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
17
+ function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
18
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
19
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
20
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
21
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
22
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
23
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
25
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
26
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
27
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
28
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
29
+ var $clear = function () {
30
+ var defaultPredicate = function defaultPredicate() {
31
+ return true;
32
+ };
33
+ var hasItems = function hasItems(state, stateKey) {
34
+ return state[stateKey].length;
35
+ };
36
+ var setDefault = function setDefault(state, stateKey, stats, changes) {
37
+ var predicate = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : defaultPredicate;
38
+ var value = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
39
+ if (predicate(state, stateKey, stats)) {
40
+ state[stateKey] = value;
41
+ stats.hasChanges = true;
42
+ }
43
+ finishTagRequest(changes, stateKey, _constants.CLEAR_TAG);
44
+ };
45
+ var clear = function clear(state, stateKey, stats, changes) {
46
+ if (!(stateKey in state)) {
47
+ return finishTagRequest(changes, stateKey, _constants.CLEAR_TAG);
48
+ }
49
+ var value = state[stateKey];
50
+ if (typeof value === 'undefined' || value === null) {
51
+ return finishTagRequest(changes, stateKey, _constants.CLEAR_TAG);
52
+ }
53
+ if ((0, _lodash3["default"])(value)) {
54
+ var hasChanges = false;
55
+ for (var k in value) {
56
+ delete state[stateKey][k];
57
+ hasChanges = true;
58
+ }
59
+ stats.hasChanges = stats.hasChanges || hasChanges;
60
+ return finishTagRequest(changes, stateKey, _constants.CLEAR_TAG);
61
+ }
62
+ var type = value.constructor.name;
63
+ if (type === 'String') {
64
+ return setDefault(state, stateKey, stats, changes, hasItems, '');
65
+ }
66
+ if (type === 'Array') {
67
+ return setDefault(state, stateKey, stats, changes, hasItems, []);
68
+ }
69
+ setDefault(state, stateKey, stats, changes);
70
+ };
71
+ return clear;
72
+ }();
73
+ exports.$clear = $clear;
74
+ var $delete = function $delete(state, stateKey, stats, changes) {
75
+ var _state$stateKey;
76
+ var deleteKeys = changes[stateKey][_constants.DELETE_TAG];
77
+ if (!Array.isArray(deleteKeys)) {
78
+ throw new TypeError("Invalid entry found at ".concat(_constants.DELETE_TAG, " change property: requires an array of state keys to delete."));
79
+ }
80
+ var finish = function finish() {
81
+ return finishTagRequest(changes, stateKey, _constants.DELETE_TAG);
82
+ };
83
+ var currValue;
84
+ try {
85
+ if (!deleteKeys.length) {
86
+ throw new Error('Delete called with no identified items to delete.');
87
+ }
88
+ ;
89
+ currValue = state[stateKey];
90
+ if ((0, _lodash["default"])(currValue)) {
91
+ throw new Error('Delete called on empty state.');
92
+ }
93
+ } catch (e) {
94
+ return finish();
95
+ }
96
+ deleteKeys = Array.from(new Set(deleteKeys));
97
+ var hasChanges = false;
98
+ if (!Array.isArray(currValue)) {
99
+ var _iterator = _createForOfIteratorHelper(deleteKeys),
100
+ _step;
101
+ try {
102
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
103
+ var k = _step.value;
104
+ if (!(0, _utils.getProperty)(currValue, k).exists) {
105
+ continue;
106
+ }
107
+ delete state[stateKey][k];
108
+ hasChanges = true;
109
+ }
110
+ } catch (err) {
111
+ _iterator.e(err);
112
+ } finally {
113
+ _iterator.f();
114
+ }
115
+ stats.hasChanges = stats.hasChanges || hasChanges;
116
+ return finish();
117
+ }
118
+ var currLen = currValue.length;
119
+ var deleteMap = {};
120
+ var _iterator2 = _createForOfIteratorHelper(deleteKeys),
121
+ _step2;
122
+ try {
123
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
124
+ var key = _step2.value;
125
+ var index = +key;
126
+ if (index > currLen) {
127
+ continue;
128
+ }
129
+ if (index < 0) {
130
+ index = currLen + index;
131
+ if (index < 0) {
132
+ continue;
133
+ }
134
+ }
135
+ deleteMap[index] = null;
136
+ }
137
+ } catch (err) {
138
+ _iterator2.e(err);
139
+ } finally {
140
+ _iterator2.f();
141
+ }
142
+ var newValue = [];
143
+ var numVisited = 0;
144
+ for (var numDeleted = numVisited, deleteLen = deleteKeys.length; numVisited < currLen; numVisited++) {
145
+ if (!(numVisited in deleteMap)) {
146
+ newValue.push(currValue[numVisited]);
147
+ continue;
148
+ }
149
+ if (++numDeleted === deleteLen) {
150
+ numVisited++;
151
+ break;
152
+ }
153
+ }
154
+ if (numVisited < currLen) {
155
+ newValue.push.apply(newValue, _toConsumableArray(currValue.slice(numVisited)));
156
+ }
157
+ if (currLen === newValue.length) {
158
+ return finish();
159
+ }
160
+ state[stateKey].length = 0;
161
+ (_state$stateKey = state[stateKey]).push.apply(_state$stateKey, newValue);
162
+ stats.hasChanges = true;
163
+ finish();
164
+ };
165
+ exports.$delete = $delete;
166
+ var $move = function $move(state, stateKey, stats, changes) {
167
+ var _state$stateKey2;
168
+ var args = changes[stateKey][_constants.MOVE_TAG];
169
+ if (!Array.isArray(args) || args.length < 2 || !Number.isInteger(args[0]) || !Number.isInteger(args[1])) {
170
+ throw new TypeError("Invalid entry found at ".concat(_constants.MOVE_TAG, " change property: expecting an array of at least 2 integer values [fromIndex, toIndex, numItems]. numItems is optional. Use negative index to count from array end."));
171
+ }
172
+ var finish = function finish() {
173
+ return finishTagRequest(changes, stateKey, _constants.MOVE_TAG);
174
+ };
175
+ var value = state[stateKey];
176
+ if (!Array.isArray(value)) {
177
+ return finish();
178
+ }
179
+ var sLen = value.length;
180
+ if (!sLen) {
181
+ return finish();
182
+ }
183
+ var _args = _slicedToArray(args, 3),
184
+ from = _args[0],
185
+ to = _args[1],
186
+ _args$ = _args[2],
187
+ numItems = _args$ === void 0 ? 1 : _args$;
188
+ if (!Number.isInteger(numItems) || numItems < 1) {
189
+ return finish();
190
+ }
191
+ if (from < 0) {
192
+ from = sLen + from;
193
+ }
194
+ if (from < 0 || from >= sLen) {
195
+ return finish();
196
+ }
197
+ if (to < 0) {
198
+ to = sLen + to;
199
+ }
200
+ if (to < 0 || to >= sLen) {
201
+ return finish();
202
+ }
203
+ if (from === to) {
204
+ return finish();
205
+ }
206
+ var maxTransferLen = sLen - from;
207
+ if (numItems > maxTransferLen) {
208
+ numItems = maxTransferLen;
209
+ }
210
+ (_state$stateKey2 = state[stateKey]).splice.apply(_state$stateKey2, [to, 0].concat(_toConsumableArray(value.splice(from, numItems))));
211
+ stats.hasChanges = true;
212
+ finish();
213
+ };
214
+ exports.$move = $move;
215
+ var $push = function $push(state, stateKey, stats, changes) {
216
+ var _state$stateKey3;
217
+ var args = changes[stateKey][_constants.PUSH_TAG];
218
+ if (!Array.isArray(args)) {
219
+ throw new TypeError("Invalid entry found at ".concat(_constants.PUSH_TAG, " change property: expecting an array of [].pudh(...) compliant argument values."));
220
+ }
221
+ if (!args.length || !Array.isArray(state[stateKey])) {
222
+ return finishTagRequest(changes, stateKey, _constants.PUSH_TAG);
223
+ }
224
+ (_state$stateKey3 = state[stateKey]).push.apply(_state$stateKey3, _toConsumableArray(args));
225
+ stats.hasChanges = true;
226
+ finishTagRequest(changes, stateKey, _constants.PUSH_TAG);
227
+ };
228
+ exports.$push = $push;
229
+ var $replace = function $replace(state, stateKey, stats, changes) {
230
+ applyReplaceCommand(_constants.REPLACE_TAG, state, changes, stateKey, stats);
231
+ };
232
+ exports.$replace = $replace;
233
+ var $set = function () {
234
+ var toString = Object.prototype.toString;
235
+ var set = function set(state, stateKey, stats, changes) {
236
+ if (toString.call(changes[stateKey][_constants.SET_TAG]) === '[object Function]') {
237
+ changes[stateKey][_constants.SET_TAG] = changes[stateKey][_constants.SET_TAG]((0, _utils.clonedeep)(state[stateKey]));
238
+ }
239
+ applyReplaceCommand(_constants.SET_TAG, state, changes, stateKey, stats);
240
+ };
241
+ return set;
242
+ }();
243
+ exports.$set = $set;
244
+ var $splice = function $splice(state, stateKey, stats, changes) {
245
+ var args = changes[stateKey][_constants.SPLICE_TAG];
246
+ if (!Array.isArray(args) || args.length < 2 || !Number.isInteger(args[0]) || !Number.isInteger(args[1])) {
247
+ throw new TypeError("Invalid entry found at ".concat(_constants.SPLICE_TAG, " change property: expecting an array of [].splice(...) compliant argument values."));
248
+ }
249
+ var _args2 = _toArray(args),
250
+ start = _args2[0],
251
+ deleteCount = _args2[1],
252
+ items = _args2.slice(2);
253
+ var iLen = items.length;
254
+ var value = state[stateKey];
255
+ if (!Array.isArray(value) || deleteCount < 1 && !iLen) {
256
+ return finishTagRequest(changes, stateKey, _constants.SPLICE_TAG);
257
+ }
258
+ if (deleteCount > 0) {
259
+ var sLen = value.length;
260
+ start = start < 0 ? Math.abs(start) > sLen ? 0 : sLen + start : start > sLen ? sLen : start;
261
+ var maxCount = sLen - start;
262
+ if (maxCount > iLen) {
263
+ maxCount = iLen;
264
+ }
265
+ if (maxCount > deleteCount) {
266
+ maxCount = deleteCount;
267
+ }
268
+ var numLeftTrimmed = 0;
269
+ for (; numLeftTrimmed < maxCount; numLeftTrimmed++) {
270
+ if (!(0, _lodash2["default"])(value[start + numLeftTrimmed], items[numLeftTrimmed])) {
271
+ break;
272
+ }
273
+ }
274
+ start += numLeftTrimmed;
275
+ items.splice(0, numLeftTrimmed);
276
+ iLen = items.length;
277
+ deleteCount -= numLeftTrimmed;
278
+ }
279
+ if (deleteCount > 0 || iLen) {
280
+ var _state$stateKey4;
281
+ (_state$stateKey4 = state[stateKey]).splice.apply(_state$stateKey4, [start, deleteCount].concat(_toConsumableArray(items)));
282
+ stats.hasChanges = true;
283
+ }
284
+ finishTagRequest(changes, stateKey, _constants.SPLICE_TAG);
285
+ };
286
+ exports.$splice = $splice;
287
+ var tagMap = (_tagMap = {}, _defineProperty(_tagMap, _constants.CLEAR_TAG, $clear), _defineProperty(_tagMap, _constants.DELETE_TAG, $delete), _defineProperty(_tagMap, _constants.MOVE_TAG, $move), _defineProperty(_tagMap, _constants.PUSH_TAG, $push), _defineProperty(_tagMap, _constants.REPLACE_TAG, $replace), _defineProperty(_tagMap, _constants.SET_TAG, $set), _defineProperty(_tagMap, _constants.SPLICE_TAG, $splice), _tagMap);
288
+ var _default = tagMap;
289
+ exports["default"] = _default;
290
+ var isClosedTag = function () {
291
+ var NO_PARAM_TAGS = _defineProperty({}, _constants.CLEAR_TAG, null);
292
+ return function (tag) {
293
+ return tag in NO_PARAM_TAGS;
294
+ };
295
+ }();
296
+ exports.isClosedTag = isClosedTag;
297
+ function applyReplaceCommand(tag, state, changes, stateKey, stats) {
298
+ var replacement = changes[stateKey][tag];
299
+ if (!((0, _utils.isDataContainer)(state[stateKey]) && (0, _utils.isDataContainer)(replacement))) {
300
+ if (state[stateKey] !== replacement) {
301
+ state[stateKey] = replacement;
302
+ stats.hasChanges = true;
303
+ }
304
+ return finishTagRequest(changes, stateKey, tag);
305
+ }
306
+ if ((0, _lodash2["default"])(state[stateKey], replacement)) {
307
+ return finishTagRequest(changes, stateKey, tag);
308
+ }
309
+ if (Array.isArray(replacement) && Array.isArray(state[stateKey])) {
310
+ state[stateKey].length = replacement.length;
311
+ }
312
+ for (var k in state[stateKey]) {
313
+ if (k in replacement) {
314
+ state[stateKey][k] = replacement[k];
315
+ } else {
316
+ delete state[stateKey][k];
317
+ }
318
+ }
319
+ for (var _k in replacement) {
320
+ state[stateKey][_k] = replacement[_k];
321
+ }
322
+ stats.hasChanges = true;
323
+ finishTagRequest(changes, stateKey, tag);
324
+ }
325
+ var finishTagRequest = function () {
326
+ var end = function end(changes, key) {
327
+ delete changes[key];
328
+ };
329
+ var runCloser = function runCloser(changes, key, tag) {
330
+ if (isClosedTag(tag)) {
331
+ return end(changes, key);
332
+ }
333
+ var keyCount = 0;
334
+ for (var k in changes[key]) {
335
+ if (++keyCount === 2) {
336
+ return end(changes[key], tag);
337
+ }
338
+ }
339
+ keyCount = 0;
340
+ for (var _k2 in changes) {
341
+ if (++keyCount === 2) {
342
+ return end(changes[key], tag);
343
+ }
344
+ }
345
+ end(changes, key);
346
+ };
347
+ return runCloser;
348
+ }();
@@ -7,6 +7,6 @@ declare class AccessorCache<T extends import("../../types").State> {
7
7
  [propertyPaths: string]: Readonly<any>;
8
8
  };
9
9
  unlinkClient(clientId: string): void;
10
- watchSource(changes: import("../../types").PartialState<T>): void;
10
+ watchSource(changes: import("../../types").UpdatePayload<import("../../types").PartialState<T>>): void;
11
11
  #private;
12
12
  }
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash.get"));
8
- var _lodash2 = _interopRequireDefault(require("lodash.has"));
9
- var _lodash3 = _interopRequireDefault(require("lodash.isempty"));
10
- var _lodash4 = _interopRequireDefault(require("lodash.isequal"));
7
+ var _lodash = _interopRequireDefault(require("lodash.isempty"));
8
+ var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
11
9
  var _constants = require("../../constants");
10
+ var _utils = require("../../utils");
12
11
  var _atom = _interopRequireDefault(require("../atom"));
13
12
  var _accessor = _interopRequireDefault(require("../accessor"));
14
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -62,7 +61,7 @@ var AccessorCache = function () {
62
61
  for (var _len = arguments.length, propertyPaths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
63
62
  propertyPaths[_key - 1] = arguments[_key];
64
63
  }
65
- if ((0, _lodash3["default"])(propertyPaths)) {
64
+ if ((0, _lodash["default"])(propertyPaths)) {
66
65
  propertyPaths = [_constants.FULL_STATE_SELECTOR];
67
66
  }
68
67
  var cacheKey = JSON.stringify(propertyPaths);
@@ -104,11 +103,11 @@ var AccessorCache = function () {
104
103
  var atoms = _classPrivateFieldGet(this, _atoms);
105
104
  var updatedPaths = [];
106
105
  for (var path in atoms) {
107
- if (path !== _constants.FULL_STATE_SELECTOR && !(0, _lodash2["default"])(originChanges, path)) {
106
+ if (path !== _constants.FULL_STATE_SELECTOR && !(0, _utils.getProperty)(originChanges, path).exists) {
108
107
  continue;
109
108
  }
110
109
  var newAtomVal = _classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path);
111
- if ((0, _lodash4["default"])(newAtomVal, atoms[path].value)) {
110
+ if ((0, _lodash2["default"])(newAtomVal, atoms[path].value)) {
112
111
  continue;
113
112
  }
114
113
  atoms[path].setValue(newAtomVal);
@@ -146,7 +145,7 @@ function _createAccessor2(cacheKey, propertyPaths) {
146
145
  return _classPrivateFieldGet(this, _accessors)[cacheKey];
147
146
  }
148
147
  function _getOriginAt2(propertyPath) {
149
- return propertyPath !== _constants.FULL_STATE_SELECTOR ? (0, _lodash["default"])(_classPrivateFieldGet(this, _origin), propertyPath) : _classPrivateFieldGet(this, _origin);
148
+ return propertyPath !== _constants.FULL_STATE_SELECTOR ? (0, _utils.getProperty)(_classPrivateFieldGet(this, _origin), propertyPath).value : _classPrivateFieldGet(this, _origin);
150
149
  }
151
150
  var _default = AccessorCache;
152
151
  exports["default"] = _default;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
8
7
  var _utils = require("../../utils");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
9
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
12
10
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -61,7 +59,7 @@ var Atom = function () {
61
59
  }, {
62
60
  key: "setValue",
63
61
  value: function setValue(newValue) {
64
- _classPrivateFieldSet(this, _value, (0, _utils.makeReadonly)((0, _lodash["default"])(newValue)));
62
+ _classPrivateFieldSet(this, _value, (0, _utils.makeReadonly)((0, _utils.clonedeep)(newValue)));
65
63
  }
66
64
  }]);
67
65
  return Atom;
@@ -4,9 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
7
+ var _utils = require("../../utils");
8
8
  var _globalThis$sessionSt;
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
9
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
@@ -33,7 +32,7 @@ var MemoryStorage = function () {
33
32
  _createClass(MemoryStorage, [{
34
33
  key: "clone",
35
34
  value: function clone(data) {
36
- return (0, _lodash["default"])(data);
35
+ return (0, _utils.clonedeep)(data);
37
36
  }
38
37
  }, {
39
38
  key: "getItem",
package/dist/types.d.ts CHANGED
@@ -15,7 +15,7 @@ export type IStore = {
15
15
  setState: NonReactUsageReport;
16
16
  subscribe: NonReactUsageReport;
17
17
  };
18
- export type Listener<T extends State> = (changes: PartialState<T>) => void;
18
+ export type Listener<T extends State> = (changes: UpdatePayload<PartialState<T>>) => void;
19
19
  export type NonReactUsageReport = () => never;
20
20
  export type PartialState<T extends State> = { [K in keyof T]?: T[K]; };
21
21
  export type Prehooks<T extends State> = {
@@ -25,12 +25,20 @@ export type Prehooks<T extends State> = {
25
25
  }) => boolean;
26
26
  setState?: (newChanges: PartialState<T>) => boolean;
27
27
  };
28
+ export type PropertyInfo<T extends any[] | State> = {
29
+ _value: any;
30
+ exists: boolean;
31
+ index: number;
32
+ key: string | symbol | number;
33
+ source: T;
34
+ value: any;
35
+ };
28
36
  export type State = {
29
37
  [x: string]: any;
30
38
  };
31
39
  export type StoreInternal<T extends State> = {
32
40
  resetState: (propertyPaths?: string[]) => void;
33
- setState: (changes: PartialState<T>) => void;
41
+ setState: (changes: UpdatePayload<PartialState<T>>) => void;
34
42
  } & {
35
43
  getState: (clientId: string, ...propertyPaths?: string[]) => {
36
44
  [propertyPaths: string]: Readonly<any>;
@@ -41,6 +49,42 @@ export type StoreInternal<T extends State> = {
41
49
  export type Store<T extends State> = {
42
50
  data: Data;
43
51
  resetState: (propertyPaths?: string[]) => void;
44
- setState: (changes: PartialState<T>) => void;
52
+ setState: (changes: UpdatePayload<PartialState<T>>) => void;
53
+ };
54
+ export type UpdateStats = {
55
+ hasChanges: boolean;
56
+ };
57
+ export type UpdatePayload<T> = "@@CLEAR" | T | ClearCommand | DeleteCommand<T> | MoveCommand | PushCommand | ReplaceCommand | SetCommand<T> | SpliceCommand | { [K in keyof T]?: UpdatePayload<T[K]>; };
58
+ export type ClearCommand = {
59
+ "@@CLEAR": any;
60
+ };
61
+ export type DeleteCommand<T extends any[] | State> = {
62
+ "@@DELETE": (keyof T)[];
63
+ };
64
+ export type MoveCommand = {
65
+ "@@MOVE": [number, number, number?];
45
66
  };
46
- export type Unsubscribe = VoidFunction;
67
+ export type PushCommand = {
68
+ "@@PUSH": any[];
69
+ };
70
+ export type ReplaceCommand = {
71
+ "@@REPLACE": BaseType;
72
+ };
73
+ export type SetCommand<V> = {
74
+ "@@SET": BaseType | ((currentValue: V) => any);
75
+ };
76
+ export type SpliceCommand = {
77
+ "@@SPLICE": [number, number, ...any[]];
78
+ };
79
+ export type CLEAR_TAG = typeof import("./constants").CLEAR_TAG;
80
+ export type DELETE_TAG = typeof import("./constants").DELETE_TAG;
81
+ export type FULL_STATE_SELECTOR = typeof import("./constants").FULL_STATE_SELECTOR;
82
+ export type MOVE_TAG = typeof import("./constants").MOVE_TAG;
83
+ export type PUSH_TAG = typeof import("./constants").PUSH_TAG;
84
+ export type REPLACE_TAG = typeof import("./constants").REPLACE_TAG;
85
+ export type SET_TAG = typeof import("./constants").SET_TAG;
86
+ export type SPLICE_TAG = typeof import("./constants").SPLICE_TAG;
87
+ export type Unsubscribe = VoidFunction;
88
+ export type BaseType = string | number | boolean | symbol | any[] | {
89
+ [x: string]: any;
90
+ };
@@ -0,0 +1,7 @@
1
+ export default verify;
2
+ export const CLONEABLE_TAGS: any;
3
+ declare function verify<T>(value: T): {
4
+ isEligible: boolean;
5
+ typeName: string;
6
+ value: T;
7
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports["default"] = exports.CLONEABLE_TAGS = void 0;
6
+ var _default = verify;
7
+ exports["default"] = _default;
8
+ var CLONEABLE_TAGS = Object({
9
+ Arguments: null,
10
+ Array: null,
11
+ ArrayBuffer: null,
12
+ Boolean: null,
13
+ DataView: null,
14
+ Date: null,
15
+ Error: null,
16
+ Function: null,
17
+ Float32Array: null,
18
+ Float64Array: null,
19
+ GeneratorFunction: null,
20
+ Int8Array: null,
21
+ Int16Array: null,
22
+ Int32Array: null,
23
+ Map: null,
24
+ Number: null,
25
+ Object: null,
26
+ Promise: null,
27
+ RegExp: null,
28
+ Set: null,
29
+ String: null,
30
+ Symbol: null,
31
+ Uint8Array: null,
32
+ Uint8ClampedArray: null,
33
+ Uint16Array: null,
34
+ Uint32Array: null,
35
+ WeakMap: null
36
+ });
37
+ exports.CLONEABLE_TAGS = CLONEABLE_TAGS;
38
+ function verify(value) {
39
+ var typeName = value === null || value === void 0 ? void 0 : value.constructor.name;
40
+ var isEligible;
41
+ if (typeName !== undefined) {
42
+ isEligible = typeName in CLONEABLE_TAGS;
43
+ } else {
44
+ typeName = "".concat(value);
45
+ isEligible = true;
46
+ }
47
+ return {
48
+ isEligible: isEligible,
49
+ typeName: typeName,
50
+ value: value
51
+ };
52
+ }
@@ -1,5 +1,11 @@
1
1
  export function arrangePropertyPaths(propertyPaths: Array<string>): Array<string>;
2
+ export function isDataContainer(v: any): boolean;
2
3
  export function makeReadonly<T>(v: T): Readonly<T>;
3
4
  export function mapPathsToObject<T extends {
4
5
  [x: string]: any;
5
- }>(source: T, propertyPaths: Array<string>): { [K in keyof T]?: any; };
6
+ }>(source: T, propertyPaths: Array<string>): { [K in keyof T]?: any; };
7
+ export function clonedeep<T, R>(value: T): R;
8
+ export function getProperty(source: T, path: string | symbol | number | Array<string | symbol | number>, defaultValue: any): PropertyInfo<T>;
9
+ export type GetProperty<T extends any[] | import("../types").State = any[] | import("../types").State, R = any> = (source: T, path: string | symbol | number | Array<string | symbol | number>, defaultValue?: any) => R;
10
+ export type PropertyInfo<T extends any[] | import("../types").State> = import("../types").PropertyInfo<T>;
11
+ export type State = import("../types").State;