@webkrafters/react-observable-context 4.0.0-alpha.0 → 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.
@@ -1 +1 @@
1
- /** @type {null} */
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.DEFAULT_STATE_PATH = void 0;
6
- /** @type {null} */
7
- var DEFAULT_STATE_PATH = null;
8
- exports.DEFAULT_STATE_PATH = DEFAULT_STATE_PATH;
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 @@
1
+ export default useRenderKeyProvider;
2
  [selectorKey: string]: string | keyof T;
1
3
  * @type {Provider<T>}
2
4
  * @template {State} T
3
5
  */
@@ -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(state) {
56
+ var onChange = function onChange(changes) {
57
57
  return listeners.forEach(function (listener) {
58
- return listener(state);
58
+ return listener(changes);
59
59
  });
60
60
  };
61
61
  /** @type {StoreInternal<T>["resetState"]} */
@@ -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>;
@@ -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.isequal"));
8
- var _lodash2 = _interopRequireDefault(require("lodash.omit"));
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 _useRenderKeysManager = _interopRequireDefault(require("./hooks/use-render-keys-manager"));
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, _lodash["default"])((0, _lodash2["default"])(nodeRef.current, '_owner'), (0, _lodash2["default"])(node, '_owner'))) {
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, _lodash2["default"])(child.props, 'children'), memoizeImmediateChildTree(child.props.children));
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 renderKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
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, _useRenderKeysManager["default"])(renderKeys);
145
- /** @returns {Readonly<PartialState<T>>} */
146
- var getState = function getState() {
147
- return _getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
148
- };
149
- var _useState3 = (0, _react.useState)(getState),
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
- (0, _react.useMemo)(function () {
154
- return setData(getState());
155
- }, [_renderKeys]);
156
- (0, _react.useEffect)(function () {
157
- return subscribe(function () {
158
- return setData(getState());
159
- });
160
- }, [_renderKeys]);
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
- return unlinkCache(clientId);
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(state));
100
+ stats.hasChanges && (onStateChange === null || onStateChange === void 0 ? void 0 : onStateChange(newState));
101
101
  }
102
102
  ;
103
103
  var _default = setState;
@@ -0,0 +1 @@
1
+ export default Accessor;
2
  static "__#5@#NUM_INSTANCES": number;
1
3
  /**
2
4
  * @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
3
5
  * @param {Array<string>} accessedPropertyPaths
4
6
  */
5
7
  constructor(source: T, accessedPropertyPaths: Array<string>);
6
8
  /** @type {boolean} */
7
9
  refreshDue: boolean;
8
10
  get numClients(): number;
9
11
  get id(): number;
10
12
  get paths(): string[];
11
13
  get value(): {
12
14
  [propertyPath: string]: Readonly<any>;
13
15
  };
14
16
  /** @param {string} clientId */
15
17
  addClient(clientId: string): void;
16
18
  hasClient(clientId: string): boolean;
17
19
  removeClient(clientId: string): boolean;
18
20
  /**
19
21
  * @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
20
22
  * @returns {{[propertyPath: string]: Readonly<*>}}
21
23
  */
22
24
  refreshValue(atoms: {
23
25
  [propertyPath: string]: import("../atom").default<any>;
24
26
  }): {
25
27
  [propertyPath: string]: Readonly<any>;
26
28
  };
27
29
  #private;
