@webkrafters/react-observable-context 4.4.2 → 4.4.4

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/README.md CHANGED
@@ -342,6 +342,7 @@ Routinely, the `value` prop is initialized with the full initial state. It may o
342
342
 
343
343
  <h2 id="selector-map">Selector Map</h2>
344
344
  A selector map is an object holding key:value pairs.<br />
345
+ <i><b>An array of <a href="#property-path">property paths</a> is also acceptable:</b> indexes serve as keys for this purpose.</i><br />
345
346
  <span style="margin-right: 10px">-</span><code>key</code> refers to an arbitrary name to be assigned to a given property in the <a href="#store"><code>store.data</code></a>.<br />
346
347
  <span style="margin-right: 10px">-</span><code>value</code> refers to the <a href="#property-path">property path</a> leading to a state slice whose value will be assigned to and observed by this <a href="#store"><code>store.data</code></a> property.<br />
347
348
  <span style="margin-right: 10px">-</span>A special '<a href="#fullstate-selectorkey">@@STATE</a>' value may be used to access and observe the full state object.<br />
@@ -361,7 +362,9 @@ const state = {
361
362
  }
362
363
  };
363
364
 
364
- // a client observing the following selector map
365
+ /* --------------------------------------------- */
366
+ /* a client observing the following selector map */
367
+ /* --------------------------------------------- */
365
368
  const selectorMap = {
366
369
  all: '@@STATE',
367
370
  myData: 'd',
@@ -373,7 +376,20 @@ store.data = {
373
376
  all: state,
374
377
  myData: state.d,
375
378
  secondFElement: state.d.f[1]
376
- }
379
+ };
380
+
381
+ /* --------------------------------------------------- */
382
+ /* a client observing the following property path list */
383
+ /* --------------------------------------------------- */
384
+ const propertyPaths = [ '@@STATE', 'd', 'd.f[1]' ];
385
+
386
+ // will receive the following store data
387
+ store.data = {
388
+ 0: state,
389
+ 1: state.d,
390
+ 2: state.d.f[1]
391
+ };
392
+
377
393
  ```
378
394
 
379
395
  ## Storage
@@ -1,6 +1,6 @@
1
1
  export default useRenderKeyProvider;
2
- export type Provider<T extends import("../../../types").State> = (selectorMap: {
3
- [selectorKey: string]: string | keyof T;
4
- }) => [string | keyof T];
2
+ export type Provider<T extends import("../../../types").State, MAP extends BaseSelectorMap<T> = BaseSelectorMap<T>> = (selectorMap: SelectorMap<T, MAP>) => [string | keyof T];
3
+ export type SelectorMap<STATE extends import("../../../types").State = import("../../../types").State, MAP extends BaseSelectorMap<STATE> = BaseSelectorMap<STATE>> = import("../../../types").SelectorMap<STATE>;
4
+ export type BaseSelectorMap<STATE extends import("../../../types").State = import("../../../types").State> = import("../../../types").BaseSelectorMap<STATE>;
5
5
  export type State = import("../../../types").State;
6
- declare const useRenderKeyProvider: Provider<T>;
6
+ declare const useRenderKeyProvider: Provider<T, BaseSelectorMap<T>>;
@@ -18,6 +18,10 @@ export function createContext<T extends import("../types").State>(): ObservableC
18
18
  * a valid property path follows the `lodash` object property path convention.
19
19
  * for a state = { a: 1, b: 2, c: 3, d: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] } }
20
20
  * Any of the following is an applicable selector map.
21
+ * ['d', 'a'] => {
22
+ * 0: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] },
23
+ * 1: 1
24
+ * }
21
25
  * {myData: 'd', count: 'a'} => {
22
26
  * myData: { e: 5, f: [6, { x: 7, y: 8, z: 9 } ] },
23
27
  * count: 1
@@ -17,6 +17,17 @@ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) {
17
17
  function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
18
18
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
19
19
  function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
20
+ var isFunction = function () {
21
+ var toString = Function.prototype.toString;
22
+ var is = function is(v) {
23
+ try {
24
+ return toString.call(v);
25
+ } catch (e) {
26
+ return false;
27
+ }
28
+ };
29
+ return is;
30
+ }();
20
31
  var _connections = new WeakMap();
21
32
  var _value = new WeakMap();
22
33
  var Atom = function () {
@@ -59,7 +70,7 @@ var Atom = function () {
59
70
  }, {
60
71
  key: "setValue",
61
72
  value: function setValue(newValue) {
62
- _classPrivateFieldSet(this, _value, (0, _utils.makeReadonly)((0, _utils.clonedeep)(newValue)));
73
+ _classPrivateFieldSet(this, _value, !isFunction(newValue) ? (0, _utils.makeReadonly)((0, _utils.clonedeep)(newValue)) : newValue);
63
74
  }
64
75
  }]);
65
76
  return Atom;
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  declare const _default: any;
2
2
  export default _default;
3
- export type BaseSelectorMap<T extends State> = {
3
+ export type BaseSelectorMap<T extends State> = (string | keyof T)[] | ({
4
4
  [dataPropKey: string]: string | keyof T;
5
5
  } & {
6
6
  [dataPropKey: string]: "@@STATE";
7
- };
7
+ });
8
8
  export type BaseType = boolean | any[] | {
9
9
  [x: string]: any;
10
10
  } | KeyType;
package/package.json CHANGED
@@ -133,5 +133,5 @@
133
133
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
134
134
  },
135
135
  "types": "dist/main/index.d.ts",
136
- "version": "4.4.2"
136
+ "version": "4.4.4"
137
137
  }