@webkrafters/react-observable-context 4.7.7 → 5.0.0-rc.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.
Files changed (54) hide show
  1. package/dist/constants.d.ts +2 -9
  2. package/dist/constants.js +64 -19
  3. package/dist/index.d.ts +90 -0
  4. package/dist/index.js +98 -0
  5. package/dist/main/hooks/use-prehooks-ref/index.d.ts +3 -3
  6. package/dist/main/hooks/use-prehooks-ref/index.js +8 -8
  7. package/dist/main/hooks/use-prehooks-ref/index.test.d.ts +1 -0
  8. package/dist/main/hooks/use-prehooks-ref/index.test.js +21 -0
  9. package/dist/main/hooks/use-render-key-provider/index.d.ts +4 -5
  10. package/dist/main/hooks/use-render-key-provider/index.js +23 -11
  11. package/dist/main/hooks/use-render-key-provider/index.test.d.ts +1 -0
  12. package/dist/main/hooks/use-render-key-provider/index.test.js +72 -0
  13. package/dist/main/hooks/use-store/index.d.ts +8 -21
  14. package/dist/main/hooks/use-store/index.js +113 -93
  15. package/dist/main/hooks/use-store/index.test.d.ts +1 -0
  16. package/dist/main/hooks/use-store/index.test.js +456 -0
  17. package/dist/main/index.d.ts +11 -140
  18. package/dist/main/index.js +301 -159
  19. package/dist/main/index.test.d.ts +11 -0
  20. package/dist/main/index.test.js +1298 -0
  21. package/dist/main/test-apps/normal.d.ts +36 -0
  22. package/dist/main/test-apps/normal.js +243 -0
  23. package/dist/main/test-apps/with-connected-children.d.ts +25 -0
  24. package/dist/main/test-apps/with-connected-children.js +229 -0
  25. package/dist/main/test-apps/with-pure-children.d.ts +15 -0
  26. package/dist/main/test-apps/with-pure-children.js +127 -0
  27. package/dist/model/storage/index.d.ts +7 -7
  28. package/dist/model/storage/index.js +55 -59
  29. package/dist/model/storage/index.test.d.ts +1 -0
  30. package/dist/model/storage/index.test.js +139 -0
  31. package/dist/test-artifacts/data/create-state-obj.d.ts +58 -0
  32. package/dist/test-artifacts/data/create-state-obj.js +95 -0
  33. package/dist/test-artifacts/suppress-render-compat.d.ts +1 -0
  34. package/dist/test-artifacts/suppress-render-compat.js +7 -0
  35. package/logo.png +0 -0
  36. package/package.json +31 -67
  37. package/dist/main/hooks/use-state-manager/index.d.ts +0 -12
  38. package/dist/main/hooks/use-state-manager/index.js +0 -42
  39. package/dist/main/set-state/index.d.ts +0 -31
  40. package/dist/main/set-state/index.js +0 -211
  41. package/dist/main/set-state/tag-functions/index.d.ts +0 -38
  42. package/dist/main/set-state/tag-functions/index.js +0 -360
  43. package/dist/model/accessor/index.d.ts +0 -23
  44. package/dist/model/accessor/index.js +0 -180
  45. package/dist/model/accessor-cache/index.d.ts +0 -12
  46. package/dist/model/accessor-cache/index.js +0 -170
  47. package/dist/model/atom/index.d.ts +0 -10
  48. package/dist/model/atom/index.js +0 -79
  49. package/dist/types.d.ts +0 -91
  50. package/dist/utils/clonedeep-eligibility-check.d.ts +0 -7
  51. package/dist/utils/clonedeep-eligibility-check.js +0 -52
  52. package/dist/utils/index.d.ts +0 -12
  53. package/dist/utils/index.js +0 -173
  54. package/index.js +0 -1
