@webkrafters/react-observable-context 4.0.0-alpha.3 → 4.0.0-alpha.5s

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
- 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 {Array<string>} */
9
8
  outdatedPaths: Array<string>;
10
9
  get numClients(): number;
11
10
  get id(): number;
12
11
  get paths(): string[];
13
12
  get value(): {
14
13
  [propertyPath: string]: Readonly<any>;
15
14
  };
16
15
  /** @param {string} clientId */
17
16
  addClient(clientId: string): void;
18
17
  hasClient(clientId: string): boolean;
19
18
  removeClient(clientId: string): boolean;
20
19
  /**
21
20
  * @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
22
21
  * @returns {{[propertyPath: string]: Readonly<*>}}
23
22
  */
24
23
  refreshValue(atoms: {
25
24
  [propertyPath: string]: import("../atom").default<any>;
26
25
  }): {
27
26
  [propertyPath: string]: Readonly<any>;
28
27
  };
29
28
  #private;
29
+ export default Accessor;
30
30
  static "__#5@#NUM_INSTANCES": number;
31
31
  constructor(source: T, accessedPropertyPaths: Array<string>);
32
32
  outdatedPaths: Array<string>;
33
33
  get numClients(): number;
34
34
  get id(): number;
35
35
  get paths(): string[];
36
36
  get value(): {
37
37
  [propertyPath: string]: Readonly<any>;
38
38
  };
39
39
  addClient(clientId: string): void;
40
40
  hasClient(clientId: string): boolean;
41
41
  removeClient(clientId: string): boolean;
42
42
  refreshValue(atoms: {
43
43
  [propertyPath: string]: import("../atom").default<any>;
44
44
  }): {
45
45
  [propertyPath: string]: Readonly<any>;
46
46
  };
47
47
  #private;
@@ -26,7 +26,6 @@ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _
26
26
  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
27
  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
28
  var MODERATE_NUM_PATHS_THRESHOLD = 8;
29
- /** @template {State} T */
30
29
  var _clients = new WeakMap();
31
30
  var _id = new WeakMap();
32
31
  var _paths = new WeakMap();
@@ -34,12 +33,6 @@ var _source = new WeakMap();
34
33
  var _value = new WeakMap();
35
34
  var _setValueAt = new WeakSet();
