@webkrafters/react-observable-context 4.0.0-alpha.1 → 4.0.0-alpha.2
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.
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +7 -4
- package/dist/main/hooks/use-render-key-provider/index.d.ts +1 -0
- package/dist/main/hooks/use-render-key-provider/index.js +34 -0
- package/dist/main/hooks/use-state-manager/index.d.ts +1 -1
- package/dist/main/hooks/use-store/index.d.ts +1 -1
- package/dist/main/hooks/use-store/index.js +2 -2
- package/dist/main/index.d.ts +1 -1
- package/dist/main/index.js +77 -23
- package/dist/main/set-state/index.js +1 -1
- package/dist/model/accessor/index.d.ts +1 -1
- package/dist/model/accessor/index.js +25 -140
- package/dist/model/accessor-cache/index.d.ts +1 -1
- package/dist/model/accessor-cache/index.js +27 -28
- package/dist/model/atom/index.d.ts +1 -1
- package/dist/model/atom/index.js +5 -3
- package/dist/types.d.ts +1 -1
- package/package.json +114 -112
- package/dist/main/hooks/use-render-keys-manager/index.d.ts +0 -1
- package/dist/main/hooks/use-render-keys-manager/index.js +0 -34
package/dist/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/** @type {
|
|
1
|
+
/** @type {"@@STATE"} */
|
package/dist/constants.js
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports.
|
|
6
|
-
/** @type {
|
|
7
|
-
var
|
|
8
|
-
exports.
|
|
5
|
+
exports.NULL_STATE_SELECTOR = exports.FULL_STATE_SELECTOR = void 0;
|
|
6
|
+
/** @type {"@@STATE"} */
|
|
7
|
+
var FULL_STATE_SELECTOR = '@@STATE';
|
|
8
|
+
exports.FULL_STATE_SELECTOR = FULL_STATE_SELECTOR;
|
|
9
|
+
/** @type {""} */
|
|
10
|
+
var NULL_STATE_SELECTOR = '';
|
|
11
|
+
exports.NULL_STATE_SELECTOR = NULL_STATE_SELECTOR;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = void 0;
|
|
6
|
+
var _react = require("react");
|
|
7
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
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."); }
|
|
9
|
+
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); }
|
|
10
|
+
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; }
|
|
11
|
+
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; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
/**
|
|
14
|
* @type {Provider<T>}
|
|
1
15
|
* @template {State} T
|
|
2
16
|
*/
|
|
17
|
+
var getCurrKeys = function getCurrKeys(selectorMap) {
|
|
18
|
+
var currKeys = Object.values(selectorMap);
|
|
19
|
+
return currKeys.length ? Array.from(new Set(currKeys)) : [];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
3
22
|
* @type {Provider<T>}
|
|
4
23
|
* @template {State} T
|
|
5
24
|
*/
|
|
25
|
+
var useRenderKeyProvider = function useRenderKeyProvider(selectorMap) {
|
|
26
|
+
var _useState = (0, _react.useState)(function () {
|
|
27
|
+
return getCurrKeys(selectorMap);
|
|
28
|
+
}),
|
|
29
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
+
renderKeys = _useState2[0],
|
|
31
|
+
setRenderKeys = _useState2[1];
|
|
32
|
+
var currKeys = getCurrKeys(selectorMap);
|
|
33
|
+
(renderKeys.length !== currKeys.length || renderKeys.some(function (k, i) {
|
|
34
|
+
return k !== currKeys[i];
|
|
35
|
+
})) && setRenderKeys(currKeys);
|
|
36
|
+
return renderKeys;
|
|
37
|
+
};
|
|
38
|
+
var _default = useRenderKeyProvider;
|
|
39
|
+
/**
|
|
6
40
|
* @callback Provider
|
|
7
41
|
* @param {{[selectorKey: string]: string|keyof T}} selectorMap Key:value pairs where `key` => arbitrary key given to Store.data property holding the state slices and `value` => property paths to state slices used by this component. May use `{..., state: '@@STATE'}` to indicate a desire to obtain the entire state object and assign to a `state` property of Store.data. A change in any of the referenced properties results in this component render. When using `['@@STATE']`, any change in the state object results in this component render.
|
|
8
42
|
* @returns {[string|keyof T]} Property paths
|
|
9
43
|
* @template {State} T
|
|
10
44
|
*/
|
|
45
|
+
exports["default"] = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default useStateManager;
|
|
2
1
|
* @param {T} initStateValue
|
|
3
2
|
* @template {State} T
|
|
4
3
|
*/
|
|
5
4
|
select: (clientId: string, ...propertyPaths?: string[]) => Readonly<import("../../../types").PartialState<T>>;
|
|
6
5
|
state: T;
|
|
7
6
|
stateWatch: Listener<T>;
|
|
8
7
|
unlink: (clientId: string) => void;
|
|
8
|
+
export default useStateManager;
|
|
9
9
|
* @param {T} initStateValue
|
|
10
10
|
* @template {State} T
|
|
11
11
|
*/
|
|
12
12
|
select: (clientId: string, ...propertyPaths?: string[]) => {
|
|
13
13
|
[propertyPaths: string]: Readonly<any>;
|
|
14
14
|
};
|
|
15
15
|
state: T;
|
|
16
16
|
stateWatch: Listener<T>;
|
|
17
17
|
unlink: (clientId: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export namespace deps {
|
|
2
1
|
export { _setState as setState };
|
|
3
2
|
export { v4 as uuid };
|
|
4
3
|
* @param {Prehooks<T>} prehooks
|
|
5
4
|
* @param {T} value
|
|
6
5
|
* @param {IStorage<T>} [storage] Closed to modification post-initialization
|
|
7
6
|
* @template {State} T
|
|
8
7
|
*/
|
|
9
8
|
getState: (clientId: string, ...propertyPaths?: string[]) => Readonly<import("../../../types").PartialState<T>>;
|
|
10
9
|
resetState: VoidFunction;
|
|
11
10
|
setState: (changes: import("../../../types").PartialState<T>) => void;
|
|
12
11
|
subscribe: (listener: import("../../../types").Listener<T>) => VoidFunction;
|
|
13
12
|
unlinkCache: (clientId: string) => void;
|
|
13
|
+
export namespace deps {
|
|
14
14
|
export { _setState as setState };
|
|
15
15
|
export { v4 as uuid };
|
|
16
16
|
* @param {Prehooks<T>} prehooks
|
|
17
17
|
* @param {T} value
|
|
18
18
|
* @param {IStorage<T>} [storage] Closed to modification post-initialization
|
|
19
19
|
* @template {State} T
|
|
20
20
|
*/
|
|
21
21
|
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
22
22
|
[propertyPaths: string]: Readonly<any>;
|
|
23
23
|
};
|
|
24
24
|
resetState: VoidFunction;
|
|
25
25
|
setState: (changes: import("../../../types").PartialState<T>) => void;
|
|
26
26
|
subscribe: (listener: import("../../../types").Listener<T>) => VoidFunction;
|
|
27
27
|
unlinkCache: (clientId: string) => void;
|
|
@@ -53,9 +53,9 @@ var useStore = function useStore(prehooks, value, storage) {
|
|
|
53
53
|
_useState4 = _slicedToArray(_useState3, 1),
|
|
54
54
|
_storage = _useState4[0];
|
|
55
55
|
/** @type {Listener<T>} */
|
|
56
|
-
var onChange = function onChange(
|
|
56
|
+
var onChange = function onChange(changes) {
|
|
57
57
|
return listeners.forEach(function (listener) {
|
|
58
|
-
return listener(
|
|
58
|
+
return listener(changes);
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
/** @type {StoreInternal<T>["resetState"]} */
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class UsageError extends Error {
|
|
2
1
|
Provider: ObservableProvider<S>;
|
|
3
2
|
children?: ReactNode;
|
|
4
3
|
prehooks?: Prehooks<T>;
|
|
5
4
|
storage?: IStorage<T>;
|
|
6
5
|
value: PartialState<T>;
|
|
6
|
+
export class UsageError extends Error {
|
|
7
7
|
[selectorKey: string]: string | keyof T_1;
|
|
8
8
|
Provider: ObservableProvider<S>;
|
|
9
9
|
children?: ReactNode;
|
|
10
10
|
prehooks?: Prehooks<T>;
|
|
11
11
|
storage?: IStorage<T>;
|
|
12
12
|
value: PartialState<T>;
|
package/dist/main/index.js
CHANGED
|
@@ -4,10 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
exports.useContext = exports.createContext = exports.UsageError = void 0;
|
|
6
6
|
var _react = _interopRequireWildcard(require("react"));
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash.
|
|
8
|
-
var _lodash2 = _interopRequireDefault(require("lodash.
|
|
7
|
+
var _lodash = _interopRequireDefault(require("lodash.isempty"));
|
|
8
|
+
var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
|
|
9
|
+
var _lodash3 = _interopRequireDefault(require("lodash.omit"));
|
|
9
10
|
var _uuid = require("uuid");
|
|
10
|
-
var
|
|
11
|
+
var _useRenderKeyProvider = _interopRequireDefault(require("./hooks/use-render-key-provider"));
|
|
11
12
|
var _useStore = _interopRequireDefault(require("./hooks/use-store"));
|
|
12
13
|
var _excluded = ["getState", "subscribe", "unlinkCache"];
|
|
13
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -16,6 +17,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
16
17
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
18
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
19
|
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; }
|
|
20
|
+
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; } } }; }
|
|
19
21
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
20
22
|
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."); }
|
|
21
23
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
@@ -64,7 +66,7 @@ var reportNonReactUsage = function reportNonReactUsage() {
|
|
|
64
66
|
var ChildMemo = function () {
|
|
65
67
|
var useNodeMemo = function useNodeMemo(node) {
|
|
66
68
|
var nodeRef = (0, _react.useRef)(node);
|
|
67
|
-
if (!(0,
|
|
69
|
+
if (!(0, _lodash2["default"])((0, _lodash3["default"])(nodeRef.current, '_owner'), (0, _lodash3["default"])(node, '_owner'))) {
|
|
68
70
|
nodeRef.current = node;
|
|
69
71
|
}
|
|
70
72
|
return nodeRef.current;
|
|
@@ -91,7 +93,7 @@ var memoizeImmediateChildTree = function memoizeImmediateChildTree(children) {
|
|
|
91
93
|
return child;
|
|
92
94
|
}
|
|
93
95
|
if ((_child$props = child.props) !== null && _child$props !== void 0 && _child$props.children) {
|
|
94
|
-
child = (0, _react.cloneElement)(child, (0,
|
|
96
|
+
child = (0, _react.cloneElement)(child, (0, _lodash3["default"])(child.props, 'children'), memoizeImmediateChildTree(child.props.children));
|
|
95
97
|
}
|
|
96
98
|
return _react["default"].createElement(ChildMemo, {
|
|
97
99
|
child: child
|
|
@@ -129,9 +131,9 @@ var createContext = function createContext() {
|
|
|
129
131
|
return Context;
|
|
130
132
|
};
|
|
131
133
|
exports.createContext = createContext;
|
|
132
|
-
/**
|
|
133
134
|
* Actively monitors the store and triggers component re-render if any of the watched keys in the state objects changes
|
|
134
135
|
*
|
|
135
136
|
* @param {ObservableContext<T>} context Refers to the PublicObservableContext<T> type of the ObservableContext<T>
|
|
136
137
|
* @param {Array<string|keyof T>} [renderKeys = []] a list of paths to state object properties used by this component: see examples below. May use `['@@STATE']` to indicate a desire to obtain the entire state object. A change in any of the referenced properties results in this component render. When using `['@@STATE']`, any change in the state object results in this component render.
|
|
137
138
|
* @returns {Store<T>}
|
|
138
139
|
* @template {State} T
|
|
139
140
|
* @see {ObservableContext<T>}
|
|
140
141
|
* @example
|
|
141
142
|
* a valid renderKey follows the `lodash` object property path convention.
|
|
142
143
|
* for a state = { a: 1, b: 2, c: 3, d: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] } }
|
|
143
144
|
* Any of the following is a valid renderKey
|
|
144
145
|
* 'a' => 1
|
|
145
146
|
* 'd' => { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] }
|
|
146
147
|
* 'd.e' => 5
|
|
147
148
|
* 'd.e.f => [6, { x: 7, y: 8, z: 9 } ]
|
|
148
149
|
* 'd.e.f[0]' or 'd.e.f.0' => 6
|
|
149
150
|
* 'd.e.f[1]' or 'd.e.f.1' => { x: 7, y: 8, z: 9 }
|
|
150
151
|
* 'd.e.f[1].x' or 'd.e.f.1.x' => 7
|
|
151
152
|
* '@@STATE' => state
|
|
152
153
|
*/
|
|
154
|
+
/**
|
|
153
155
|
* Actively monitors the store and triggers component re-render if any of the watched keys in the state objects changes
|
|
154
156
|
*
|
|
155
157
|
* @param {ObservableContext<T>} context Refers to the PublicObservableContext<T> type of the ObservableContext<T>
|
|
156
158
|
* @param {{[selectorKey: string]: string|keyof T}} [selectorMap = {}] Key:value pairs where `key` => arbitrary key given to Store.data property holding the state slices and `value` => property paths to state slices used by this component: see examples below. May use `{..., state: '@@STATE'}` to indicate a desire to obtain the entire state object and assign to a `state` property of Store.data. A change in any of the referenced properties results in this component render. When using `['@@STATE']`, any change in the state object results in this component render.
|
|
157
159
|
* @returns {Store<T>}
|
|
158
160
|
* @template {State} T
|
|
159
161
|
* @see {ObservableContext<T>}
|
|
160
162
|
* @example
|
|
161
163
|
* a valid propertyPath follows the `lodash` object property path convention.
|
|
162
164
|
* for a state = { a: 1, b: 2, c: 3, d: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] } }
|
|
163
165
|
* Any of the following is an applicable selector map.
|
|
164
166
|
* {count: 'a', myData: 'd'} => {count: 1, myData: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] }}
|
|
165
167
|
* {count: 'a'} => {count: 1}
|
|
166
168
|
* {myData: 'd'} => {mydata: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] }}
|
|
167
169
|
* {xyz: 'd.e'} => {xyz: 5}
|
|
168
170
|
* {def: 'd.e.f'} => {def: [6, { x: 7, y: 8, z: 9 } ]}
|
|
169
171
|
* {f1: 'd.e.f[0]'} or {f1: 'd.e.f.0'} => {f1: 6}
|
|
170
172
|
* {secondFElement: 'd.e.f[1]'} or {secondFElement: 'd.e.f.1'} => {secondFElement: { x: 7, y: 8, z: 9 }}
|
|
171
173
|
* {myX: 'd.e.f[1].x'} or {myX: 'd.e.f.1.x'} => {myX: 7}
|
|
172
174
|
* {myData: '@@STATE'} => {myData: state}
|
|
173
175
|
*/
|
|
174
176
|
var useContext = function useContext(context) {
|
|
175
|
-
var
|
|
177
|
+
var selectorMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
176
178
|
/** @type {StoreInternal<T>} */
|
|
177
179
|
var _useContext2 = (0, _react.useContext)(context),
|
|
178
180
|
_getState = _useContext2.getState,
|
|
@@ -141,28 +143,80 @@ var useContext = function useContext(context) {
|
|
|
141
143
|
var _useState = (0, _react.useState)(_uuid.v4),
|
|
142
144
|
_useState2 = _slicedToArray(_useState, 1),
|
|
143
145
|
clientId = _useState2[0];
|
|
144
|
-
var _renderKeys = (0,
|
|
145
|
-
/** @
|
|
146
|
-
var
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
var _renderKeys = (0, _useRenderKeyProvider["default"])(selectorMap);
|
|
147
|
+
/** @type {{[propertyPath: string]: string}} Reversed selectorMap i.e. {selectorKey: propertyPath} => {propertyPath: selectorKey} */
|
|
148
|
+
var path2SelectorMap = (0, _react.useMemo)(function () {
|
|
149
|
+
var map = {};
|
|
150
|
+
if ((0, _lodash["default"])(_renderKeys)) {
|
|
151
|
+
return map;
|
|
152
|
+
}
|
|
153
|
+
;
|
|
154
|
+
for (var selectorKey in selectorMap) {
|
|
155
|
+
map[selectorMap[selectorKey]] = selectorKey;
|
|
156
|
+
}
|
|
157
|
+
return map;
|
|
158
|
+
}, [_renderKeys]);
|
|
159
|
+
/** @type {[Data, Function]} */
|
|
160
|
+
var _useState3 = (0, _react.useState)(function () {
|
|
161
|
+
var data = {};
|
|
162
|
+
if ((0, _lodash["default"])(_renderKeys)) {
|
|
163
|
+
return data;
|
|
164
|
+
}
|
|
165
|
+
var state = _getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
|
|
166
|
+
var _iterator = _createForOfIteratorHelper(_renderKeys),
|
|
167
|
+
_step;
|
|
168
|
+
try {
|
|
169
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
170
|
+
var path = _step.value;
|
|
171
|
+
data[path2SelectorMap[path]] = state[path];
|
|
172
|
+
}
|
|
173
|
+
} catch (err) {
|
|
174
|
+
_iterator.e(err);
|
|
175
|
+
} finally {
|
|
176
|
+
_iterator.f();
|
|
177
|
+
}
|
|
178
|
+
return data;
|
|
179
|
+
}),
|
|
150
180
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
151
181
|
data = _useState4[0],
|
|
152
182
|
setData = _useState4[1];
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
183
|
+
var updateData = function updateData() {
|
|
184
|
+
var hasChanges = false;
|
|
185
|
+
var state = _getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
|
|
186
|
+
var _iterator2 = _createForOfIteratorHelper(_renderKeys),
|
|
187
|
+
_step2;
|
|
188
|
+
try {
|
|
189
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
190
|
+
var path = _step2.value;
|
|
191
|
+
if (data[path2SelectorMap[path]] !== state[path]) {
|
|
192
|
+
data[path2SelectorMap[path]] = state[path];
|
|
193
|
+
hasChanges = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} catch (err) {
|
|
197
|
+
_iterator2.e(err);
|
|
198
|
+
} finally {
|
|
199
|
+
_iterator2.f();
|
|
200
|
+
}
|
|
201
|
+
hasChanges && setData(_objectSpread({}, data));
|
|
202
|
+
};
|
|
161
203
|
(0, _react.useEffect)(function () {
|
|
204
|
+
if ((0, _lodash["default"])(_renderKeys)) {
|
|
205
|
+
!(0, _lodash2["default"])({}, data) && setData({});
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
for (var selectorKey in data) {
|
|
209
|
+
if (!(selectorMap[selectorKey] in path2SelectorMap)) {
|
|
210
|
+
delete data[selectorKey];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var unsubscribe = subscribe(updateData);
|
|
214
|
+
updateData();
|
|
162
215
|
return function () {
|
|
163
|
-
|
|
216
|
+
unsubscribe();
|
|
217
|
+
unlinkCache(clientId);
|
|
164
218
|
};
|
|
165
|
-
}, []);
|
|
219
|
+
}, [_renderKeys]);
|
|
166
220
|
return (0, _react.useMemo)(function () {
|
|
167
221
|
return _objectSpread({
|
|
168
222
|
data: data
|
|
@@ -97,7 +97,7 @@ function setState(state, newState, onStateChange) {
|
|
|
97
97
|
hasChanges: false
|
|
98
98
|
};
|
|
99
99
|
set(state, newState, stats);
|
|
100
|
-
stats.hasChanges && (onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(
|
|
100
|
+
stats.hasChanges && (onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(newState));
|
|
101
101
|
}
|
|
102
102
|
;
|
|
103
103
|
var _default = setState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default Accessor;
|
|
2
1
|
static "__#5@#NUM_INSTANCES": number;
|
|
3
2
|
/**
|
|
4
3
|
* @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
|
|
5
4
|
* @param {Array<string>} accessedPropertyPaths
|
|
6
5
|
*/
|
|
7
6
|
constructor(source: T, accessedPropertyPaths: Array<string>);
|
|
8
7
|
/** @type {boolean} */
|
|
9
8
|
refreshDue: boolean;
|
|
10
9
|
get numClients(): number;
|
|
11
10
|
get id(): number;
|
|
12
11
|
get paths(): string[];
|
|
13
12
|
get value(): Readonly<import("../../types").PartialState<T>>;
|
|
14
13
|
/** @param {string} clientId */
|
|
15
14
|
addClient(clientId: string): void;
|
|
16
15
|
hasClient(clientId: string): boolean;
|
|
17
16
|
removeClient(clientId: string): boolean;
|
|
18
17
|
/**
|
|
19
18
|
* @param {{[propertyPath: string]: Atom}} atoms Curated slices of state currently requested
|
|
20
19
|
* @returns {Readonly<PartialState<State>>}
|
|
21
20
|
*/
|
|
22
21
|
refreshValue(atoms: {
|
|
23
22
|
[propertyPath: string]: import("../atom").default;
|
|
24
23
|
}): Readonly<PartialState<State>>;
|
|
25
24
|
#private;
|
|
25
|
+
export default Accessor;
|
|
26
26
|
static "__#5@#NUM_INSTANCES": number;
|
|
27
27
|
/**
|
|
28
28
|
* @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
|
|
29
29
|
* @param {Array<string>} accessedPropertyPaths
|
|
30
30
|
*/
|
|
31
31
|
constructor(source: T, accessedPropertyPaths: Array<string>);
|
|
32
32
|
/** @type {boolean} */
|
|
33
33
|
refreshDue: boolean;
|
|
34
34
|
get numClients(): number;
|
|
35
35
|
get id(): number;
|
|
36
36
|
get paths(): string[];
|
|
37
37
|
get value(): {
|
|
38
38
|
[propertyPath: string]: Readonly<any>;
|
|
39
39
|
};
|
|
40
40
|
/** @param {string} clientId */
|
|
41
41
|
addClient(clientId: string): void;
|
|
42
42
|
hasClient(clientId: string): boolean;
|
|
43
43
|
removeClient(clientId: string): boolean;
|
|
44
44
|
/**
|
|
45
45
|
* @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
|
|
46
46
|
* @returns {{[propertyPath: string]: Readonly<*>}}
|
|
47
47
|
*/
|
|
48
48
|
refreshValue(atoms: {
|
|
49
49
|
[propertyPath: string]: import("../atom").default<any>;
|
|
50
50
|
}): {
|
|
51
51
|
[propertyPath: string]: Readonly<any>;
|
|
52
52
|
};
|
|
53
53
|
#private;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
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); }
|
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
|
3
4
|
value: true
|
|
4
5
|
});
|
|
5
6
|
exports["default"] = void 0;
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var _lodash4 = _interopRequireDefault(require("lodash.set"));
|
|
10
|
-
var _constants = require("../../constants");
|
|
11
|
-
var _utils = require("../../utils");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
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); }
|
|
7
|
+
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; } } }; }
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
14
10
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
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); } }
|
|
16
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
14
|
+
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
15
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
18
16
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
19
17
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
@@ -25,118 +23,18 @@ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) {
|
|
|
25
23
|
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
26
24
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
27
25
|
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; } }
|
|
28
|
-
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; } } }; }
|
|
29
|
-
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); }
|
|
30
|
-
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; }
|
|
31
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
32
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
33
|
-
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; }
|
|
34
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
35
|
-
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); }
|
|
36
|
-
/**
|
|
37
26
|
* Returns function that checks whether its argument is either the ancestorPath or its child/descendant
|
|
38
27
|
*
|
|
39
28
|
* @type {(ancestorPath?: string) => {contains: (path: string) => boolean}}
|
|
40
29
|
*/
|
|
41
|
-
var getPathTesterIn = function () {
|
|
42
|
-
var PATH_DELIMITERS = {
|
|
43
|
-
'.': null,
|
|
44
|
-
'[': null
|
|
45
|
-
};
|
|
46
|
-
return function () {
|
|
47
|
-
var ancestorPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
48
|
-
var ancestorPathLength = (ancestorPath === null || ancestorPath === void 0 ? void 0 : ancestorPath.length) || 0;
|
|
49
|
-
return {
|
|
50
|
-
contains: function contains(path) {
|
|
51
|
-
return ancestorPathLength && path.startsWith(ancestorPath) && (ancestorPathLength === path.length || path[ancestorPathLength] in PATH_DELIMITERS);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
}();
|
|
56
|
-
/**
|
|
57
30
|
* Merges `changes` into a `slice` of the state object.
|
|
58
31
|
*
|
|
59
32
|
* Advisory: Will undo the readonly xteristics of affected hierarchies within the `slice`.
|
|
60
33
|
*/
|
|
61
|
-
var mergeChanges = function () {
|
|
62
|
-
var matchCompositeType = function matchCompositeType(slice, changes) {
|
|
63
|
-
if (Array.isArray(slice) && Array.isArray(changes)) {
|
|
64
|
-
return Array;
|
|
65
|
-
}
|
|
66
|
-
if ((0, _lodash3["default"])(slice) && (0, _lodash3["default"])(changes)) {
|
|
67
|
-
return Object;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var doMergeAt = function doMergeAt(key, slice, changes) {
|
|
71
|
-
if ((0, _lodash2["default"])(slice[key], changes[key])) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (Object.isFrozen(changes[key])) {
|
|
75
|
-
slice[key] = changes[key];
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (Object.isFrozen(slice[key])) {
|
|
79
|
-
slice[key] = _objectSpread({}, slice[key]);
|
|
80
|
-
}
|
|
81
|
-
switch (matchCompositeType(slice[key], changes[key])) {
|
|
82
|
-
case Object:
|
|
83
|
-
runMerger(slice[key], changes[key]);
|
|
84
|
-
break;
|
|
85
|
-
case Array:
|
|
86
|
-
slice[key].length = changes[key].length;
|
|
87
|
-
runMerger(slice[key], changes[key]);
|
|
88
|
-
break;
|
|
89
|
-
default:
|
|
90
|
-
slice[key] = changes[key];
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
var runMerger = function runMerger(slice, changes) {
|
|
94
|
-
if ((0, _lodash3["default"])(changes)) {
|
|
95
|
-
for (var k in changes) {
|
|
96
|
-
doMergeAt(k, slice, changes);
|
|
97
|
-
}
|
|
98
|
-
} else if (Array.isArray(changes)) {
|
|
99
|
-
changes.forEach(function (_, c) {
|
|
100
|
-
return doMergeAt(c, slice, changes);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
34
|
* @param {T} slice
|
|
106
35
|
* @param {T} changes
|
|
107
36
|
* @template {PartialState<State>} T
|
|
108
37
|
*/
|
|
109
|
-
var mergeChanges = function mergeChanges(slice, changes) {
|
|
110
|
-
!(0, _lodash2["default"])(slice, changes) && runMerger(slice, changes);
|
|
111
|
-
};
|
|
112
|
-
return mergeChanges;
|
|
113
|
-
}();
|
|
114
|
-
/** @type {(paths: Array<string>) => Array<string>} */
|
|
115
|
-
var arrangePaths = function arrangePaths(paths) {
|
|
116
|
-
if (paths.includes(_constants.DEFAULT_STATE_PATH)) {
|
|
117
|
-
return [_constants.DEFAULT_STATE_PATH];
|
|
118
|
-
}
|
|
119
|
-
/** @type {Array<string>} */
|
|
120
|
-
var arranged = [];
|
|
121
|
-
var group = getPathTesterIn();
|
|
122
|
-
var _iterator = _createForOfIteratorHelper((0, _lodash["default"])(paths).sort()),
|
|
123
|
-
_step;
|
|
124
|
-
try {
|
|
125
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
126
|
-
var path = _step.value;
|
|
127
|
-
if (group.contains(path)) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
group = getPathTesterIn(path);
|
|
131
|
-
arranged.push(path);
|
|
132
|
-
}
|
|
133
|
-
} catch (err) {
|
|
134
|
-
_iterator.e(err);
|
|
135
|
-
} finally {
|
|
136
|
-
_iterator.f();
|
|
137
|
-
}
|
|
138
|
-
return arranged;
|
|
139
|
-
};
|
|
140
|
-
/** @template {State} T */
|
|
141
38
|
var _clients = new WeakMap();
|
|
142
39
|
var _id = new WeakMap();
|
|
143
40
|
var _paths = new WeakMap();
|
|
144
41
|
var _source = new WeakMap();
|
|
145
42
|
var _value = new WeakMap();
|
|
43
|
+
/** @template {State} T */
|
|
146
44
|
var Accessor = function () {
|
|
147
45
|
/** @type {Set<string>} */
|
|
148
46
|
/** @type {number} */
|
|
149
47
|
/** @type {Array<string>} */
|
|
150
48
|
/** @type {T} */
|
|
151
|
-
/** @type {Readonly
|
|
49
|
+
/** @type {{[propertyPath: string]: Readonly<*>}} */
|
|
152
50
|
/**
|
|
153
51
|
* @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
|
|
154
52
|
* @param {Array<string>} accessedPropertyPaths
|
|
155
53
|
*/
|
|
156
54
|
function Accessor(source, accessedPropertyPaths) {
|
|
157
55
|
var _Accessor$NUM_INSTANC, _Accessor$NUM_INSTANC2;
|
|
@@ -163,11 +61,11 @@ var Accessor = function () {
|
|
|
163
61
|
});
|
|
164
62
|
_classPrivateFieldSet(this, _clients, new Set());
|
|
165
63
|
_classPrivateFieldSet(this, _id, _classStaticPrivateFieldSpecSet(Accessor, Accessor, _NUM_INSTANCES, (_Accessor$NUM_INSTANC2 = _classStaticPrivateFieldSpecGet(Accessor, Accessor, _NUM_INSTANCES), ++_Accessor$NUM_INSTANC2)));
|
|
166
|
-
_classPrivateFieldSet(this, _paths,
|
|
64
|
+
_classPrivateFieldSet(this, _paths, Array.from(new Set(accessedPropertyPaths)));
|
|
167
65
|
/** @type {boolean} */
|
|
168
66
|
this.refreshDue = true;
|
|
169
67
|
_classPrivateFieldSet(this, _source, source);
|
|
170
|
-
_classPrivateFieldSet(this, _value,
|
|
68
|
+
_classPrivateFieldSet(this, _value, {});
|
|
171
69
|
}
|
|
172
70
|
_createClass(Accessor, [{
|
|
173
71
|
key: "numClients",
|
|
@@ -207,7 +105,7 @@ var Accessor = function () {
|
|
|
207
105
|
value: function removeClient(clientId) {
|
|
208
106
|
return _classPrivateFieldGet(this, _clients)["delete"](clientId);
|
|
209
107
|
}
|
|
210
|
-
/**
|
|
211
108
|
* @param {{[propertyPath: string]: Atom}} atoms Curated slices of state currently requested
|
|
212
109
|
* @returns {Readonly<PartialState<State>>}
|
|
213
110
|
*/
|
|
111
|
+
/**
|
|
214
112
|
* @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
|
|
215
113
|
* @returns {{[propertyPath: string]: Readonly<*>}}
|
|
216
114
|
*/
|
|
217
115
|
}, {
|
|
218
116
|
key: "refreshValue",
|
|
219
117
|
value: function refreshValue(atoms) {
|
|
@@ -215,36 +113,23 @@ var Accessor = function () {
|
|
|
215
113
|
return _classPrivateFieldGet(this, _value);
|
|
216
114
|
}
|
|
217
115
|
this.refreshDue = false;
|
|
218
|
-
var
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
} else {
|
|
226
|
-
/** @type {PartialState<State>} */
|
|
227
|
-
var update = {};
|
|
228
|
-
var _iterator2 = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths)),
|
|
229
|
-
_step2;
|
|
230
|
-
try {
|
|
231
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
232
|
-
var p = _step2.value;
|
|
233
|
-
if (!(p in atoms)) {
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
var atom = atoms[p];
|
|
237
|
-
!atom.isConnected(_classPrivateFieldGet(this, _id)) && atom.connect(_classPrivateFieldGet(this, _id));
|
|
238
|
-
(0, _lodash4["default"])(update, p, atom.value);
|
|
116
|
+
var _iterator = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths)),
|
|
117
|
+
_step;
|
|
118
|
+
try {
|
|
119
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
120
|
+
var p = _step.value;
|
|
121
|
+
if (!(p in atoms)) {
|
|
122
|
+
continue;
|
|
239
123
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_iterator2.f();
|
|
124
|
+
var atom = atoms[p];
|
|
125
|
+
!atom.isConnected(_classPrivateFieldGet(this, _id)) && atom.connect(_classPrivateFieldGet(this, _id));
|
|
126
|
+
_classPrivateFieldGet(this, _value)[p] = atom.value;
|
|
244
127
|
}
|
|
245
|
-
|
|
128
|
+
} catch (err) {
|
|
129
|
+
_iterator.e(err);
|
|
130
|
+
} finally {
|
|
131
|
+
_iterator.f();
|
|
246
132
|
}
|
|
247
|
-
_classPrivateFieldSet(this, _value, (0, _utils.makeReadonly)(value));
|
|
248
133
|
return _classPrivateFieldGet(this, _value);
|
|
249
134
|
}
|
|
250
135
|
}]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default AccessorCache;
|
|
2
1
|
/** @param {T} origin State object reference from which slices stored in this cache are to be curated */
|
|
3
2
|
constructor(origin: T);
|
|
4
3
|
/**
|
|
5
4
|
* Gets state slice from the cache matching the `propertyPaths`.\
|
|
6
5
|
* If not found, creates a new entry for the client from source, and returns it.
|
|
7
6
|
*
|
|
8
7
|
* @param {string} clientId
|
|
9
8
|
* @param {...string} propertyPaths
|
|
10
9
|
* @return {Readonly<PartialState<T>>}
|
|
11
10
|
*/
|
|
12
11
|
get(clientId: string, ...propertyPaths: string[]): Readonly<PartialState<T>>;
|
|
13
12
|
/**
|
|
14
13
|
* Unlinks a consumer from the cache: performing synchronized state cleanup
|
|
15
14
|
*
|
|
16
15
|
* @param {string} clientId
|
|
17
16
|
*/
|
|
18
17
|
unlinkClient(clientId: string): void;
|
|
19
18
|
/** Observes the origin state bearing ObservableContext store for state changes to update accessors. */
|
|
20
19
|
watchSource(): void;
|
|
21
20
|
#private;
|
|
21
|
+
export default AccessorCache;
|
|
22
22
|
/** @param {T} origin State object reference from which slices stored in this cache are to be curated */
|
|
23
23
|
constructor(origin: T);
|
|
24
24
|
/**
|
|
25
25
|
* Gets state slice from the cache matching the `propertyPaths`.\
|
|
26
26
|
* If not found, creates a new entry for the client from source, and returns it.
|
|
27
27
|
*
|
|
28
28
|
* @param {string} clientId
|
|
29
29
|
* @param {...string} propertyPaths
|
|
30
30
|
* @return {{[propertyPaths: string]: Readonly<*>}}
|
|
31
31
|
*/
|
|
32
32
|
get(clientId: string, ...propertyPaths: string[]): {
|
|
33
33
|
[propertyPaths: string]: Readonly<any>;
|
|
34
34
|
};
|
|
35
35
|
/**
|
|
36
36
|
* Unlinks a consumer from the cache: performing synchronized state cleanup
|
|
37
37
|
*
|
|
38
38
|
* @param {string} clientId
|
|
39
39
|
*/
|
|
40
40
|
unlinkClient(clientId: string): void;
|
|
41
41
|
watchSource(changes: import("../../types").PartialState<T>): void;
|
|
42
42
|
#private;
|
|
@@ -5,8 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
7
|
var _lodash = _interopRequireDefault(require("lodash.get"));
|
|
8
|
-
var _lodash2 = _interopRequireDefault(require("lodash.
|
|
9
|
-
var _lodash3 = _interopRequireDefault(require("lodash.
|
|
8
|
+
var _lodash2 = _interopRequireDefault(require("lodash.has"));
|
|
9
|
+
var _lodash3 = _interopRequireDefault(require("lodash.isempty"));
|
|
10
|
+
var _lodash4 = _interopRequireDefault(require("lodash.isequal"));
|
|
10
11
|
var _constants = require("../../constants");
|
|
11
12
|
var _atom = _interopRequireDefault(require("../atom"));
|
|
12
13
|
var _accessor = _interopRequireDefault(require("../accessor"));
|
|
@@ -32,14 +33,16 @@ var _accessors = new WeakMap();
|
|
|
32
33
|
var _atoms = new WeakMap();
|
|
33
34
|
var _origin = new WeakMap();
|
|
34
35
|
var _createAccessor = new WeakSet();
|
|
36
|
+
var _getOriginAt = new WeakSet();
|
|
35
37
|
/** @template {State} T */
|
|
36
38
|
var AccessorCache = function () {
|
|
37
39
|
/** @type {{[propertyPaths: string]: Accessor<T>}} */
|
|
38
|
-
/** @type {{[propertyPath: string]: Atom}} */
|
|
40
|
+
/** @type {{[propertyPath: string]: Atom<*>}} */
|
|
39
41
|
/** @type {T} */
|
|
40
42
|
/** @param {T} origin State object reference from which slices stored in this cache are to be curated */
|
|
41
43
|
function AccessorCache(origin) {
|
|
42
44
|
_classCallCheck(this, AccessorCache);
|
|
45
|
+
_classPrivateMethodInitSpec(this, _getOriginAt);
|
|
43
46
|
_classPrivateMethodInitSpec(this, _createAccessor);
|
|
44
47
|
_classPrivateFieldInitSpec(this, _accessors, {
|
|
45
48
|
writable: true,
|
|
@@ -61,13 +64,13 @@ var AccessorCache = function () {
|
|
|
61
64
|
_createClass(AccessorCache, [{
|
|
62
65
|
key: "get",
|
|
63
66
|
value:
|
|
64
|
-
/**
|
|
65
67
|
* Gets state slice from the cache matching the `propertyPaths`.\
|
|
66
68
|
* If not found, creates a new entry for the client from source, and returns it.
|
|
67
69
|
*
|
|
68
70
|
* @param {string} clientId
|
|
69
71
|
* @param {...string} propertyPaths
|
|
70
72
|
* @return {Readonly<PartialState<T>>}
|
|
71
73
|
*/
|
|
74
|
+
/**
|
|
72
75
|
* Gets state slice from the cache matching the `propertyPaths`.\
|
|
73
76
|
* If not found, creates a new entry for the client from source, and returns it.
|
|
74
77
|
*
|
|
75
78
|
* @param {string} clientId
|
|
76
79
|
* @param {...string} propertyPaths
|
|
77
80
|
* @return {{[propertyPaths: string]: Readonly<*>}}
|
|
78
81
|
*/
|
|
79
82
|
function get(clientId) {
|
|
80
83
|
for (var _len = arguments.length, propertyPaths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
81
84
|
propertyPaths[_key - 1] = arguments[_key];
|
|
82
85
|
}
|
|
83
|
-
if ((0,
|
|
84
|
-
propertyPaths = [_constants.
|
|
86
|
+
if ((0, _lodash3["default"])(propertyPaths)) {
|
|
87
|
+
propertyPaths = [_constants.FULL_STATE_SELECTOR];
|
|
85
88
|
}
|
|
86
89
|
var cacheKey = JSON.stringify(propertyPaths);
|
|
87
90
|
var accessor = cacheKey in _classPrivateFieldGet(this, _accessors) ? _classPrivateFieldGet(this, _accessors)[cacheKey] : _classPrivateMethodGet(this, _createAccessor, _createAccessor2).call(this, cacheKey, propertyPaths);
|
|
@@ -102,38 +105,33 @@ var AccessorCache = function () {
|
|
|
102
105
|
delete accessors[k];
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
|
-
/**
|
|
108
|
+
/**
|
|
106
109
|
* Observes the origin state bearing ObservableContext store for state changes to update accessors.
|
|
107
110
|
*
|
|
108
111
|
* @type {Listener<T>}
|
|
109
112
|
*/
|
|
110
113
|
}, {
|
|
111
114
|
key: "watchSource",
|
|
112
|
-
value: function watchSource() {
|
|
115
|
+
value: function watchSource(originChanges) {
|
|
113
116
|
var accessors = _classPrivateFieldGet(this, _accessors);
|
|
114
117
|
var atoms = _classPrivateFieldGet(this, _atoms);
|
|
115
|
-
var state = _classPrivateFieldGet(this, _origin);
|
|
116
118
|
var updatedPaths = {};
|
|
117
119
|
for (var path in atoms) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
if (path !== _constants.FULL_STATE_SELECTOR && !(0, _lodash2["default"])(originChanges, path)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
var newAtomVal = _classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path);
|
|
124
|
+
if ((0, _lodash4["default"])(newAtomVal, atoms[path].value)) {
|
|
120
125
|
continue;
|
|
121
126
|
}
|
|
122
127
|
atoms[path].setValue(newAtomVal);
|
|
123
128
|
updatedPaths[path] = true;
|
|
124
129
|
}
|
|
125
|
-
if ((0,
|
|
126
|
-
for (var k in accessors) {
|
|
127
|
-
if (accessors[k].paths[0] === _constants.DEFAULT_STATE_PATH) {
|
|
128
|
-
accessors[k].refreshDue = true;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
130
|
+
if ((0, _lodash3["default"])(updatedPaths)) {
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
133
|
-
for (var
|
|
134
|
-
if (accessors[
|
|
135
|
-
|
|
133
|
+
for (var k in accessors) {
|
|
134
|
+
if (!accessors[k].refreshDue) {
|
|
135
|
+
accessors[k].refreshDue = accessors[k].paths.some(function (p) {
|
|
136
|
+
return p in updatedPaths;
|
|
137
|
+
});
|
|
136
138
|
}
|
|
137
|
-
var accessorPaths = accessors[_k].paths;
|
|
138
|
-
accessors[_k].refreshDue = accessorPaths[0] === _constants.DEFAULT_STATE_PATH || accessorPaths.some(function (p) {
|
|
139
|
-
return p in updatedPaths;
|
|
140
|
-
});
|
|
141
139
|
}
|
|
142
140
|
}
|
|
143
141
|
}]);
|
|
@@ -148,11 +146,9 @@ function _createAccessor2(cacheKey, propertyPaths) {
|
|
|
148
146
|
try {
|
|
149
147
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
150
148
|
var path = _step2.value;
|
|
151
|
-
if (path in atoms) {
|
|
152
|
-
|
|
149
|
+
if (!(path in atoms)) {
|
|
150
|
+
atoms[path] = new _atom["default"](_classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path));
|
|
153
151
|
}
|
|
154
|
-
atoms[path] = new _atom["default"]();
|
|
155
|
-
atoms[path].setValue((0, _lodash["default"])(_classPrivateFieldGet(this, _origin), path));
|
|
156
152
|
}
|
|
157
153
|
} catch (err) {
|
|
158
154
|
_iterator2.e(err);
|
|
@@ -161,5 +157,8 @@ function _createAccessor2(cacheKey, propertyPaths) {
|
|
|
161
157
|
}
|
|
162
158
|
return _classPrivateFieldGet(this, _accessors)[cacheKey];
|
|
163
159
|
}
|
|
160
|
+
function _getOriginAt2(propertyPath) {
|
|
161
|
+
return propertyPath !== _constants.FULL_STATE_SELECTOR ? (0, _lodash["default"])(_classPrivateFieldGet(this, _origin), propertyPath) : _classPrivateFieldGet(this, _origin);
|
|
162
|
+
}
|
|
164
163
|
var _default = AccessorCache;
|
|
165
164
|
exports["default"] = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default Atom;
|
|
2
1
|
[x: string]: any;
|
|
3
2
|
get value(): Readonly<Value>;
|
|
4
3
|
/**
|
|
5
4
|
* @param {number} accessorId
|
|
6
5
|
* @returns {number} Number of connections remaining
|
|
7
6
|
*/
|
|
8
7
|
connect(accessorId: number): number;
|
|
9
8
|
/**
|
|
10
9
|
* @param {number} accessorId
|
|
11
10
|
* @returns {number} Number of connections remaining
|
|
12
11
|
*/
|
|
13
12
|
disconnect(accessorId: number): number;
|
|
14
13
|
/** @param {number} accessorId */
|
|
15
14
|
isConnected(accessorId: number): boolean;
|
|
16
15
|
/** @param {Value|Readonly<Value>} newValue */
|
|
17
16
|
setValue(newValue: Value | Readonly<Value>): void;
|
|
18
17
|
#private;
|
|
18
|
+
export default Atom;
|
|
19
19
|
constructor(value?: any);
|
|
20
20
|
get value(): Readonly<T>;
|
|
21
21
|
/**
|
|
22
22
|
* @param {number} accessorId
|
|
23
23
|
* @returns {number} Number of connections remaining
|
|
24
24
|
*/
|
|
25
25
|
connect(accessorId: number): number;
|
|
26
26
|
/**
|
|
27
27
|
* @param {number} accessorId
|
|
28
28
|
* @returns {number} Number of connections remaining
|
|
29
29
|
*/
|
|
30
30
|
disconnect(accessorId: number): number;
|
|
31
31
|
/** @param {number} accessorId */
|
|
32
32
|
isConnected(accessorId: number): boolean;
|
|
33
33
|
/** @param {T|Readonly<T>} newValue */
|
|
34
34
|
setValue(newValue: T | Readonly<T>): void;
|
|
35
35
|
#private;
|
package/dist/model/atom/index.js
CHANGED
|
@@ -22,10 +22,12 @@ function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.
|
|
|
22
22
|
var _connections = new WeakMap();
|
|
23
23
|
var _value = new WeakMap();
|
|
24
24
|
/** An atom represents an entry for each individual property path of the state still in use by client components */
|
|
25
|
+
/** @template T */
|
|
25
26
|
var Atom = function () {
|
|
26
27
|
/** @type {Set<number>} */
|
|
27
|
-
/** @type {Readonly<
|
|
28
|
+
/** @type {Readonly<T>} */
|
|
28
29
|
function Atom() {
|
|
30
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
29
31
|
_classCallCheck(this, Atom);
|
|
30
32
|
_classPrivateFieldInitSpec(this, _connections, {
|
|
31
33
|
writable: true,
|
|
@@ -36,7 +38,7 @@ var Atom = function () {
|
|
|
36
38
|
value: void 0
|
|
37
39
|
});
|
|
38
40
|
_classPrivateFieldSet(this, _connections, new Set());
|
|
39
|
-
|
|
41
|
+
this.setValue(value);
|
|
40
42
|
}
|
|
41
43
|
_createClass(Atom, [{
|
|
42
44
|
key: "value",
|
|
@@ -63,7 +65,7 @@ var Atom = function () {
|
|
|
63
65
|
value: function isConnected(accessorId) {
|
|
64
66
|
return _classPrivateFieldGet(this, _connections).has(accessorId);
|
|
65
67
|
}
|
|
66
|
-
/** @param {
|
|
68
|
+
/** @param {T|Readonly<T>} newValue */
|
|
67
69
|
}, {
|
|
68
70
|
key: "setValue",
|
|
69
71
|
value: function setValue(newValue) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
declare const _default: any;
|
|
2
1
|
getItem: (key: string) => T;
|
|
3
2
|
removeItem: (key: string) => void;
|
|
4
3
|
setItem: (key: string, data: T) => void;
|
|
5
4
|
getState: NonReactUsageReport;
|
|
6
5
|
resetState: NonReactUsageReport;
|
|
7
6
|
setState: NonReactUsageReport;
|
|
8
7
|
subscribe: NonReactUsageReport;
|
|
9
8
|
resetState?: (state: {
|
|
10
9
|
current: T;
|
|
11
10
|
original: T;
|
|
12
11
|
}) => boolean;
|
|
13
12
|
setState?: (newChanges: PartialState<T>) => boolean;
|
|
14
13
|
[x: string]: any;
|
|
15
14
|
resetState: VoidFunction;
|
|
16
15
|
setState: (changes: PartialState<T>) => void;
|
|
17
16
|
getState: (clientId: string, ...propertyPaths?: string[]) => Readonly<PartialState<T>>;
|
|
18
17
|
subscribe: (listener: Listener<T>) => Unsubscribe;
|
|
19
18
|
unlinkCache: (clientId: string) => void;
|
|
20
19
|
data: PartialState<T>;
|
|
21
20
|
resetState: VoidFunction;
|
|
22
21
|
setState: (changes: PartialState<T>) => void;
|
|
22
|
+
declare const _default: any;
|
|
23
23
|
[selectorKey: string]: Readonly<any>;
|
|
24
24
|
getItem: (key: string) => T;
|
|
25
25
|
removeItem: (key: string) => void;
|
|
26
26
|
setItem: (key: string, data: T) => void;
|
|
27
27
|
getState: NonReactUsageReport;
|
|
28
28
|
resetState: NonReactUsageReport;
|
|
29
29
|
setState: NonReactUsageReport;
|
|
30
30
|
subscribe: NonReactUsageReport;
|
|
31
31
|
resetState?: (state: {
|
|
32
32
|
current: T;
|
|
33
33
|
original: T;
|
|
34
34
|
}) => boolean;
|
|
35
35
|
setState?: (newChanges: PartialState<T>) => boolean;
|
|
36
36
|
[x: string]: any;
|
|
37
37
|
resetState: VoidFunction;
|
|
38
38
|
setState: (changes: PartialState<T>) => void;
|
|
39
39
|
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
40
40
|
[propertyPaths: string]: Readonly<any>;
|
|
41
41
|
};
|
|
42
42
|
subscribe: (listener: Listener<T>) => Unsubscribe;
|
|
43
43
|
unlinkCache: (clientId: string) => void;
|
|
44
44
|
data: Data;
|
|
45
45
|
resetState: VoidFunction;
|
|
46
46
|
setState: (changes: PartialState<T>) => void;
|
package/package.json
CHANGED
|
@@ -1,112 +1,114 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "Stephen Isienyi <stephen.isienyi@webkrafting.com>",
|
|
3
|
-
"bugs": {
|
|
4
|
-
"url": "https://github.com/steveswork/react-observable-context/issues"
|
|
5
|
-
},
|
|
6
|
-
"contributors": [
|
|
7
|
-
"steveswork <stephen.isienyi@webkrafting.com> (https://github.com/steveswork)"
|
|
8
|
-
],
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"lodash.clonedeep": "^4.5.0",
|
|
11
|
-
"lodash.get": "^4.4.2",
|
|
12
|
-
"lodash.
|
|
13
|
-
"lodash.
|
|
14
|
-
"lodash.
|
|
15
|
-
"lodash.
|
|
16
|
-
"lodash.
|
|
17
|
-
"lodash.
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
"@babel/
|
|
24
|
-
"@babel/
|
|
25
|
-
"@babel/
|
|
26
|
-
"@babel/plugin-
|
|
27
|
-
"@babel/
|
|
28
|
-
"@babel/preset-
|
|
29
|
-
"@
|
|
30
|
-
"@testing-library/
|
|
31
|
-
"@testing-library/react
|
|
32
|
-
"@testing-library/
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"babel-
|
|
36
|
-
"
|
|
37
|
-
"eslint
|
|
38
|
-
"eslint-
|
|
39
|
-
"eslint-plugin-
|
|
40
|
-
"eslint-plugin-
|
|
41
|
-
"eslint-plugin-
|
|
42
|
-
"eslint-plugin-
|
|
43
|
-
"eslint-plugin-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"react
|
|
47
|
-
"react-
|
|
48
|
-
"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"dist/
|
|
55
|
-
"dist/
|
|
56
|
-
"dist/
|
|
57
|
-
"dist/
|
|
58
|
-
"dist/
|
|
59
|
-
"dist/
|
|
60
|
-
"dist/
|
|
61
|
-
"dist/
|
|
62
|
-
"dist/
|
|
63
|
-
"dist/
|
|
64
|
-
"dist/
|
|
65
|
-
"dist/
|
|
66
|
-
"dist/
|
|
67
|
-
"dist/
|
|
68
|
-
"dist/
|
|
69
|
-
"dist/
|
|
70
|
-
"dist/
|
|
71
|
-
"dist/
|
|
72
|
-
"dist/
|
|
73
|
-
"dist/
|
|
74
|
-
"dist/
|
|
75
|
-
"dist/
|
|
76
|
-
"index.
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"
|
|
88
|
-
"react-
|
|
89
|
-
"react",
|
|
90
|
-
"
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
1
|
+
{
|
|
2
|
+
"author": "Stephen Isienyi <stephen.isienyi@webkrafting.com>",
|
|
3
|
+
"bugs": {
|
|
4
|
+
"url": "https://github.com/steveswork/react-observable-context/issues"
|
|
5
|
+
},
|
|
6
|
+
"contributors": [
|
|
7
|
+
"steveswork <stephen.isienyi@webkrafting.com> (https://github.com/steveswork)"
|
|
8
|
+
],
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"lodash.clonedeep": "^4.5.0",
|
|
11
|
+
"lodash.get": "^4.4.2",
|
|
12
|
+
"lodash.has": "^4.5.2",
|
|
13
|
+
"lodash.isempty": "^4.4.0",
|
|
14
|
+
"lodash.isequal": "^4.5.0",
|
|
15
|
+
"lodash.isplainobject": "^4.0.6",
|
|
16
|
+
"lodash.omit": "^4.5.0",
|
|
17
|
+
"lodash.pick": "^4.4.0",
|
|
18
|
+
"lodash.set": "^4.3.2",
|
|
19
|
+
"uuid": "^9.0.0"
|
|
20
|
+
},
|
|
21
|
+
"description": "Observable react context - prevents an automatic total component tree tear-down and re-rendering during context updates.",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@babel/cli": "^7.17.0",
|
|
24
|
+
"@babel/core": "^7.20.5",
|
|
25
|
+
"@babel/node": "^7.12.10",
|
|
26
|
+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
27
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
28
|
+
"@babel/preset-env": "^7.20.2",
|
|
29
|
+
"@babel/preset-react": "^7.18.6",
|
|
30
|
+
"@testing-library/jest-dom": "^5.16.5",
|
|
31
|
+
"@testing-library/react": "^13.4.0",
|
|
32
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
33
|
+
"@testing-library/user-event": "^14.4.3",
|
|
34
|
+
"@types/jest-cli": "^24.3.0",
|
|
35
|
+
"babel-jest": "^26.6.3",
|
|
36
|
+
"babel-loader": "^8.2.5",
|
|
37
|
+
"eslint": "^8.29.0",
|
|
38
|
+
"eslint-config-standard": "^16.0.2",
|
|
39
|
+
"eslint-plugin-import": "^2.22.1",
|
|
40
|
+
"eslint-plugin-jest": "^26.0.0",
|
|
41
|
+
"eslint-plugin-node": "^11.1.0",
|
|
42
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
43
|
+
"eslint-plugin-react": "^7.31.11",
|
|
44
|
+
"eslint-plugin-standard": "^5.0.0",
|
|
45
|
+
"jest-cli": "^26.6.3",
|
|
46
|
+
"react": "^18.2.0",
|
|
47
|
+
"react-dom": "^18.2.0",
|
|
48
|
+
"react-performance-testing": "^2.0.0",
|
|
49
|
+
"typescript": "^4.8.2"
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"package.json",
|
|
53
|
+
"index.js",
|
|
54
|
+
"dist/utils/index.js",
|
|
55
|
+
"dist/utils/index.d.ts",
|
|
56
|
+
"dist/types.d.ts",
|
|
57
|
+
"dist/model/storage/index.js",
|
|
58
|
+
"dist/model/storage/index.d.ts",
|
|
59
|
+
"dist/model/atom/index.js",
|
|
60
|
+
"dist/model/atom/index.d.ts",
|
|
61
|
+
"dist/model/accessor-cache/index.js",
|
|
62
|
+
"dist/model/accessor-cache/index.d.ts",
|
|
63
|
+
"dist/model/accessor/index.js",
|
|
64
|
+
"dist/model/accessor/index.d.ts",
|
|
65
|
+
"dist/main/set-state/index.js",
|
|
66
|
+
"dist/main/set-state/index.d.ts",
|
|
67
|
+
"dist/main/index.js",
|
|
68
|
+
"dist/main/index.d.ts",
|
|
69
|
+
"dist/main/hooks/use-store/index.js",
|
|
70
|
+
"dist/main/hooks/use-store/index.d.ts",
|
|
71
|
+
"dist/main/hooks/use-state-manager/index.js",
|
|
72
|
+
"dist/main/hooks/use-state-manager/index.d.ts",
|
|
73
|
+
"dist/main/hooks/use-render-key-provider/index.js",
|
|
74
|
+
"dist/main/hooks/use-render-key-provider/index.d.ts",
|
|
75
|
+
"dist/main/hooks/use-prehooks-ref/index.js",
|
|
76
|
+
"dist/main/hooks/use-prehooks-ref/index.d.ts",
|
|
77
|
+
"dist/constants.js",
|
|
78
|
+
"dist/constants.d.ts"
|
|
79
|
+
],
|
|
80
|
+
"homepage": "https://github.com/steveswork/react-observable-context#readme",
|
|
81
|
+
"jest": {
|
|
82
|
+
"transform": {
|
|
83
|
+
"\\.[jt]sx?$": "babel-jest"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"keywords": [
|
|
87
|
+
"context",
|
|
88
|
+
"react-hooks",
|
|
89
|
+
"react-context",
|
|
90
|
+
"react",
|
|
91
|
+
"useContext"
|
|
92
|
+
],
|
|
93
|
+
"license": "MIT",
|
|
94
|
+
"main": "index.js",
|
|
95
|
+
"name": "@webkrafters/react-observable-context",
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@types/react": ">= 16.8.0",
|
|
98
|
+
"react": ">= 16.8.0"
|
|
99
|
+
},
|
|
100
|
+
"publishConfig": {
|
|
101
|
+
"access": "public"
|
|
102
|
+
},
|
|
103
|
+
"repository": {
|
|
104
|
+
"type": "git",
|
|
105
|
+
"url": "git+https://github.com/steveswork/react-observable-context.git"
|
|
106
|
+
},
|
|
107
|
+
"scripts": {
|
|
108
|
+
"build": "eslint --fix && rm -rf dist && babel src -d dist && npx -p typescript tsc && node ./post-builder",
|
|
109
|
+
"test": "eslint --fix && jest --updateSnapshot",
|
|
110
|
+
"test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
|
|
111
|
+
},
|
|
112
|
+
"types": "dist/main/index.d.ts",
|
|
113
|
+
"version": "4.0.0-alpha.2"
|
|
114
|
+
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
exports["default"] = exports.NULL_STATE_SELECTOR = exports.FULL_STATE_SELECTOR = void 0;
|
|
6
|
-
var _react = require("react");
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash.isempty"));
|
|
8
|
-
var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
10
|
-
var FULL_STATE_SELECTOR = '@@STATE';
|
|
11
|
-
exports.FULL_STATE_SELECTOR = FULL_STATE_SELECTOR;
|
|
12
|
-
var NULL_STATE_SELECTOR = '';
|
|
13
|
-
exports.NULL_STATE_SELECTOR = NULL_STATE_SELECTOR;
|
|
14
|
-
/**
|
|
15
|
* @param {string[]} renderKeys
|
|
16
1
|
* @returns {string[]}
|
|
17
2
|
*/
|
|
18
|
-
var useRenderKeysManager = function useRenderKeysManager(renderKeys) {
|
|
19
|
-
var curKeys = (0, _react.useRef)([]);
|
|
20
|
-
var managedKeys = (0, _react.useMemo)(function () {
|
|
21
|
-
if (!(0, _lodash2["default"])(curKeys.current, renderKeys)) {
|
|
22
|
-
curKeys.current = renderKeys;
|
|
23
|
-
}
|
|
24
|
-
return curKeys.current;
|
|
25
|
-
}, [renderKeys]);
|
|
26
|
-
return (0, _react.useMemo)(function () {
|
|
27
|
-
var selectors = Array.isArray(managedKeys) ? Array.from(new Set(managedKeys)) : [];
|
|
28
|
-
if ((0, _lodash["default"])(selectors)) {
|
|
29
|
-
selectors[0] = NULL_STATE_SELECTOR;
|
|
30
|
-
} else if (managedKeys.includes(FULL_STATE_SELECTOR)) {
|
|
31
|
-
selectors.length = 0;
|
|
32
|
-
}
|
|
33
|
-
return selectors;
|
|
34
|
-
}, [managedKeys]);
|
|
35
|
-
};
|
|
36
|
-
var _default = useRenderKeysManager;
|
|
37
|
-
exports["default"] = _default;
|