@@ -1,170 +0,0 @@
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["default"] = void 0;
7
- var _lodash = _interopRequireDefault(require("lodash.isempty"));
8
- var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
9
- var _constants = require("../../constants");
10
- var _utils = require("../../utils");
11
- var _atom = _interopRequireDefault(require("../atom"));
12
- var _accessor = _interopRequireDefault(require("../accessor"));
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
- 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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
15
- 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); }
16
- 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; }
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
- 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); } }
19
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
21
- 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); }
22
- function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
23
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
24
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
25
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
26
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
27
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
28
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
29
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
30
- function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
31
- var _accessors = new WeakMap();
32
- var _atoms = new WeakMap();
33
- var _origin = new WeakMap();
34
- var _createAccessor = new WeakSet();
35
- var _getOriginAt = new WeakSet();
36
- var AccessorCache = function () {
37
- function AccessorCache(origin) {
38
- _classCallCheck(this, AccessorCache);
39
- _classPrivateMethodInitSpec(this, _getOriginAt);
40
- _classPrivateMethodInitSpec(this, _createAccessor);
41
- _classPrivateFieldInitSpec(this, _accessors, {
42
- writable: true,
43
- value: void 0
44
- });
45
- _classPrivateFieldInitSpec(this, _atoms, {
46
- writable: true,
47
- value: void 0
48
- });
49
- _classPrivateFieldInitSpec(this, _origin, {
50
- writable: true,
51
- value: void 0
52
- });
53
- _classPrivateFieldSet(this, _accessors, {});
54
- _classPrivateFieldSet(this, _atoms, {});
55
- _classPrivateFieldSet(this, _origin, origin);
56
- }
57
- _createClass(AccessorCache, [{
58
- key: "atomize",
59
- value: function atomize(originChanges) {
60
- var accessors = _classPrivateFieldGet(this, _accessors);
61
- var atoms = _classPrivateFieldGet(this, _atoms);
62
- var updatedPaths = [];
63
- for (var path in atoms) {
64
- var _classPrivateMethodGe = _classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path),
65
- exists = _classPrivateMethodGe.exists,
66
- newAtomVal = _classPrivateMethodGe.value;
67
- if (path !== _constants.FULL_STATE_SELECTOR && exists && (newAtomVal === null || newAtomVal === undefined)) {
68
- if (!Array.isArray(originChanges)) {
69
- if (!(0, _utils.getProperty)(originChanges, path).trail.length) {
70
- continue;
71
- }
72
- } else {
73
- var found = false;
74
- for (var i = originChanges.length; i--;) {
75
- if ((0, _utils.getProperty)(originChanges, "".concat(i, ".").concat(path)).trail.length) {
76
- found = true;
77
- break;
78
- }
79
- }
80
- if (!found) {
81
- continue;
82
- }
83
- }
84
- }
85
- if ((0, _lodash2["default"])(newAtomVal, atoms[path].value)) {
86
- continue;
87
- }
88
- atoms[path].setValue(newAtomVal);
89
- updatedPaths.push(path);
90
- }
91
- if (!updatedPaths.length) {
92
- return;
93
- }
94
- for (var k in accessors) {
95
- var _accessors$k$outdated;
96
- (_accessors$k$outdated = accessors[k].outdatedPaths).push.apply(_accessors$k$outdated, updatedPaths);
97
- }
98
- }
99
- }, {
100
- key: "get",
101
- value: function get(clientId) {
102
- for (var _len = arguments.length, propertyPaths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
103
- propertyPaths[_key - 1] = arguments[_key];
104
- }
105
- if ((0, _lodash["default"])(propertyPaths)) {
106
- propertyPaths = [_constants.FULL_STATE_SELECTOR];
107
- }
108
- var cacheKey = JSON.stringify(propertyPaths);
109
- var accessor = cacheKey in _classPrivateFieldGet(this, _accessors) ? _classPrivateFieldGet(this, _accessors)[cacheKey] : _classPrivateMethodGet(this, _createAccessor, _createAccessor2).call(this, cacheKey, propertyPaths);
110
- !accessor.hasClient(clientId) && accessor.addClient(clientId);
111
- return accessor.refreshValue(_classPrivateFieldGet(this, _atoms));
112
- }
113
- }, {
114
- key: "unlinkClient",
115
- value: function unlinkClient(clientId) {
116
- var accessors = _classPrivateFieldGet(this, _accessors);
117
- var atoms = _classPrivateFieldGet(this, _atoms);
118
- for (var k in accessors) {
119
- var accessor = accessors[k];
120
- if (!accessor.removeClient(clientId) || accessor.numClients) {
121
- continue;
122
- }
123
- var _iterator = _createForOfIteratorHelper(accessor.paths),
124
- _step;
125
- try {
126
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
127
- var p = _step.value;
128
- if (p in atoms && atoms[p].disconnect(accessor.id) < 1) {
129
- delete atoms[p];
130
- }
131
- }
132
- } catch (err) {
133
- _iterator.e(err);
134
- } finally {
135
- _iterator.f();
136
- }
137
- delete accessors[k];
138
- }
139
- }
140
- }]);
141
- return AccessorCache;
142
- }();
143
- function _createAccessor2(cacheKey, propertyPaths) {
144
- var atoms = _classPrivateFieldGet(this, _atoms);
145
- var accessor = new _accessor["default"](_classPrivateFieldGet(this, _origin), propertyPaths);
146
- _classPrivateFieldGet(this, _accessors)[cacheKey] = accessor;
147
- var _iterator2 = _createForOfIteratorHelper(accessor.paths),
148
- _step2;
149
- try {
150
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
151
- var path = _step2.value;
152
- if (!(path in atoms)) {
153
- atoms[path] = new _atom["default"](_classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path).value);
154
- }
155
- }
156
- } catch (err) {
157
- _iterator2.e(err);
158
- } finally {
159
- _iterator2.f();
160
- }
161
- return _classPrivateFieldGet(this, _accessors)[cacheKey];
162
- }
163
- function _getOriginAt2(propertyPath) {
164
- return propertyPath === _constants.FULL_STATE_SELECTOR ? {
165
- exists: true,
166
- value: _classPrivateFieldGet(this, _origin)
167
- } : (0, _utils.getProperty)(_classPrivateFieldGet(this, _origin), propertyPath);
168
- }
169
- var _default = AccessorCache;
170
- exports["default"] = _default;
@@ -1,10 +0,0 @@
1
- export default Atom;
2
- declare class Atom<T> {
3
- constructor(value?: T | Readonly<T>);
4
- get value(): Readonly<T>;
5
- connect(accessorId: number): number;
6
- disconnect(accessorId: number): number;
7
- isConnected(accessorId: number): boolean;
8
- setValue(newValue: T | Readonly<T>): void;
9
- #private;
10
- }
@@ -1,79 +0,0 @@
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["default"] = void 0;
7
- var _utils = require("../../utils");
8
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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; }
11
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
- 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); }
13
- function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
14
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
15
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
16
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
17
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
18
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
19
- function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
20
- var isFunction = function () {
21
- var toString = Function.prototype.toString;
22
- var is = function is(v) {
23
- try {
24
- return toString.call(v);
25
- } catch (e) {
26
- return false;
27
- }
28
- };
29
- return is;
30
- }();
31
- var _connections = new WeakMap();
32
- var _value = new WeakMap();
33
- var Atom = function () {
34
- function Atom() {
35
- var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
36
- _classCallCheck(this, Atom);
37
- _classPrivateFieldInitSpec(this, _connections, {
38
- writable: true,
39
- value: void 0
40
- });
41
- _classPrivateFieldInitSpec(this, _value, {
42
- writable: true,
43
- value: void 0
44
- });
45
- _classPrivateFieldSet(this, _connections, new Set());
46
- this.setValue(value);
47
- }
48
- _createClass(Atom, [{
49
- key: "value",
50
- get: function get() {
51
- return _classPrivateFieldGet(this, _value);
52
- }
53
- }, {
54
- key: "connect",
55
- value: function connect(accessorId) {
56
- _classPrivateFieldGet(this, _connections).add(accessorId);
57
- return _classPrivateFieldGet(this, _connections).size;
58
- }
59
- }, {
60
- key: "disconnect",
61
- value: function disconnect(accessorId) {
62
- _classPrivateFieldGet(this, _connections)["delete"](accessorId);
63
- return _classPrivateFieldGet(this, _connections).size;
64
- }
65
- }, {
66
- key: "isConnected",
67
- value: function isConnected(accessorId) {
68
- return _classPrivateFieldGet(this, _connections).has(accessorId);
69
- }
70
- }, {
71
- key: "setValue",
72
- value: function setValue(newValue) {
73
- _classPrivateFieldSet(this, _value, !isFunction(newValue) ? (0, _utils.makeReadonly)((0, _utils.clonedeep)(newValue)) : newValue);
74
- }
75
- }]);
76
- return Atom;
77
- }();
78
- var _default = Atom;
79
- exports["default"] = _default;
package/dist/types.d.ts DELETED
@@ -1,91 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
3
- export type BaseSelectorMap<T extends State> = (string | keyof T)[] | ({
4
- [dataPropKey: string]: string | keyof T;
5
- } & {
6
- [dataPropKey: string]: "@@STATE";
7
- });
8
- export type BaseType = boolean | any[] | {
9
- [x: string]: any;
10
- } | KeyType;
11
- export type Data<SELECTOR_MAP extends BaseSelectorMap<State> = BaseSelectorMap<State>> = { [selectorKey in keyof SELECTOR_MAP]: Readonly<any>; };
12
- export type IStorage<T extends State> = {
13
- clone: (data: T) => T;
14
- getItem: (key: string) => T;
15
- removeItem: (key: string) => void;
16
- setItem: (key: string, data: T) => void;
17
- };
18
- export type IStore = {
19
- getState: NonReactUsageReport;
20
- resetState: NonReactUsageReport;
21
- setState: NonReactUsageReport;
22
- subscribe: NonReactUsageReport;
23
- };
24
- export type KeyType = number | string | symbol;
25
- export type Listener<T extends State> = (changes: Changes<T>) => void;
26
- export type NonReactUsageReport = () => never;
27
- export type PartialState<T extends State> = { [K in keyof T]?: T[K]; };
28
- export type Prehooks<T extends State> = {
29
- resetState?: (resetData: PartialState<T>, state: {
30
- current: T;
31
- original: T;
32
- }) => boolean;
33
- setState?: (newChanges: Changes<T>) => boolean;
34
- };
35
- export type SelectorMap<T extends State = State, MAP extends BaseSelectorMap<T> = BaseSelectorMap<T>> = MAP;
36
- export type State = {
37
- [x: string]: any;
38
- [x: number]: any;
39
- [x: symbol]: any;
40
- };
41
- export type StoreInternal<T extends State> = {
42
- resetState: (propertyPaths?: string[]) => void;
43
- setState: (changes: Changes<T>) => void;
44
- } & {
45
- getState: (clientId: string, ...propertyPaths?: string[]) => {
46
- [propertyPaths: string]: Readonly<any>;
47
- };
48
- subscribe: (listener: Listener<T>) => Unsubscribe;
49
- unlinkCache: (clientId: string) => void;
50
- };
51
- export type Store<T extends State, SELECTOR_MAP extends BaseSelectorMap<T> = BaseSelectorMap<T>> = {
52
- data: Data<SELECTOR_MAP>;
53
- resetState: (propertyPaths?: string[]) => void;
54
- setState: (changes: Changes<T>) => void;
55
- };
56
- export type Changes<T extends State> = UpdatePayload<PartialState<T>> | UpdatePayloadArray<PartialState<T>>;
57
- export type UpdateStats = {
58
- hasChanges: boolean;
59
- };
60
- export type UpdatePayloadArray<T> = Array<UpdatePayload<T>>;
61
- export type UpdatePayload<T> = "@@CLEAR" | T | ClearCommand | DeleteCommand<T> | MoveCommand | PushCommand | ReplaceCommand | SetCommand<T> | SpliceCommand | { [K in keyof T]?: UpdatePayload<T[K]>; };
62
- export type ClearCommand = {
63
- "@@CLEAR": any;
64
- };
65
- export type DeleteCommand<T extends any[] | State> = {
66
- "@@DELETE": (keyof T)[];
67
- };
68
- export type MoveCommand = {
69
- "@@MOVE": [number, number, number?];
70
- };
71
- export type PushCommand = {
72
- "@@PUSH": any[];
73
- };
74
- export type ReplaceCommand = {
75
- "@@REPLACE": BaseType;
76
- };
77
- export type SetCommand<V> = {
78
- "@@SET": BaseType | ((currentValue: V) => any);
79
- };
80
- export type SpliceCommand = {
81
- "@@SPLICE": [number, number, ...any[]];
82
- };
83
- export type CLEAR_TAG = typeof import("./constants").CLEAR_TAG;
84
- export type DELETE_TAG = typeof import("./constants").DELETE_TAG;
85
- export type FULL_STATE_SELECTOR = typeof import("./constants").FULL_STATE_SELECTOR;
86
- export type MOVE_TAG = typeof import("./constants").MOVE_TAG;
87
- export type PUSH_TAG = typeof import("./constants").PUSH_TAG;
88
- export type REPLACE_TAG = typeof import("./constants").REPLACE_TAG;
89
- export type SET_TAG = typeof import("./constants").SET_TAG;
90
- export type SPLICE_TAG = typeof import("./constants").SPLICE_TAG;
91
- export type Unsubscribe = VoidFunction;
@@ -1,7 +0,0 @@
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
- };
@@ -1,52 +0,0 @@
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,12 +0,0 @@
1
- export function arrangePropertyPaths(propertyPaths: Array<string>): Array<string>;
2
- export function isDataContainer(v: any): boolean;
3
- export function makeReadonly<T>(v: T): Readonly<T>;
4
- export function mapPathsToObject<T extends {
5
- [x: string]: any;
6
- }>(source: T, propertyPaths: Array<string>, transform?: Tranform): { [K in keyof T]?: any; };
7
- export function clonedeep<T, R>(value: T): R;
8
- export const getProperty: typeof get;
9
- export const stringToDotPath: (path: string) => string;
10
- export type Tranform<T = any> = (property: PropertyInfo) => T;
11
- export type PropertyInfo = import("@webkrafters/get-property").PropertyInfo;
12
- import get from "@webkrafters/get-property";
@@ -1,173 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- exports.arrangePropertyPaths = arrangePropertyPaths;
6
- exports.getProperty = exports.clonedeep = void 0;
7
- exports.isDataContainer = isDataContainer;
8
- exports.makeReadonly = makeReadonly;
9
- exports.mapPathsToObject = mapPathsToObject;
10
- exports.stringToDotPath = void 0;
11
- var _lodash = _interopRequireDefault(require("lodash.clonedeepwith"));
12
- var _lodash2 = _interopRequireDefault(require("lodash.isplainobject"));
13
- var _clonedeepEligibilityCheck = _interopRequireDefault(require("./clonedeep-eligibility-check"));
14
- var _getProperty = _interopRequireDefault(require("@webkrafters/get-property"));
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
16
- 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); }
17
- 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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
18
- 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); }
19
- 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; }
20
- function arrangePropertyPaths(propertyPaths) {
21
- var superPathTokensMap = {};
22
- var _iterator = _createForOfIteratorHelper(propertyPaths),
23
- _step;
24
- try {
25
- var _loop = function _loop() {
26
- var path = _step.value;
27
- var pathTokens = path.replace(/\[([0-9]+)\]/g, '.$1').replace(/^\./, '').split(/\./);
28
- L2: {
29
- var replacedSuperPaths = [];
30
- var _loop2 = function _loop2(superPath) {
31
- var superPathTokens = superPathTokensMap[superPath];
32
- if (superPathTokens.length <= pathTokens.length) {
33
- if (superPathTokens.every(function (p, i) {
34
- return p === pathTokens[i];
35
- })) {
36
- return "break|L2";
37
- }
38
- return "continue";
39
- }
40
- pathTokens.every(function (p, i) {
41
- return p === superPathTokens[i];
42
- }) && replacedSuperPaths.push(superPath);
43
- };
44
- for (var superPath in superPathTokensMap) {
45
- var _ret = _loop2(superPath);
46
- if (_ret === "break|L2") break L2;
47
- if (_ret === "continue") continue;
48
- }
49
- superPathTokensMap[path] = pathTokens;
50
- for (var _i = 0, _replacedSuperPaths = replacedSuperPaths; _i < _replacedSuperPaths.length; _i++) {
51
- var _path = _replacedSuperPaths[_i];
52
- delete superPathTokensMap[_path];
53
- }
54
- }
55
- };
56
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
- _loop();
58
- }
59
- } catch (err) {
60
- _iterator.e(err);
61
- } finally {
62
- _iterator.f();
63
- }
64
- return Object.keys(superPathTokensMap);
65
- }
66
- ;
67
- var clonedeep = function () {
68
- var clone = function clone(value) {
69
- var customizer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (v) {
70
- if (v === null) {
71
- return;
72
- }
73
- if (_typeof(v) === 'object') {
74
- if ('clone' in v && typeof v.clone === 'function') {
75
- return v.clone();
76
- }
77
- if ('cloneNode' in v && typeof v.cloneNode === 'function') {
78
- return v.cloneNode(true);
79
- }
80
- }
81
- if (!(0, _clonedeepEligibilityCheck["default"])(v).isEligible) {
82
- return v;
83
- }
84
- };
85
- return (0, _lodash["default"])(value, customizer);
86
- };
87
- var clonedeep = function clonedeep(value) {
88
- return clone(value);
89
- };
90
- return clonedeep;
91
- }();
92
- exports.clonedeep = clonedeep;
93
- var getProperty = _getProperty["default"];
94
- exports.getProperty = getProperty;
95
- function isDataContainer(v) {
96
- return (0, _lodash2["default"])(v) || Array.isArray(v);
97
- }
98
- function makeReadonly(v) {
99
- var frozen = true;
100
- if ((0, _lodash2["default"])(v)) {
101
- for (var k in v) {
102
- makeReadonly(v[k]);
103
- }
104
- frozen = Object.isFrozen(v);
105
- } else if (Array.isArray(v)) {
106
- var vLen = v.length;
107
- for (var i = 0; i < vLen; i++) {
108
- makeReadonly(v[i]);
109
- }
110
- frozen = Object.isFrozen(v);
111
- }
112
- !frozen && Object.freeze(v);
113
- return v;
114
- }
115
- ;
116
- var defaultFormatValue = function defaultFormatValue(_ref) {
117
- var value = _ref.value;
118
- return value;
119
- };
120
- var stringToDotPath = function () {
121
- var BRACKET_OPEN = /\.?\[/g;
122
- var BRACKET_CLOSE = /^\.|\]/g;
123
- return function (path) {
124
- return path.replace(BRACKET_OPEN, '.').replace(BRACKET_CLOSE, '');
125
- };
126
- }();
127
- exports.stringToDotPath = stringToDotPath;
128
- function mapPathsToObject(source, propertyPaths) {
129
- var transform = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultFormatValue;
130
- var paths = [];
131
- var _iterator2 = _createForOfIteratorHelper(propertyPaths),
132
- _step2;
133
- try {
134
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
135
- var path = _step2.value;
136
- paths.push(stringToDotPath(path));
137
- }
138
- } catch (err) {
139
- _iterator2.e(err);
140
- } finally {
141
- _iterator2.f();
142
- }
143
- var dest = {};
144
- var object = dest;
145
- var _iterator3 = _createForOfIteratorHelper(arrangePropertyPaths(paths)),
146
- _step3;
147
- try {
148
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
149
- var _path2 = _step3.value;
150
- var property = getProperty(source, _path2);
151
- if (!property.exists) {
152
- continue;
153
- }
154
- for (var tokens = _path2.split('.'), tLen = tokens.length, t = 0; t < tLen; t++) {
155
- var token = tokens[t];
156
- if (t + 1 === tLen) {
157
- object[token] = transform(property);
158
- object = dest;
159
- break;
160
- }
161
- if (!(token in object)) {
162
- object[token] = {};
163
- }
164
- object = object[token];
165
- }
166
- }
167
- } catch (err) {
168
- _iterator3.e(err);
169
- } finally {
170
- _iterator3.f();
171
- }
172
- return dest;
173
- }
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require( './dist/main' );