36
35
  var Accessor = function () {
37
- /** @type {Set<string>} */
38
- /** @type {number} */
39
- /** @type {Array<string>} */
40
- /** @type {T} */
41
- /** @type {{[propertyPath: string]: Readonly<*>}} */
42
- /**
43
36
  * @param {T} source State object reference from which the accessedPropertyPaths are to be selected.
44
37
  * @param {Array<string>} accessedPropertyPaths
45
38
  */
46
39
  function Accessor(source, accessedPropertyPaths) {
47
40
  var _Accessor$NUM_INSTANC, _Accessor$NUM_INSTANC2;
48
41
  _classCallCheck(this, Accessor);
@@ -67,7 +60,6 @@ var Accessor = function () {
67
60
  _classPrivateFieldSet(this, _clients, new Set());
68
61
  _classPrivateFieldSet(this, _id, _classStaticPrivateFieldSpecSet(Accessor, Accessor, _NUM_INSTANCES, (_Accessor$NUM_INSTANC2 = _classStaticPrivateFieldSpecGet(Accessor, Accessor, _NUM_INSTANCES), ++_Accessor$NUM_INSTANC2)));
69
62
  _classPrivateFieldSet(this, _paths, Array.from(new Set(accessedPropertyPaths)));
70
- /** @type {Array<string>} */
71
63
  this.outdatedPaths = _classPrivateFieldGet(this, _paths).slice();
72
64
  _classPrivateFieldSet(this, _source, source);
73
65
  _classPrivateFieldSet(this, _value, {});
@@ -92,26 +84,22 @@ var Accessor = function () {
92
84
  get: function get() {
93
85
  return _classPrivateFieldGet(this, _value);
94
86
  }
95
- /**
96
87
  * @param {string} propertyPath
97
88
  * @param {Atom<V>} atom
98
89
  * @template V
99
90
  */
100
91
  }, {
101
92
  key: "addClient",
102
- value: /** @param {string} clientId */
93
+ value:
103
94
  function addClient(clientId) {
104
95
  _classPrivateFieldGet(this, _clients).add(clientId);
105
96
  }
106
- /** @type {(clientId: string) => boolean} */
107
97
  }, {
108
98
  key: "hasClient",
109
99
  value: function hasClient(clientId) {
110
100
  return _classPrivateFieldGet(this, _clients).has(clientId);
111
101
  }
112
- /** @type {(clientId: string) => boolean} */
113
102
  }, {
114
103
  key: "removeClient",
115
104
  value: function removeClient(clientId) {
116
105
  return _classPrivateFieldGet(this, _clients)["delete"](clientId);
117
106
  }
118
- /**
119
107
  * @param {{[propertyPath: string]: Atom<*>}} atoms Curated slices of state currently requested
120
108
  * @returns {{[propertyPath: string]: Readonly<*>}}
121
109
  */
122
110
  }, {
123
111
  key: "refreshValue",
124
112
  value: function refreshValue(atoms) {
@@ -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 {{[propertyPaths: string]: Readonly<*>}}
11
10
  */
12
11
  get(clientId: string, ...propertyPaths: string[]): {
13
12
  [propertyPaths: string]: Readonly<any>;
14
13
  };
15
14
  /**
16
15
  * Unlinks a consumer from the cache: performing synchronized state cleanup
17
16
  *
18
17
  * @param {string} clientId
19
18
  */
20
19
  unlinkClient(clientId: string): void;
21
20
  watchSource(changes: import("../../types").PartialState<T>): void;
22
21
  #private;
22
+ export default AccessorCache;
23
23
  constructor(origin: T);
24
24
  get(clientId: string, ...propertyPaths: string[]): {
25
25
  [propertyPaths: string]: Readonly<any>;
26
26
  };
27
27
  unlinkClient(clientId: string): void;
28
28
  watchSource(changes: import("../../types").PartialState<T>): void;
29
29
  #private;
@@ -34,12 +34,7 @@ var _atoms = new WeakMap();
34
34
  var _origin = new WeakMap();
35
35
  var _createAccessor = new WeakSet();
36
36
  var _getOriginAt = new WeakSet();
37
- /** @template {State} T */
38
37
  var AccessorCache = function () {
39
- /** @type {{[propertyPaths: string]: Accessor<T>}} */
40
- /** @type {{[propertyPath: string]: Atom<*>}} */
41
- /** @type {T} */
42
- /** @param {T} origin State object reference from which slices stored in this cache are to be curated */
43
38
  function AccessorCache(origin) {
44
39
  _classCallCheck(this, AccessorCache);
45
40
  _classPrivateMethodInitSpec(this, _getOriginAt);
@@ -60,11 +55,9 @@ var AccessorCache = function () {
60
55
  _classPrivateFieldSet(this, _atoms, {});
61
56
  _classPrivateFieldSet(this, _origin, origin);
62
57
  }
63
- /**
64
58
  * Add new cache entry
65
59
  *
66
60
  * @param {string} cacheKey
67
61
  * @param {Array<string>} propertyPaths
68
62
  * @return {Accessor<T>}
69
63
  */
70
64
  _createClass(AccessorCache, [{
71
65
  key: "get",
72
66
  value:
73
- /**
74
67
  * Gets state slice from the cache matching the `propertyPaths`.\
75
68
  * If not found, creates a new entry for the client from source, and returns it.
76
69
  *
77
70
  * @param {string} clientId
78
71
  * @param {...string} propertyPaths
79
72
  * @return {{[propertyPaths: string]: Readonly<*>}}
80
73
  */
81
74
  function get(clientId) {
82
75
  for (var _len = arguments.length, propertyPaths = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
83
76
  propertyPaths[_key - 1] = arguments[_key];
@@ -77,7 +70,6 @@ var AccessorCache = function () {
77
70
  !accessor.hasClient(clientId) && accessor.addClient(clientId);
78
71
  return accessor.refreshValue(_classPrivateFieldGet(this, _atoms));
79
72
  }
80
- /**
81
73
  * Unlinks a consumer from the cache: performing synchronized state cleanup
82
74
  *
83
75
  * @param {string} clientId
84
76
  */
85
77
  }, {
86
78
  key: "unlinkClient",
87
79
  value: function unlinkClient(clientId) {
@@ -105,7 +97,6 @@ var AccessorCache = function () {
105
97
  delete accessors[k];
106
98
  }
107
99
  }
108
- /**
109
100
  * Observes the origin state bearing ObservableContext store for state changes to update accessors.
110
101
  *
111
102
  * @type {Listener<T>}
112
103
  */
113
104
  }, {
114
105
  key: "watchSource",
115
106
  value: function watchSource(originChanges) {
@@ -1 +1 @@
1
- export default Atom;
2
1
  constructor(value?: any);
3
2
  get value(): Readonly<T>;
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 {T|Readonly<T>} newValue */
17
16
  setValue(newValue: T | Readonly<T>): void;
18
17
  #private;
18
+ export default Atom;
19
19
  constructor(value?: any);
20
20
  get value(): Readonly<T>;
21
21
  connect(accessorId: number): number;
22
22
  disconnect(accessorId: number): number;
23
23
  isConnected(accessorId: number): boolean;
24
24
  setValue(newValue: T | Readonly<T>): void;
25
25
  #private;
@@ -21,11 +21,7 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
21
21
  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; } }
22
22
  var _connections = new WeakMap();
23
23
  var _value = new WeakMap();
24
- /** An atom represents an entry for each individual property path of the state still in use by client components */
25
- /** @template T */
26
24
  var Atom = function () {
27
- /** @type {Set<number>} */
28
- /** @type {Readonly<T>} */
29
25
  function Atom() {
30
26
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
31
27
  _classCallCheck(this, Atom);
@@ -45,27 +41,23 @@ var Atom = function () {
45
41
  get: function get() {
46
42
  return _classPrivateFieldGet(this, _value);
47
43
  }
48
- /**
49
44
  * @param {number} accessorId
50
45
  * @returns {number} Number of connections remaining
51
46
  */
52
47
  }, {
53
48
  key: "connect",
54
49
  value: function connect(accessorId) {
55
50
  _classPrivateFieldGet(this, _connections).add(accessorId);
56
51
  return _classPrivateFieldGet(this, _connections).size;
57
52
  }
58
- /**
59
53
  * @param {number} accessorId
60
54
  * @returns {number} Number of connections remaining
61
55
  */
62
56
  }, {
63
57
  key: "disconnect",
64
58
  value: function disconnect(accessorId) {
65
59
  _classPrivateFieldGet(this, _connections)["delete"](accessorId);
66
60
  return _classPrivateFieldGet(this, _connections).size;
67
61
  }
68
- /** @param {number} accessorId */
69
62
  }, {
70
63
  key: "isConnected",
71
64
  value: function isConnected(accessorId) {
72
65
  return _classPrivateFieldGet(this, _connections).has(accessorId);
73
66
  }
74
- /** @param {T|Readonly<T>} newValue */
75
67
  }, {
76
68
  key: "setValue",
77
69
  value: function setValue(newValue) {
@@ -1 +1 @@
1
- export default Storage;
2
1
  * @extends {IStorage<T>}
3
2
  * @template {State} T
4
3
  */
5
4
  static supportsSession: boolean;
6
5
  get isKeyRequired(): boolean;
7
6
  getItem(key: string): T;
8
7
  removeItem(key: string): void;
9
8
  setItem(key: string, data: T): void;
10
9
  #private;
10
+ export default Storage;
11
11
  static supportsSession: boolean;
12
12
  get isKeyRequired(): boolean;
13
13
  clone(data: T): T;
14
14
  getItem(key: string): T;
15
15
  removeItem(key: string): void;
16
16
  setItem(key: string, data: T): void;
17
17
  #private;
@@ -21,9 +21,7 @@ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _
21
21
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
22
22
  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; } }
23
23
  var _data = new WeakMap();
24
- /**
25
24
  * @class
26
25
  * @template {State} T
27
26
  */
28
27
  var MemoryStorage = function () {
29
- /** @type {T} */
30
28
  function MemoryStorage() {
31
29
  _classCallCheck(this, MemoryStorage);
32
30
  _classPrivateFieldInitSpec(this, _data, {
@@ -32,31 +30,31 @@ var MemoryStorage = function () {
32
30
  });
33
31
  _classPrivateFieldSet(this, _data, null);
34
32
  }
35
- /** @type {IStorage<T>[ "getItem" ]} */
36
33
  _createClass(MemoryStorage, [{
34
+ key: "clone",
35
+ value: function clone(data) {
36
+ return (0, _lodash["default"])(data);
37
+ }
38
+ }, {
37
39
  key: "getItem",
38
40
  value: function getItem(key) {
39
- return (0, _lodash["default"])(_classPrivateFieldGet(this, _data));
41
+ return _classPrivateFieldGet(this, _data);
40
42
  }
41
- /** @type {IStorage<T>[ "removeItem" ]} */
42
43
  }, {
43
44
  key: "removeItem",
44
45
  value: function removeItem(key) {
45
46
  _classPrivateFieldSet(this, _data, null);
46
47
  }
47
- /** @type {IStorage<T>[ "setItem" ]} */
48
48
  }, {
49
49
  key: "setItem",
50
50
  value: function setItem(key, data) {
51
- _classPrivateFieldSet(this, _data, (0, _lodash["default"])(data));
51
+ _classPrivateFieldSet(this, _data, data);
52
52
  }
53
53
  }]);
54
54
  return MemoryStorage;
55
55
  }();
56
- /**
57
56
  * @extends {IStorage<T>}
58
57
  * @template {State} T
59
58
  */
60
59
  var _storage = new WeakMap();
61
60
  var SessionStorage = function () {
62
- /** @type {IStorage<T>} */
63
61
  function SessionStorage() {
64
62
  _classCallCheck(this, SessionStorage);
65
63
  _classPrivateFieldInitSpec(this, _storage, {
@@ -65,19 +63,21 @@ var SessionStorage = function () {
65
63
  });
66
64
  _classPrivateFieldSet(this, _storage, globalThis.sessionStorage);
67
65
  }
68
- /** @type {IStorage<T>[ "getItem" ]} */
69
66
  _createClass(SessionStorage, [{
67
+ key: "clone",
68
+ value: function clone(data) {
69
+ return data;
70
+ }
71
+ }, {
70
72
  key: "getItem",
71
73
  value: function getItem(key) {
72
74
  return JSON.parse(_classPrivateFieldGet(this, _storage).getItem(key));
73
75
  }
74
- /** @type {IStorage<T>[ "removeItem" ]} */
75
76
  }, {
76
77
  key: "removeItem",
77
78
  value: function removeItem(key) {
78
79
  return _classPrivateFieldGet(this, _storage).removeItem(key);
79
80
  }
80
- /** @type {IStorage<T>[ "setItem" ]} */
81
81
  }, {
82
82
  key: "setItem",
83
83
  value: function setItem(key, data) {
@@ -86,10 +86,8 @@ var SessionStorage = function () {
86
86
  }]);
87
87
  return SessionStorage;
88
88
  }();
89
- /**
90
89
  * @extends {IStorage<T>}
91
90
  * @template {State} T
92
91
  */
93
92
  var _storage2 = new WeakMap();
94
93
  var Storage = function () {
95
- /** @type {IStorage<T>} */
96
94
  function Storage() {
97
95
  _classCallCheck(this, Storage);
98
96
  _classPrivateFieldInitSpec(this, _storage2, {
@@ -103,19 +101,21 @@ var Storage = function () {
103
101
  get: function get() {
104
102
  return _classPrivateFieldGet(this, _storage2) instanceof SessionStorage;
105
103
  }
106
- /** @type {IStorage<T>[ "getItem" ]} */
104
+ }, {
105
+ key: "clone",
106
+ value: function clone(data) {
107
+ return _classPrivateFieldGet(this, _storage2).clone(data);
108
+ }
107
109
  }, {
108
110
  key: "getItem",
109
111
  value: function getItem(key) {
110
112
  return _classPrivateFieldGet(this, _storage2).getItem(key);
111
113
  }
112
- /** @type {IStorage<T>[ "removeItem" ]} */
113
114
  }, {
114
115
  key: "removeItem",
115
116
  value: function removeItem(key) {
116
117
  _classPrivateFieldGet(this, _storage2).removeItem(key);
117
118
  }
118
- /** @type {IStorage<T>[ "setItem" ]} */
119
119
  }, {
120
120
  key: "setItem",
121
121
  value: function setItem(key, data) {
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- declare const _default: any;
2
1
  [selectorKey: string]: Readonly<any>;
3
2
  getItem: (key: string) => T;
4
3
  removeItem: (key: string) => void;
5
4
  setItem: (key: string, data: T) => void;
6
5
  getState: NonReactUsageReport;
7
6
  resetState: NonReactUsageReport;
8
7
  setState: NonReactUsageReport;
9
8
  subscribe: NonReactUsageReport;
10
9
  resetState?: (state: {
11
10
  current: T;
12
11
  original: T;
13
12
  }) => boolean;
14
13
  setState?: (newChanges: PartialState<T>) => boolean;
15
14
  [x: string]: any;
16
15
  resetState: VoidFunction;
17
16
  setState: (changes: PartialState<T>) => void;
18
17
  getState: (clientId: string, ...propertyPaths?: string[]) => {
19
18
  [propertyPaths: string]: Readonly<any>;
20
19
  };
21
20
  subscribe: (listener: Listener<T>) => Unsubscribe;
22
21
  unlinkCache: (clientId: string) => void;
23
22
  data: Data;
24
23
  resetState: VoidFunction;
25
24
  setState: (changes: PartialState<T>) => void;
25
+ declare const _default: any;
26
26
  [selectorKey: string]: Readonly<any>;
27
27
  clone: (data: T) => T;
28
28
  getItem: (key: string) => T;
29
29
  removeItem: (key: string) => void;
30
30
  setItem: (key: string, data: T) => void;
31
31
  getState: NonReactUsageReport;
32
32
  resetState: NonReactUsageReport;
33
33
  setState: NonReactUsageReport;
34
34
  subscribe: NonReactUsageReport;
35
35
  resetState?: (resetData: PartialState<T>, state: {
36
36
  current: T;
37
37
  original: T;
38
38
  }) => boolean;
39
39
  setState?: (newChanges: PartialState<T>) => boolean;
40
40
  [x: string]: any;
41
41
  resetState: (propertyPaths?: string[]) => void;
42
42
  setState: (changes: PartialState<T>) => void;
43
43
  getState: (clientId: string, ...propertyPaths?: string[]) => {
44
44
  [propertyPaths: string]: Readonly<any>;
45
45
  };
46
46
  subscribe: (listener: Listener<T>) => Unsubscribe;
47
47
  unlinkCache: (clientId: string) => void;
48
48
  data: Data;
49
49
  resetState: (propertyPaths?: string[]) => void;
50
50
  setState: (changes: PartialState<T>) => void;
@@ -1 +1 @@
1
- export function makeReadonly<T>(v: T): Readonly<T>;
1
+ export function arrangePropertyPaths(propertyPaths: Array<string>): Array<string>;
2
2
  [x: string]: any;
@@ -1,14 +1,80 @@
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
- exports.makeReadonly = void 0;
6
- var _lodash = _interopRequireDefault(require("lodash.isplainobject"));
6
+ exports.arrangePropertyPaths = arrangePropertyPaths;
7
+ exports.makeReadonly = makeReadonly;
8
+ exports.mapPathsToObject = mapPathsToObject;
9
+ exports.none = void 0;
10
+ var _lodash = _interopRequireDefault(require("lodash.get"));
11
+ var _lodash2 = _interopRequireDefault(require("lodash.has"));
12
+ var _lodash3 = _interopRequireDefault(require("lodash.isplainobject"));
13
+ var _lodash4 = _interopRequireDefault(require("lodash.set"));
7
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
- /**
9
15
  * Converts argument to readonly.
10
16
  *
11
17
  * Note: Mutates original argument.
12
18
  *
13
19
  * @param {T} v
14
20
  * @returns {Readonly<T>}
15
21
  * @template T
16
22
  */
17
- var makeReadonly = function makeReadonly(v) {
23
+ 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; } } }; }
24
+ 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); }
25
+ 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; }
26
+ 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); } }
27
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
28
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
29
+ 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); }
30
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
+ var None = _createClass(function None() {
32
+ _classCallCheck(this, None);
33
+ });
34
+ ;
35
+ var none = new None();
36
+ exports.none = none;
37
+ function arrangePropertyPaths(propertyPaths) {
38
+ var superPathTokensMap = {};
39
+ var _iterator = _createForOfIteratorHelper(propertyPaths),
40
+ _step;
41
+ try {
42
+ var _loop = function _loop() {
43
+ var path = _step.value;
44
+ var pathTokens = path.replace(/\[([0-9]+)\]/g, '.$1').replace(/^\./, '').split(/\./);
45
+ L2: {
46
+ var replacedSuperPaths = [];
47
+ var _loop2 = function _loop2(superPath) {
48
+ var superPathTokens = superPathTokensMap[superPath];
49
+ if (superPathTokens.length <= pathTokens.length) {
50
+ if (superPathTokens.every(function (p, i) {
51
+ return p === pathTokens[i];
52
+ })) {
53
+ return "break|L2";
54
+ }
55
+ } else {
56
+ pathTokens.every(function (p, i) {
57
+ return p === superPathTokens[i];
58
+ }) && replacedSuperPaths.push(superPath);
59
+ }
60
+ };
61
+ for (var superPath in superPathTokensMap) {
62
+ var _ret = _loop2(superPath);
63
+ if (_ret === "break|L2") break L2;
64
+ }
65
+ superPathTokensMap[path] = pathTokens;
66
+ for (var _i = 0, _replacedSuperPaths = replacedSuperPaths; _i < _replacedSuperPaths.length; _i++) {
67
+ var _path = _replacedSuperPaths[_i];
68
+ delete superPathTokensMap[_path];
69
+ }
70
+ }
71
+ };
72
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
73
+ _loop();
74
+ }
75
+ } catch (err) {
76
+ _iterator.e(err);
77
+ } finally {
78
+ _iterator.f();
79
+ }
80
+ return Object.keys(superPathTokensMap);
81
+ }
82
+ ;
83
+ function makeReadonly(v) {
18
84
  var frozen = true;
19
- if ((0, _lodash["default"])(v)) {
85
+ if ((0, _lodash3["default"])(v)) {
20
86
  for (var k in v) {
21
87
  makeReadonly(v[k]);
22
88
  }
@@ -22,5 +88,71 @@ var makeReadonly = function makeReadonly(v) {
22
88
  }
23
89
  !frozen && Object.freeze(v);
24
90
  return v;
25
- };
26
- exports.makeReadonly = makeReadonly;
91
+ }
92
+ ;
93
+ function mapPathsToObject(source, propertyPaths) {
94
+ var object = {};
95
+ var _iterator2 = _createForOfIteratorHelper(arrangePropertyPaths(propertyPaths)),
96
+ _step2;
97
+ try {
98
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
99
+ var path = _step2.value;
100
+ var value = (0, _lodash["default"])(source, path);
101
+ if (typeof value === 'undefined' && !(0, _lodash2["default"])(source, path)) {
102
+ continue;
103
+ }
104
+ var parent = object;
105
+ var _loop3 = function _loop3(tokens, tLen, t) {
106
+ if (!tokens[t].endsWith(']')) {
107
+ if (t + 1 === tLen) {
108
+ parent[tokens[t]] = value;
109
+ } else if (!(tokens[t] in parent)) {
110
+ parent[tokens[t]] = {};
111
+ }
112
+ parent = parent[tokens[t]];
113
+ return "continue";
114
+ }
115
+ var arrayMatch = tokens[t].match(/^([^\[]+)((?:\[[0-9]+\])+)$/);
116
+ var indexMatches = arrayMatch[2].replace(/^\[/, '').replace(/\]$/, '').split('][');
117
+ var exArray = arrayMatch[1] in parent ? parent[arrayMatch[1]] : none;
118
+ parent[arrayMatch[1]] = new Array(+indexMatches[0]);
119
+ parent = parent[arrayMatch[1]];
120
+ var currArray = parent;
121
+ for (var iLen = indexMatches.length, i = 0; i < iLen; i++) {
122
+ var stateIndex = +indexMatches[i];
123
+ parent[stateIndex] = i + 1 === iLen ? value : new Array(+indexMatches[i + 1]);
124
+ parent = parent[stateIndex];
125
+ }
126
+ if (exArray instanceof None) {
127
+ return "continue";
128
+ }
129
+ (function mergeIndexedObj(source) {
130
+ var parentPropertyPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
131
+ if ((0, _lodash3["default"])(source)) {
132
+ for (var k in source) {
133
+ mergeIndexedObj(source[k], "".concat(parentPropertyPath).concat(k, "."));
134
+ }
135
+ return;
136
+ }
137
+ if (Array.isArray(source)) {
138
+ for (var sLen = source.length, s = 0; s < sLen; s++) {
139
+ mergeIndexedObj(source[s], "".concat(parentPropertyPath).concat(s, "."));
140
+ }
141
+ return;
142
+ }
143
+ (0, _lodash4["default"])(currArray, parentPropertyPath.replace(/\.+$/, ''), source);
144
+ })(exArray);
145
+ };
146
+ for (var tokens = path.split('.'), tLen = tokens.length, t = 0; t < tLen; t++) {
147
+ var _ret2 = _loop3(tokens, tLen, t);
148
+ if (_ret2 === "continue") continue;
149
+ }
150
+ }
151
+ } catch (err) {
152
+ _iterator2.e(err);
153
+ } finally {
154
+ _iterator2.f();
155
+ }
156
+ return object;
157
+ }
158
+ ;
package/package.json CHANGED
@@ -14,7 +14,6 @@
14
14
  "lodash.isequal": "^4.5.0",
15
15
  "lodash.isplainobject": "^4.0.6",
16
16
  "lodash.omit": "^4.5.0",
17
- "lodash.pick": "^4.4.0",
18
17
  "lodash.set": "^4.3.2",
19
18
  "uuid": "^9.0.0"
20
19
  },
@@ -84,6 +83,7 @@
84
83
  }
85
84
  },
86
85
  "keywords": [
86
+ "connect",
87
87
  "context",
88
88
  "react-hooks",
89
89
  "react-context",
@@ -105,10 +105,11 @@
105
105
  "url": "git+https://github.com/steveswork/react-observable-context.git"
106
106
  },
107
107
  "scripts": {
108
- "build": "eslint --fix && rm -rf dist && babel src -d dist && npx -p typescript tsc && node ./post-builder",
108
+ "build": "eslint --fix && rm -rf dist && babel src -d dist && npx -p typescript tsc",
109
+ "postbuild": "node ./post-builder",
109
110
  "test": "eslint --fix && jest --updateSnapshot",
110
111
  "test:watch": "eslint --fix && jest --updateSnapshot --watchAll"
111
112
  },
112
113
  "types": "dist/main/index.d.ts",
113
- "version": "4.0.0-alpha.3"
114
+ "version": "4.0.0-alpha.5s"
114
115
  }