@@ -0,0 +1,143 @@
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
+ 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; }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
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); }
15
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
16
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
17
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
18
+ function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
19
+ function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { _classCheckPrivateStaticAccess(receiver, classConstructor); _classCheckPrivateStaticFieldDescriptor(descriptor, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
20
+ function _classCheckPrivateStaticFieldDescriptor(descriptor, action) { if (descriptor === undefined) { throw new TypeError("attempted to " + action + " private static field before its declaration"); } }
21
+ function _classCheckPrivateStaticAccess(receiver, classConstructor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } }
22
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
23
+ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
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); }
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; } }
26
+ var _clients = new WeakMap();
27
+ var _id = new WeakMap();
28
+ var _paths = new WeakMap();
29
+ var _source = new WeakMap();
30
+ var _value = new WeakMap();
31
+ /** @template {State} T */
32
+ var Accessor = function () {
33
+ /** @type {Set<string>} */
34
+ /** @type {number} */
35
+ /** @type {Array<string>} */
36
+ /** @type {T} */
37
+ /** @type {{[propertyPath: string]: Readonly<*>}} */
38
+ /**
39
  * @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
1
40
  * @param {Array<string>} accessedPropertyPaths
2
41
  */
42
+ function Accessor(source, accessedPropertyPaths) {
43
+ var _Accessor$NUM_INSTANC, _Accessor$NUM_INSTANC2;
44
+ _classCallCheck(this, Accessor);
45
+ _classPrivateFieldInitSpec(this, _clients, {
46
+ writable: true,
47
+ value: void 0
48
+ });
49
+ _classPrivateFieldInitSpec(this, _id, {
50
+ writable: true,
51
+ value: void 0
52
+ });
53
+ _classPrivateFieldInitSpec(this, _paths, {
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ _classPrivateFieldInitSpec(this, _source, {
58
+ writable: true,
59
+ value: void 0
60
+ });
61
+ _classPrivateFieldInitSpec(this, _value, {
62
+ writable: true,
63
+ value: void 0
64
+ });
65
+ _classPrivateFieldSet(this, _clients, new Set());
66
+ _classPrivateFieldSet(this, _id, _classStaticPrivateFieldSpecSet(Accessor, Accessor, _NUM_INSTANCES, (_Accessor$NUM_INSTANC2 = _classStaticPrivateFieldSpecGet(Accessor, Accessor, _NUM_INSTANCES), ++_Accessor$NUM_INSTANC2)));
67
+ _classPrivateFieldSet(this, _paths, Array.from(new Set(accessedPropertyPaths)));
68
+ /** @type {boolean} */
69
+ this.refreshDue = true;
70
+ _classPrivateFieldSet(this, _source, source);
71
+ _classPrivateFieldSet(this, _value, {});
72
+ }
73
+ _createClass(Accessor, [{
74
+ key: "numClients",
75
+ get: function get() {
76
+ return _classPrivateFieldGet(this, _clients).size;
77
+ }
78
+ }, {
79
+ key: "id",
80
+ get: function get() {
81
+ return _classPrivateFieldGet(this, _id);
82
+ }
83
+ }, {
84
+ key: "paths",
85
+ get: function get() {
86
+ return _classPrivateFieldGet(this, _paths);
87
+ }
88
+ }, {
89
+ key: "value",
90
+ get: function get() {
91
+ return _classPrivateFieldGet(this, _value);
92
+ }
93
+ /** @param {string} clientId */
94
+ }, {
95
+ key: "addClient",
96
+ value: function addClient(clientId) {
97
+ _classPrivateFieldGet(this, _clients).add(clientId);
98
+ }
99
+ /** @type {(clientId: string) => boolean} */
100
+ }, {
101
+ key: "hasClient",
102
+ value: function hasClient(clientId) {
103
+ return _classPrivateFieldGet(this, _clients).has(clientId);
104
+ }
105
+ /** @type {(clientId: string) => boolean} */
106
+ }, {
107
+ key: "removeClient",
108
+ value: function removeClient(clientId) {
109
+ return _classPrivateFieldGet(this, _clients)["delete"](clientId);
110
+ }
111
+ /**
3
112
  * @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
4
113
  * @returns {{[propertyPath: string]: Readonly<*>}}
5
114
  */
115
+ }, {
116
+ key: "refreshValue",
117
+ value: function refreshValue(atoms) {
118
+ if (!this.refreshDue) {
119
+ return _classPrivateFieldGet(this, _value);
120
+ }
121
+ this.refreshDue = false;
122
+ var _iterator = _createForOfIteratorHelper(_classPrivateFieldGet(this, _paths)),
123
+ _step;
124
+ try {
125
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
126
+ var p = _step.value;
127
+ if (!(p in atoms)) {
128
+ continue;
129
+ }
130
+ var atom = atoms[p];
131
+ !atom.isConnected(_classPrivateFieldGet(this, _id)) && atom.connect(_classPrivateFieldGet(this, _id));
132
+ _classPrivateFieldGet(this, _value)[p] = atom.value;
133
+ }
134
+ } catch (err) {
135
+ _iterator.e(err);
136
+ } finally {
137
+ _iterator.f();
138
+ }
139
+ return _classPrivateFieldGet(this, _value);
140
+ }
141
+ }]);
142
+ return Accessor;
143
+ }();
144
+ var _NUM_INSTANCES = {
145
+ writable: true,
146
+ value: 0
147
+ };
148
+ var _default = Accessor;
149
+ exports["default"] = _default;
@@ -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.isempty"));
9
- var _lodash3 = _interopRequireDefault(require("lodash.isequal"));
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, _lodash2["default"])(propertyPaths)) {
84
- propertyPaths = [_constants.DEFAULT_STATE_PATH];
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
- /** Observes the origin state bearing ObservableContext store for state changes to update accessors. */
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
- var newAtomVal = (0, _lodash["default"])(state, path);
119
- if ((0, _lodash3["default"])(newAtomVal, atoms[path].value)) {
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, _lodash2["default"])(updatedPaths)) {
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 _k in accessors) {
134
- if (accessors[_k].refreshDue) {
135
- continue;
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
- continue;
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;
@@ -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<Value>} */
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
- _classPrivateFieldSet(this, _value, (0, _utils.makeReadonly)({}));
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 {Value|Readonly<Value>} newValue */
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.isempty": "^4.4.0",
13
- "lodash.isequal": "^4.5.0",
14
- "lodash.isplainobject": "^4.0.6",
15
- "lodash.omit": "^4.5.0",
16
- "lodash.pick": "^4.4.0",
17
- "lodash.set": "^4.3.2",
18
- "uuid": "^9.0.0"
19
- },
20
- "description": "Observable react context - prevents an automatic total component tree tear-down and re-rendering during context updates.",
21
- "devDependencies": {
22
- "@babel/cli": "^7.17.0",
23
- "@babel/core": "^7.20.5",
24
- "@babel/node": "^7.12.10",
25
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
26
- "@babel/plugin-transform-runtime": "^7.17.0",
27
- "@babel/preset-env": "^7.20.2",
28
- "@babel/preset-react": "^7.18.6",
29
- "@testing-library/jest-dom": "^5.16.5",
30
- "@testing-library/react": "^13.4.0",
31
- "@testing-library/react-hooks": "^8.0.1",
32
- "@testing-library/user-event": "^14.4.3",
33
- "@types/jest-cli": "^24.3.0",
34
- "babel-jest": "^26.6.3",
35
- "babel-loader": "^8.2.5",
36
- "eslint": "^8.29.0",
37
- "eslint-config-standard": "^16.0.2",
38
- "eslint-plugin-import": "^2.22.1",
39
- "eslint-plugin-jest": "^26.0.0",
40
- "eslint-plugin-node": "^11.1.0",
41
- "eslint-plugin-promise": "^4.2.1",
42
- "eslint-plugin-react": "^7.31.11",
43
- "eslint-plugin-standard": "^5.0.0",
44
- "jest-cli": "^26.6.3",
45
- "react": "^18.2.0",
46
- "react-dom": "^18.2.0",
47
- "react-performance-testing": "^2.0.0",
48
- "typescript": "^4.8.2"
49
- },
50
- "files": [
51
- "dist/constants.js",
52
- "dist/constants.d.ts",
53
- "dist/main/index.js",
54
- "dist/main/index.d.ts",
55
- "dist/main/set-state/index.js",
56
- "dist/main/set-state/index.d.ts",
57
- "dist/main/hooks/use-prehooks-ref/index.js",
58
- "dist/main/hooks/use-prehooks-ref/index.d.ts",
59
- "dist/main/hooks/use-render-keys-manager/index.js",
60
- "dist/main/hooks/use-render-keys-manager/index.d.ts",
61
- "dist/main/hooks/use-state-manager/index.js",
62
- "dist/main/hooks/use-state-manager/index.d.ts",
63
- "dist/main/hooks/use-store/index.js",
64
- "dist/main/hooks/use-store/index.d.ts",
65
- "dist/model/accesor/index.js",
66
- "dist/model/accesor/index.d.ts",
67
- "dist/model/accessor-cache/index.js",
68
- "dist/model/accessor-cache/index.d.ts",
69
- "dist/model/atom/index.js",
70
- "dist/model/atom/index.d.ts",
71
- "dist/model/storage/index.js",
72
- "dist/model/storage/index.d.ts",
73
- "dist/utils/index.js",
74
- "dist/utils/index.d.ts",
75
- "dist/types.d.ts",
76
- "index.js",
77
- "package.json"
78
- ],
79
- "homepage": "https://github.com/steveswork/react-observable-context#readme",
80
- "jest": {
81
- "transform": {
82
- "\\.[jt]sx?$": "babel-jest"
83
- }
84
- },
85
- "keywords": [
86
- "context",
87
- "react-hooks",
88
- "react-context",
89
- "react",
90
- "useContext"
91
- ],
92
- "license": "MIT",
93
- "main": "index.js",
94
- "name": "@webkrafters/react-observable-context",
95
- "peerDependencies": {
96
- "react": ">= 16.8.0"
97
- },
98
- "publishConfig": {
99
- "access": "public"
100
- },
101
- "repository": {
102
- "type": "git",
103
- "url": "git+https://github.com/steveswork/react-observable-context.git"
104
- },
105
- "scripts": {
106
- "build": "eslint --fix && rm -rf dist && babel src -d dist && npx -p typescript tsc && node ./trim-comments",
107
- "test": "eslint --fix && jest --updateSnapshot",
108
- "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
109
- },
110
- "types": "dist/main/index.d.ts",
111
- "version": "4.0.0-alpha.0"
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 +0,0 @@
1
- export const FULL_STATE_SELECTOR: "@@STATE";
2
  * @param {string[]} renderKeys
3
1
  * @returns {string[]}
4
2
  */
@@ -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;