@dr.pogodin/react-global-state 0.8.3 → 0.9.1

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,181 +1,191 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4
- import _createClass from "@babel/runtime/helpers/createClass";
5
-
6
- 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; }
7
-
8
- 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; }
9
-
10
- import { cloneDeep, get as _get, isArray, isObject, isNil, set as _set, toPath } from 'lodash';
1
+ import _classPrivateFieldGet from "@babel/runtime/helpers/classPrivateFieldGet";
2
+ import _classPrivateFieldSet from "@babel/runtime/helpers/classPrivateFieldSet";
3
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
4
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
5
+ import { cloneDeep, get, isFunction, isObject, isNil, set, toPath } from 'lodash';
11
6
  import { isDebugMode } from "./utils";
12
- var ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';
13
- /**
14
- * Transform state path into the full path inside GlobalState object.
15
- * @param {string} statePath
16
- * @return {string}
17
- * @ignore
18
- */
19
-
20
- function fullPath(statePath) {
21
- return isNil(statePath) ? 'state' : "state.".concat(statePath);
22
- }
23
-
24
- var GlobalState = /*#__PURE__*/function () {
7
+ const ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';
8
+ var _initialState = /*#__PURE__*/new WeakMap();
9
+ var _nextNotifierId = /*#__PURE__*/new WeakMap();
10
+ var _ssrContext = /*#__PURE__*/new WeakMap();
11
+ var _currentState = /*#__PURE__*/new WeakMap();
12
+ var _watchers = /*#__PURE__*/new WeakMap();
13
+ export default class GlobalState {
25
14
  /**
26
15
  * Creates a new global state object.
27
16
  * @param {any} [initialState] Intial global state content.
28
17
  * @param {SsrContext} [ssrContext] Server-side rendering context.
29
18
  */
30
- function GlobalState(initialState, ssrContext) {
31
- _classCallCheck(this, GlobalState);
32
-
33
- /* eslint-disable no-param-reassign */
34
- this.state = cloneDeep(initialState);
35
- this.nextNotifierId = null;
36
- this.watchers = [];
37
-
19
+ constructor(initialState, ssrContext) {
20
+ _classPrivateFieldInitSpec(this, _initialState, {
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ _classPrivateFieldInitSpec(this, _nextNotifierId, {
25
+ writable: true,
26
+ value: null
27
+ });
28
+ _classPrivateFieldInitSpec(this, _ssrContext, {
29
+ writable: true,
30
+ value: void 0
31
+ });
32
+ _classPrivateFieldInitSpec(this, _currentState, {
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ _classPrivateFieldInitSpec(this, _watchers, {
37
+ writable: true,
38
+ value: []
39
+ });
40
+ _classPrivateFieldSet(this, _currentState, initialState);
41
+ _classPrivateFieldSet(this, _initialState, initialState);
38
42
  if (ssrContext) {
43
+ /* eslint-disable no-param-reassign */
39
44
  ssrContext.dirty = false;
40
45
  ssrContext.pending = [];
41
- ssrContext.state = this.state;
42
- this.ssrContext = ssrContext;
43
- }
46
+ ssrContext.state = _classPrivateFieldGet(this, _currentState);
47
+ /* eslint-enable no-param-reassign */
44
48
 
49
+ _classPrivateFieldSet(this, _ssrContext, ssrContext);
50
+ }
45
51
  if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
46
52
  /* eslint-disable no-console */
47
- var msg = 'New ReactGlobalState created';
53
+ let msg = 'New ReactGlobalState created';
48
54
  if (ssrContext) msg += ' (SSR mode)';
49
55
  console.groupCollapsed(msg);
50
56
  console.log('Initial state:', cloneDeep(initialState));
51
57
  console.groupEnd();
52
58
  /* eslint-enable no-console */
53
59
  }
54
- /* eslint-enable no-param-reassign */
55
-
56
60
  }
61
+
57
62
  /**
58
- * Gets the value at given `path` of global state. If `path` is null or
59
- * undefined, the entire state object is returned.
60
- * @param {string} [path] Dot-delimitered state path. If not given, entire
61
- * global state content is returned.
62
- * @return {any}
63
+ * Gets current or initial value at the specified "path" of the global state.
64
+ * Allows to get the entire global state, and automatically set default value
65
+ * at the "path".
66
+ * @param {string} [path] Dot-delimitered state path. Pass it "null",
67
+ * or "undefined" to refer the entire global state.
68
+ * @param {object} [options={}] Additional options.
69
+ * @param {boolean} [options.initialState] If "true" the value will be read
70
+ * from the initial state instead of the current one.
71
+ * @param {any} [options.initialValue] If the value read from the "path" is
72
+ * "undefined", this "initialValue" will be returned instead. In such case
73
+ * "initialValue" will also be written to the "path" of the current global
74
+ * state (no matter "initialState" flag), if "undefined" is stored there.
75
+ * @return {any} Retrieved value.
63
76
  */
64
-
65
-
66
- _createClass(GlobalState, [{
67
- key: "get",
68
- value: function get(path) {
69
- return _get(this, fullPath(path));
77
+ get(path) {
78
+ let {
79
+ initialState,
80
+ initialValue
81
+ } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
82
+ const state = initialState ? _classPrivateFieldGet(this, _initialState) : _classPrivateFieldGet(this, _currentState);
83
+ let value = isNil(path) ? state : get(state, path);
84
+ if (value === undefined && initialValue !== undefined) {
85
+ value = isFunction(initialValue) ? initialValue() : initialValue;
86
+ if (!initialState || this.get(path) === undefined) this.set(path, value);
70
87
  }
71
- /**
72
- * Writes the `value` to given global state `path`.
73
- * @param {string} [path] Dot-delimitered state path. If not given, entire
74
- * global state content is replaced by the `value`.
75
- * @param {any} value The value.
76
- * @return {any} Given `value` itself.
77
- */
78
-
79
- }, {
80
- key: "set",
81
- value: function set(path, value) {
82
- var _this = this;
83
-
84
- var p = fullPath(path);
85
-
86
- if (value !== _get(this, p)) {
87
- if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
88
- /* eslint-disable no-console */
89
- console.groupCollapsed("ReactGlobalState update. Path: \"".concat(path || '', "\""));
90
- console.log('New value:', cloneDeep(value));
91
- /* eslint-enable no-console */
92
- }
88
+ return value;
89
+ }
93
90
 
94
- var pos = this;
95
- var pathSegments = toPath(p);
91
+ /**
92
+ * Writes the `value` to given global state `path`.
93
+ * @param {string} [path] Dot-delimitered state path. If not given, entire
94
+ * global state content is replaced by the `value`.
95
+ * @param {any} value The value.
96
+ * @return {any} Given `value` itself.
97
+ */
98
+ set(path, value) {
99
+ if (value !== this.get(path)) {
100
+ if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
101
+ /* eslint-disable no-console */
102
+ console.groupCollapsed(`ReactGlobalState update. Path: "${path || ''}"`);
103
+ console.log('New value:', cloneDeep(value));
104
+ /* eslint-enable no-console */
105
+ }
96
106
 
97
- for (var i = 0; i < pathSegments.length - 1; i += 1) {
98
- var seg = pathSegments[i];
99
- var next = pos[seg];
100
- if (isArray(next)) pos[seg] = _toConsumableArray(next);else if (isObject(next)) pos[seg] = _objectSpread({}, next);else break;
107
+ if (isNil(path)) _classPrivateFieldSet(this, _currentState, value);else {
108
+ const root = {
109
+ state: _classPrivateFieldGet(this, _currentState)
110
+ };
111
+ let segIdx = 0;
112
+ let pos = root;
113
+ const pathSegments = toPath(`state.${path}`);
114
+ for (; segIdx < pathSegments.length - 1; segIdx += 1) {
115
+ const seg = pathSegments[segIdx];
116
+ const next = pos[seg];
117
+ if (Array.isArray(next)) pos[seg] = [...next];else if (isObject(next)) pos[seg] = {
118
+ ...next
119
+ };else {
120
+ // We arrived to a state sub-segment, where the remaining part of
121
+ // the update path does not exist yet. We rely on lodash's set()
122
+ // function to create the remaining path, and set the value.
123
+ set(pos, pathSegments.slice(segIdx), value);
124
+ break;
125
+ }
101
126
  pos = pos[seg];
102
- } // TODO: With such naive use of _.set, the state is mutated in place,
103
- // which may cause tons of unexpected side effects for dependants.
104
- // It will be better to partially clone the state, so that any existing
105
- // references are not mutated, while the full deep clonning is also
106
- // avoided.
107
-
108
-
109
- _set(this, p, value);
110
-
111
- if (this.ssrContext) {
112
- this.ssrContext.dirty = true;
113
- this.ssrContext.state = this.state;
114
- } else if (!this.nextNotifierId) {
115
- this.nextNotifierId = setTimeout(function () {
116
- _this.nextNotifierId = null;
117
-
118
- _toConsumableArray(_this.watchers).forEach(function (w) {
119
- return w();
120
- });
121
- });
122
127
  }
123
-
124
- if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
125
- /* eslint-disable no-console */
126
- console.log('New state:', cloneDeep(this.state));
127
- console.groupEnd();
128
- /* eslint-enable no-console */
128
+ if (segIdx === pathSegments.length - 1) {
129
+ pos[pathSegments[segIdx]] = value;
129
130
  }
131
+ _classPrivateFieldSet(this, _currentState, root.state);
130
132
  }
131
-
132
- return value;
133
- }
134
- /**
135
- * Unsubscribes `callback` from watching state updates; no operation if
136
- * `callback` is not subscribed to the state updates.
137
- * @param {function} callback
138
- * @throws if {@link SsrContext} is attached to the state instance: the state
139
- * watching functionality is intended for client-side (non-SSR) only.
140
- */
141
-
142
- }, {
143
- key: "unWatch",
144
- value: function unWatch(callback) {
145
- if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);
146
- var watchers = this.watchers;
147
- var pos = watchers.indexOf(callback);
148
-
149
- if (pos >= 0) {
150
- watchers[pos] = watchers[watchers.length - 1];
151
- watchers.pop();
133
+ if (_classPrivateFieldGet(this, _ssrContext)) {
134
+ _classPrivateFieldGet(this, _ssrContext).dirty = true;
135
+ _classPrivateFieldGet(this, _ssrContext).state = _classPrivateFieldGet(this, _currentState);
136
+ } else if (!_classPrivateFieldGet(this, _nextNotifierId)) {
137
+ _classPrivateFieldSet(this, _nextNotifierId, setTimeout(() => {
138
+ _classPrivateFieldSet(this, _nextNotifierId, null);
139
+ [..._classPrivateFieldGet(this, _watchers)].forEach(w => w());
140
+ }));
141
+ }
142
+ if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
143
+ /* eslint-disable no-console */
144
+ console.log('New state:', cloneDeep(_classPrivateFieldGet(this, _currentState)));
145
+ console.groupEnd();
146
+ /* eslint-enable no-console */
152
147
  }
153
148
  }
154
- /**
155
- * Subscribes `callback` to watch state updates; no operation if
156
- * `callback` is already subscribed to this state instance.
157
- * @param {function} callback It will be called without any arguments every
158
- * time the state content changes (note, howhever, separate state updates can
159
- * be applied to the state at once, and watching callbacks will be called once
160
- * after such bulk update).
161
- * @throws if {@link SsrContext} is attached to the state instance: the state
162
- * watching functionality is intended for client-side (non-SSR) only.
163
- */
164
149
 
165
- }, {
166
- key: "watch",
167
- value: function watch(callback) {
168
- if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);
169
- var watchers = this.watchers;
150
+ return value;
151
+ }
170
152
 
171
- if (watchers.indexOf(callback) < 0) {
172
- watchers.push(callback);
173
- }
153
+ /**
154
+ * Unsubscribes `callback` from watching state updates; no operation if
155
+ * `callback` is not subscribed to the state updates.
156
+ * @param {function} callback
157
+ * @throws if {@link SsrContext} is attached to the state instance: the state
158
+ * watching functionality is intended for client-side (non-SSR) only.
159
+ */
160
+ unWatch(callback) {
161
+ if (_classPrivateFieldGet(this, _ssrContext)) throw new Error(ERR_NO_SSR_WATCH);
162
+ const watchers = _classPrivateFieldGet(this, _watchers);
163
+ const pos = watchers.indexOf(callback);
164
+ if (pos >= 0) {
165
+ watchers[pos] = watchers[watchers.length - 1];
166
+ watchers.pop();
174
167
  }
175
- }]);
176
-
177
- return GlobalState;
178
- }();
168
+ }
169
+ get ssrContext() {
170
+ return _classPrivateFieldGet(this, _ssrContext);
171
+ }
179
172
 
180
- export { GlobalState as default };
173
+ /**
174
+ * Subscribes `callback` to watch state updates; no operation if
175
+ * `callback` is already subscribed to this state instance.
176
+ * @param {function} callback It will be called without any arguments every
177
+ * time the state content changes (note, howhever, separate state updates can
178
+ * be applied to the state at once, and watching callbacks will be called once
179
+ * after such bulk update).
180
+ * @throws if {@link SsrContext} is attached to the state instance: the state
181
+ * watching functionality is intended for client-side (non-SSR) only.
182
+ */
183
+ watch(callback) {
184
+ if (_classPrivateFieldGet(this, _ssrContext)) throw new Error(ERR_NO_SSR_WATCH);
185
+ const watchers = _classPrivateFieldGet(this, _watchers);
186
+ if (watchers.indexOf(callback) < 0) {
187
+ watchers.push(callback);
188
+ }
189
+ }
190
+ }
181
191
  //# sourceMappingURL=GlobalState.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/GlobalState.js"],"names":["cloneDeep","get","isArray","isObject","isNil","set","toPath","isDebugMode","ERR_NO_SSR_WATCH","fullPath","statePath","GlobalState","initialState","ssrContext","state","nextNotifierId","watchers","dirty","pending","process","env","NODE_ENV","msg","console","groupCollapsed","log","groupEnd","path","value","p","pos","pathSegments","i","length","seg","next","setTimeout","forEach","w","callback","Error","indexOf","pop","push"],"mappings":";;;;;;;;;AAAA,SACEA,SADF,EAEEC,GAAG,IAAHA,IAFF,EAGEC,OAHF,EAIEC,QAJF,EAKEC,KALF,EAMEC,GAAG,IAAHA,IANF,EAOEC,MAPF,QAQO,QARP;AAUA,SAASC,WAAT;AAEA,IAAMC,gBAAgB,GAAG,gDAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CAAkBC,SAAlB,EAA6B;AAC3B,SAAON,KAAK,CAACM,SAAD,CAAL,GAAmB,OAAnB,mBAAsCA,SAAtC,CAAP;AACD;;IAEoBC,W;AACnB;AACF;AACA;AACA;AACA;AACE,uBAAYC,YAAZ,EAA0BC,UAA1B,EAAsC;AAAA;;AACpC;AACA,SAAKC,K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O,CAACE,GAAR,CAAY,YAAZ,EAA0BzB,SAAS,CAAC,KAAKc,KAAN,CAAnC;AACAS,UAAAA,OAAO,CAACG,QAAR;AACA;AACD;AACF;;AACD,aAAOE,KAAP;AACD;AAED;AACF;AACA;AACA;AACA;AACA;AACA;;;;WACE,iBAAQW,QAAR,EAAkB;AAChB,UAAI,KAAK1B,UAAT,EAAqB,MAAM,IAAI2B,KAAJ,CAAUhC,gBAAV,CAAN;AACrB,UAAQQ,QAAR,GAAqB,IAArB,CAAQA,QAAR;AACA,UAAMc,GAAG,GAAGd,QAAQ,CAACyB,OAAT,CAAiBF,QAAjB,CAAZ;;AACA,UAAIT,GAAG,IAAI,CAAX,EAAc;AACZd,QAAAA,QAAQ,CAACc,GAAD,CAAR,GAAgBd,QAAQ,CAACA,QAAQ,CAACiB,MAAT,GAAkB,CAAnB,CAAxB;AACAjB,QAAAA,QAAQ,CAAC0B,GAAT;AACD;AACF;AAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;WACE,eAAMH,QAAN,EAAgB;AACd,UAAI,KAAK1B,UAAT,EAAqB,MAAM,IAAI2B,KAAJ,CAAUhC,gBAAV,CAAN;AACrB,UAAQQ,QAAR,GAAqB,IAArB,CAAQA,QAAR;;AACA,UAAIA,QAAQ,CAACyB,OAAT,CAAiBF,QAAjB,IAA6B,CAAjC,EAAoC;AAClCvB,QAAAA,QAAQ,CAAC2B,IAAT,CAAcJ,QAAd;AACD;AACF;;;;;;SAlIkB5B,W","sourcesContent":["import {\n cloneDeep,\n get,\n isArray,\n isObject,\n isNil,\n set,\n toPath,\n} from 'lodash';\n\nimport { isDebugMode } from './utils';\n\nconst ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';\n\n/**\n * Transform state path into the full path inside GlobalState object.\n * @param {string} statePath\n * @return {string}\n * @ignore\n */\nfunction fullPath(statePath) {\n return isNil(statePath) ? 'state' : `state.${statePath}`;\n}\n\nexport default class GlobalState {\n /**\n * Creates a new global state object.\n * @param {any} [initialState] Intial global state content.\n * @param {SsrContext} [ssrContext] Server-side rendering context.\n */\n constructor(initialState, ssrContext) {\n /* eslint-disable no-param-reassign */\n this.state = cloneDeep(initialState);\n this.nextNotifierId = null;\n this.watchers = [];\n\n if (ssrContext) {\n ssrContext.dirty = false;\n ssrContext.pending = [];\n ssrContext.state = this.state;\n this.ssrContext = ssrContext;\n }\n\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n let msg = 'New ReactGlobalState created';\n if (ssrContext) msg += ' (SSR mode)';\n console.groupCollapsed(msg);\n console.log('Initial state:', cloneDeep(initialState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n /* eslint-enable no-param-reassign */\n }\n\n /**\n * Gets the value at given `path` of global state. If `path` is null or\n * undefined, the entire state object is returned.\n * @param {string} [path] Dot-delimitered state path. If not given, entire\n * global state content is returned.\n * @return {any}\n */\n get(path) {\n return get(this, fullPath(path));\n }\n\n /**\n * Writes the `value` to given global state `path`.\n * @param {string} [path] Dot-delimitered state path. If not given, entire\n * global state content is replaced by the `value`.\n * @param {any} value The value.\n * @return {any} Given `value` itself.\n */\n set(path, value) {\n const p = fullPath(path);\n if (value !== get(this, p)) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState update. Path: \"${path || ''}\"`,\n );\n console.log('New value:', cloneDeep(value));\n /* eslint-enable no-console */\n }\n let pos = this;\n const pathSegments = toPath(p);\n for (let i = 0; i < pathSegments.length - 1; i += 1) {\n const seg = pathSegments[i];\n const next = pos[seg];\n if (isArray(next)) pos[seg] = [...next];\n else if (isObject(next)) pos[seg] = { ...next };\n else break;\n pos = pos[seg];\n }\n\n // TODO: With such naive use of _.set, the state is mutated in place,\n // which may cause tons of unexpected side effects for dependants.\n // It will be better to partially clone the state, so that any existing\n // references are not mutated, while the full deep clonning is also\n // avoided.\n set(this, p, value);\n\n if (this.ssrContext) {\n this.ssrContext.dirty = true;\n this.ssrContext.state = this.state;\n } else if (!this.nextNotifierId) {\n this.nextNotifierId = setTimeout(() => {\n this.nextNotifierId = null;\n [...this.watchers].forEach((w) => w());\n });\n }\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log('New state:', cloneDeep(this.state));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n return value;\n }\n\n /**\n * Unsubscribes `callback` from watching state updates; no operation if\n * `callback` is not subscribed to the state updates.\n * @param {function} callback\n * @throws if {@link SsrContext} is attached to the state instance: the state\n * watching functionality is intended for client-side (non-SSR) only.\n */\n unWatch(callback) {\n if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n const { watchers } = this;\n const pos = watchers.indexOf(callback);\n if (pos >= 0) {\n watchers[pos] = watchers[watchers.length - 1];\n watchers.pop();\n }\n }\n\n /**\n * Subscribes `callback` to watch state updates; no operation if\n * `callback` is already subscribed to this state instance.\n * @param {function} callback It will be called without any arguments every\n * time the state content changes (note, howhever, separate state updates can\n * be applied to the state at once, and watching callbacks will be called once\n * after such bulk update).\n * @throws if {@link SsrContext} is attached to the state instance: the state\n * watching functionality is intended for client-side (non-SSR) only.\n */\n watch(callback) {\n if (this.ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n const { watchers } = this;\n if (watchers.indexOf(callback) < 0) {\n watchers.push(callback);\n }\n }\n}\n"],"file":"GlobalState.js"}
1
+ {"version":3,"file":"GlobalState.js","names":["cloneDeep","get","isFunction","isObject","isNil","set","toPath","isDebugMode","ERR_NO_SSR_WATCH","GlobalState","constructor","initialState","ssrContext","dirty","pending","state","process","env","NODE_ENV","msg","console","groupCollapsed","log","groupEnd","path","initialValue","value","undefined","root","segIdx","pos","pathSegments","length","seg","next","Array","isArray","slice","setTimeout","forEach","w","unWatch","callback","Error","watchers","indexOf","pop","watch","push"],"sources":["../../src/GlobalState.js"],"sourcesContent":["import {\n cloneDeep,\n get,\n isFunction,\n isObject,\n isNil,\n set,\n toPath,\n} from 'lodash';\n\nimport { isDebugMode } from './utils';\n\nconst ERR_NO_SSR_WATCH = 'GlobalState must not be watched at server side';\n\nexport default class GlobalState {\n #initialState;\n\n #nextNotifierId = null;\n\n #ssrContext;\n\n #currentState;\n\n #watchers = [];\n\n /**\n * Creates a new global state object.\n * @param {any} [initialState] Intial global state content.\n * @param {SsrContext} [ssrContext] Server-side rendering context.\n */\n constructor(initialState, ssrContext) {\n this.#currentState = initialState;\n this.#initialState = initialState;\n\n if (ssrContext) {\n /* eslint-disable no-param-reassign */\n ssrContext.dirty = false;\n ssrContext.pending = [];\n ssrContext.state = this.#currentState;\n /* eslint-enable no-param-reassign */\n\n this.#ssrContext = ssrContext;\n }\n\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n let msg = 'New ReactGlobalState created';\n if (ssrContext) msg += ' (SSR mode)';\n console.groupCollapsed(msg);\n console.log('Initial state:', cloneDeep(initialState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n\n /**\n * Gets current or initial value at the specified \"path\" of the global state.\n * Allows to get the entire global state, and automatically set default value\n * at the \"path\".\n * @param {string} [path] Dot-delimitered state path. Pass it \"null\",\n * or \"undefined\" to refer the entire global state.\n * @param {object} [options={}] Additional options.\n * @param {boolean} [options.initialState] If \"true\" the value will be read\n * from the initial state instead of the current one.\n * @param {any} [options.initialValue] If the value read from the \"path\" is\n * \"undefined\", this \"initialValue\" will be returned instead. In such case\n * \"initialValue\" will also be written to the \"path\" of the current global\n * state (no matter \"initialState\" flag), if \"undefined\" is stored there.\n * @return {any} Retrieved value.\n */\n get(path, { initialState, initialValue } = {}) {\n const state = initialState ? this.#initialState : this.#currentState;\n let value = isNil(path) ? state : get(state, path);\n if (value === undefined && initialValue !== undefined) {\n value = isFunction(initialValue) ? initialValue() : initialValue;\n if (!initialState || this.get(path) === undefined) this.set(path, value);\n }\n return value;\n }\n\n /**\n * Writes the `value` to given global state `path`.\n * @param {string} [path] Dot-delimitered state path. If not given, entire\n * global state content is replaced by the `value`.\n * @param {any} value The value.\n * @return {any} Given `value` itself.\n */\n set(path, value) {\n if (value !== this.get(path)) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState update. Path: \"${path || ''}\"`,\n );\n console.log('New value:', cloneDeep(value));\n /* eslint-enable no-console */\n }\n\n if (isNil(path)) this.#currentState = value;\n else {\n const root = { state: this.#currentState };\n let segIdx = 0;\n let pos = root;\n const pathSegments = toPath(`state.${path}`);\n for (; segIdx < pathSegments.length - 1; segIdx += 1) {\n const seg = pathSegments[segIdx];\n const next = pos[seg];\n if (Array.isArray(next)) pos[seg] = [...next];\n else if (isObject(next)) pos[seg] = { ...next };\n else {\n // We arrived to a state sub-segment, where the remaining part of\n // the update path does not exist yet. We rely on lodash's set()\n // function to create the remaining path, and set the value.\n set(pos, pathSegments.slice(segIdx), value);\n break;\n }\n pos = pos[seg];\n }\n\n if (segIdx === pathSegments.length - 1) {\n pos[pathSegments[segIdx]] = value;\n }\n\n this.#currentState = root.state;\n }\n\n if (this.#ssrContext) {\n this.#ssrContext.dirty = true;\n this.#ssrContext.state = this.#currentState;\n } else if (!this.#nextNotifierId) {\n this.#nextNotifierId = setTimeout(() => {\n this.#nextNotifierId = null;\n [...this.#watchers].forEach((w) => w());\n });\n }\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log('New state:', cloneDeep(this.#currentState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n return value;\n }\n\n /**\n * Unsubscribes `callback` from watching state updates; no operation if\n * `callback` is not subscribed to the state updates.\n * @param {function} callback\n * @throws if {@link SsrContext} is attached to the state instance: the state\n * watching functionality is intended for client-side (non-SSR) only.\n */\n unWatch(callback) {\n if (this.#ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n\n const watchers = this.#watchers;\n const pos = watchers.indexOf(callback);\n if (pos >= 0) {\n watchers[pos] = watchers[watchers.length - 1];\n watchers.pop();\n }\n }\n\n get ssrContext() { return this.#ssrContext; }\n\n /**\n * Subscribes `callback` to watch state updates; no operation if\n * `callback` is already subscribed to this state instance.\n * @param {function} callback It will be called without any arguments every\n * time the state content changes (note, howhever, separate state updates can\n * be applied to the state at once, and watching callbacks will be called once\n * after such bulk update).\n * @throws if {@link SsrContext} is attached to the state instance: the state\n * watching functionality is intended for client-side (non-SSR) only.\n */\n watch(callback) {\n if (this.#ssrContext) throw new Error(ERR_NO_SSR_WATCH);\n\n const watchers = this.#watchers;\n if (watchers.indexOf(callback) < 0) {\n watchers.push(callback);\n }\n }\n}\n"],"mappings":";;;;AAAA,SACEA,SAAS,EACTC,GAAG,EACHC,UAAU,EACVC,QAAQ,EACRC,KAAK,EACLC,GAAG,EACHC,MAAM,QACD,QAAQ;AAEf,SAASC,WAAW;AAEpB,MAAMC,gBAAgB,GAAG,gDAAgD;AAAC;AAAA;AAAA;AAAA;AAAA;AAE1E,eAAe,MAAMC,WAAW,CAAC;EAW/B;AACF;AACA;AACA;AACA;EACEC,WAAW,CAACC,YAAY,EAAEC,UAAU,EAAE;IAAA;MAAA;MAAA;IAAA;IAAA;MAAA;MAAA,OAbpB;IAAI;IAAA;MAAA;MAAA;IAAA;IAAA;MAAA;MAAA;IAAA;IAAA;MAAA;MAAA,OAMV;IAAE;IAQZ,0BAAI,iBAAiBD,YAAY;IACjC,0BAAI,iBAAiBA,YAAY;IAEjC,IAAIC,UAAU,EAAE;MACd;MACAA,UAAU,CAACC,KAAK,GAAG,KAAK;MACxBD,UAAU,CAACE,OAAO,GAAG,EAAE;MACvBF,UAAU,CAACG,KAAK,yBAAG,IAAI,gBAAc;MACrC;;MAEA,0BAAI,eAAeH,UAAU;IAC/B;IAEA,IAAII,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IAAIX,WAAW,EAAE,EAAE;MAC1D;MACA,IAAIY,GAAG,GAAG,8BAA8B;MACxC,IAAIP,UAAU,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 +1,29 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
-
3
1
  /* eslint-disable react/prop-types */
4
- import { createContext, useContext, useState } from 'react';
2
+
3
+ import { createContext, useContext, useRef } from 'react';
5
4
  import GlobalState from "./GlobalState";
6
5
  import { jsx as _jsx } from "react/jsx-runtime";
7
- var context = /*#__PURE__*/createContext();
6
+ const context = /*#__PURE__*/createContext();
7
+
8
8
  /**
9
9
  * Gets {@link GlobalState} instance from the context. In most cases
10
10
  * you should use {@link useGlobalState}, and other hooks to interact with
11
11
  * the global state, instead of accessing it directly.
12
12
  * @return {GlobalState}
13
13
  */
14
-
15
14
  export function getGlobalState() {
16
15
  // Here Rules of Hooks are violated because "getGlobalState()" does not follow
17
16
  // convention that hook names should start with use... This is intentional in
18
17
  // our case, as getGlobalState() hook is intended for advance scenarious,
19
18
  // while the normal interaction with the global state should happen via
20
19
  // another hook, useGlobalState().
21
-
22
20
  /* eslint-disable react-hooks/rules-of-hooks */
23
- var globalState = useContext(context);
21
+ const globalState = useContext(context);
24
22
  /* eslint-enable react-hooks/rules-of-hooks */
25
-
26
23
  if (!globalState) throw new Error('Missing GlobalStateProvider');
27
24
  return globalState;
28
25
  }
26
+
29
27
  /**
30
28
  * @category Hooks
31
29
  * @desc Gets SSR context.
@@ -40,19 +38,17 @@ export function getGlobalState() {
40
38
  * - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached
41
39
  * to the global state provided by {@link &lt;GlobalStateProvider&gt;}.
42
40
  */
43
-
44
41
  export function getSsrContext() {
45
- var throwWithoutSsrContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
46
-
47
- var _getGlobalState = getGlobalState(),
48
- ssrContext = _getGlobalState.ssrContext;
49
-
42
+ let throwWithoutSsrContext = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
43
+ const {
44
+ ssrContext
45
+ } = getGlobalState();
50
46
  if (!ssrContext && throwWithoutSsrContext) {
51
47
  throw new Error('No SSR context found');
52
48
  }
53
-
54
49
  return ssrContext;
55
50
  }
51
+
56
52
  /**
57
53
  * Provides global state to its children.
58
54
  * @prop {ReactNode} [children] Component children, which will be provided with
@@ -66,30 +62,19 @@ export function getSsrContext() {
66
62
  * - If `GlobalState` instance, it will be used by this provider.
67
63
  * - If not given, a new `GlobalState` instance will be created and used.
68
64
  */
69
-
70
65
  export default function GlobalStateProvider(_ref) {
71
- var children = _ref.children,
72
- initialState = _ref.initialState,
73
- ssrContext = _ref.ssrContext,
74
- stateProxy = _ref.stateProxy;
75
- var state; // Here Rules of Hooks are violated because hooks are called conditionally,
76
- // however we assume that these properties should not change at runtime, thus
77
- // the actual hook order is preserved. Probably, it should be handled better,
78
- // though.
79
-
80
- /* eslint-disable react-hooks/rules-of-hooks */
81
-
82
- if (stateProxy instanceof GlobalState) state = stateProxy;else if (stateProxy) state = getGlobalState();else {
83
- var _useState = useState(new GlobalState(initialState, ssrContext));
84
-
85
- var _useState2 = _slicedToArray(_useState, 1);
86
-
87
- state = _useState2[0];
66
+ let {
67
+ children,
68
+ initialState,
69
+ ssrContext,
70
+ stateProxy
71
+ } = _ref;
72
+ const state = useRef();
73
+ if (!state.current) {
74
+ if (stateProxy instanceof GlobalState) state.current = stateProxy;else if (stateProxy) state.current = getGlobalState();else state.current = new GlobalState(initialState, ssrContext);
88
75
  }
89
- /* eslint-enable react-hooks/rules-of-hooks */
90
-
91
76
  return /*#__PURE__*/_jsx(context.Provider, {
92
- value: state,
77
+ value: state.current,
93
78
  children: children
94
79
  });
95
80
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/GlobalStateProvider.jsx"],"names":["createContext","useContext","useState","GlobalState","context","getGlobalState","globalState","Error","getSsrContext","throwWithoutSsrContext","ssrContext","GlobalStateProvider","children","initialState","stateProxy","state"],"mappings":";;AAAA;AAEA,SAASA,aAAT,EAAwBC,UAAxB,EAAoCC,QAApC,QAAoD,OAApD;AAEA,OAAOC,WAAP;;AAEA,IAAMC,OAAO,gBAAGJ,aAAa,EAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,cAAT,GAA0B;AAC/B;AACA;AACA;AACA;AACA;;AACA;AACA,MAAMC,WAAW,GAAGL,UAAU,CAACG,OAAD,CAA9B;AACA;;AACA,MAAI,CAACE,WAAL,EAAkB,MAAM,IAAIC,KAAJ,CAAU,6BAAV,CAAN;AAClB,SAAOD,WAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,aAAT,GAAsD;AAAA,MAA/BC,sBAA+B,uEAAN,IAAM;;AAC3D,wBAAuBJ,cAAc,EAArC;AAAA,MAAQK,UAAR,mBAAQA,UAAR;;AACA,MAAI,CAACA,UAAD,IAAeD,sBAAnB,EAA2C;AACzC,UAAM,IAAIF,KAAJ,CAAU,sBAAV,CAAN;AACD;;AACD,SAAOG,UAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,mBAAT,OAKZ;AAAA,MAJDC,QAIC,QAJDA,QAIC;AAAA,MAHDC,YAGC,QAHDA,YAGC;AAAA,MAFDH,UAEC,QAFDA,UAEC;AAAA,MADDI,UACC,QADDA,UACC;AACD,MAAIC,KAAJ,CADC,CAED;AACA;AACA;AACA;;AACA;;AACA,MAAID,UAAU,YAAYX,WAA1B,EAAuCY,KAAK,GAAGD,UAAR,CAAvC,KACK,IAAIA,UAAJ,EAAgBC,KAAK,GAAGV,cAAc,EAAtB,CAAhB;AAAA,oBACUH,QAAQ,CAAC,IAAIC,WAAJ,CAAgBU,YAAhB,EAA8BH,UAA9B,CAAD,CADlB;;AAAA;;AACCK,IAAAA,KADD;AAAA;AAEL;;AACA,sBACE,KAAC,OAAD,CAAS,QAAT;AAAkB,IAAA,KAAK,EAAEA,KAAzB;AAAA,cACGH;AADH,IADF;AAKD","sourcesContent":["/* eslint-disable react/prop-types */\n\nimport { createContext, useContext, useState } from 'react';\n\nimport GlobalState from './GlobalState';\n\nconst context = createContext();\n\n/**\n * Gets {@link GlobalState} instance from the context. In most cases\n * you should use {@link useGlobalState}, and other hooks to interact with\n * the global state, instead of accessing it directly.\n * @return {GlobalState}\n */\nexport function getGlobalState() {\n // Here Rules of Hooks are violated because \"getGlobalState()\" does not follow\n // convention that hook names should start with use... This is intentional in\n // our case, as getGlobalState() hook is intended for advance scenarious,\n // while the normal interaction with the global state should happen via\n // another hook, useGlobalState().\n /* eslint-disable react-hooks/rules-of-hooks */\n const globalState = useContext(context);\n /* eslint-enable react-hooks/rules-of-hooks */\n if (!globalState) throw new Error('Missing GlobalStateProvider');\n return globalState;\n}\n\n/**\n * @category Hooks\n * @desc Gets SSR context.\n * @param {boolean} [throwWithoutSsrContext=true] If `true` (default),\n * this hook will throw if no SSR context is attached to the global state;\n * set `false` to not throw in such case. In either case the hook will throw\n * if the {@link &lt;GlobalStateProvider&gt;} (hence the state) is missing.\n * @returns {SsrContext} SSR context.\n * @throws\n * - If current component has no parent {@link &lt;GlobalStateProvider&gt;}\n * in the rendered React tree.\n * - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached\n * to the global state provided by {@link &lt;GlobalStateProvider&gt;}.\n */\nexport function getSsrContext(throwWithoutSsrContext = true) {\n const { ssrContext } = getGlobalState();\n if (!ssrContext && throwWithoutSsrContext) {\n throw new Error('No SSR context found');\n }\n return ssrContext;\n}\n\n/**\n * Provides global state to its children.\n * @prop {ReactNode} [children] Component children, which will be provided with\n * the global state, and rendered in place of the provider.\n * @prop {any} [initialState] Initial content of the global state.\n * @prop {SsrContext} [ssrContext] Server-side rendering (SSR) context.\n * @prop {boolean|GlobalState} [stateProxy] This option is useful for code\n * splitting and SSR implementation:\n * - If `true`, this provider instance will fetch and reuse the global state\n * from a parent provider.\n * - If `GlobalState` instance, it will be used by this provider.\n * - If not given, a new `GlobalState` instance will be created and used.\n */\nexport default function GlobalStateProvider({\n children,\n initialState,\n ssrContext,\n stateProxy,\n}) {\n let state;\n // Here Rules of Hooks are violated because hooks are called conditionally,\n // however we assume that these properties should not change at runtime, thus\n // the actual hook order is preserved. Probably, it should be handled better,\n // though.\n /* eslint-disable react-hooks/rules-of-hooks */\n if (stateProxy instanceof GlobalState) state = stateProxy;\n else if (stateProxy) state = getGlobalState();\n else [state] = useState(new GlobalState(initialState, ssrContext));\n /* eslint-enable react-hooks/rules-of-hooks */\n return (\n <context.Provider value={state}>\n {children}\n </context.Provider>\n );\n}\n"],"file":"GlobalStateProvider.js"}
1
+ {"version":3,"file":"GlobalStateProvider.js","names":["createContext","useContext","useRef","GlobalState","context","getGlobalState","globalState","Error","getSsrContext","throwWithoutSsrContext","ssrContext","GlobalStateProvider","children","initialState","stateProxy","state","current"],"sources":["../../src/GlobalStateProvider.jsx"],"sourcesContent":["/* eslint-disable react/prop-types */\n\nimport { createContext, useContext, useRef } from 'react';\n\nimport GlobalState from './GlobalState';\n\nconst context = createContext();\n\n/**\n * Gets {@link GlobalState} instance from the context. In most cases\n * you should use {@link useGlobalState}, and other hooks to interact with\n * the global state, instead of accessing it directly.\n * @return {GlobalState}\n */\nexport function getGlobalState() {\n // Here Rules of Hooks are violated because \"getGlobalState()\" does not follow\n // convention that hook names should start with use... This is intentional in\n // our case, as getGlobalState() hook is intended for advance scenarious,\n // while the normal interaction with the global state should happen via\n // another hook, useGlobalState().\n /* eslint-disable react-hooks/rules-of-hooks */\n const globalState = useContext(context);\n /* eslint-enable react-hooks/rules-of-hooks */\n if (!globalState) throw new Error('Missing GlobalStateProvider');\n return globalState;\n}\n\n/**\n * @category Hooks\n * @desc Gets SSR context.\n * @param {boolean} [throwWithoutSsrContext=true] If `true` (default),\n * this hook will throw if no SSR context is attached to the global state;\n * set `false` to not throw in such case. In either case the hook will throw\n * if the {@link &lt;GlobalStateProvider&gt;} (hence the state) is missing.\n * @returns {SsrContext} SSR context.\n * @throws\n * - If current component has no parent {@link &lt;GlobalStateProvider&gt;}\n * in the rendered React tree.\n * - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached\n * to the global state provided by {@link &lt;GlobalStateProvider&gt;}.\n */\nexport function getSsrContext(throwWithoutSsrContext = true) {\n const { ssrContext } = getGlobalState();\n if (!ssrContext && throwWithoutSsrContext) {\n throw new Error('No SSR context found');\n }\n return ssrContext;\n}\n\n/**\n * Provides global state to its children.\n * @prop {ReactNode} [children] Component children, which will be provided with\n * the global state, and rendered in place of the provider.\n * @prop {any} [initialState] Initial content of the global state.\n * @prop {SsrContext} [ssrContext] Server-side rendering (SSR) context.\n * @prop {boolean|GlobalState} [stateProxy] This option is useful for code\n * splitting and SSR implementation:\n * - If `true`, this provider instance will fetch and reuse the global state\n * from a parent provider.\n * - If `GlobalState` instance, it will be used by this provider.\n * - If not given, a new `GlobalState` instance will be created and used.\n */\nexport default function GlobalStateProvider({\n children,\n initialState,\n ssrContext,\n stateProxy,\n}) {\n const state = useRef();\n if (!state.current) {\n if (stateProxy instanceof GlobalState) state.current = stateProxy;\n else if (stateProxy) state.current = getGlobalState();\n else state.current = new GlobalState(initialState, ssrContext);\n }\n return (\n <context.Provider value={state.current}>\n {children}\n </context.Provider>\n );\n}\n"],"mappings":"AAAA;;AAEA,SAASA,aAAa,EAAEC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AAEzD,OAAOC,WAAW;AAAsB;AAExC,MAAMC,OAAO,gBAAGJ,aAAa,EAAE;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,cAAc,GAAG;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,WAAW,GAAGL,UAAU,CAACG,OAAO,CAAC;EACvC;EACA,IAAI,CAACE,WAAW,EAAE,MAAM,IAAIC,KAAK,CAAC,6BAA6B,CAAC;EAChE,OAAOD,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,aAAa,GAAgC;EAAA,IAA/BC,sBAAsB,uEAAG,IAAI;EACzD,MAAM;IAAEC;EAAW,CAAC,GAAGL,cAAc,EAAE;EACvC,IAAI,CAACK,UAAU,IAAID,sBAAsB,EAAE;IACzC,MAAM,IAAIF,KAAK,CAAC,sBAAsB,CAAC;EACzC;EACA,OAAOG,UAAU;AACnB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,mBAAmB,OAKxC;EAAA,IALyC;IAC1CC,QAAQ;IACRC,YAAY;IACZH,UAAU;IACVI;EACF,CAAC;EACC,MAAMC,KAAK,GAAGb,MAAM,EAAE;EACtB,IAAI,CAACa,KAAK,CAACC,OAAO,EAAE;IAClB,IAAIF,UAAU,YAAYX,WAAW,EAAEY,KAAK,CAACC,OAAO,GAAGF,UAAU,CAAC,KAC7D,IAAIA,UAAU,EAAEC,KAAK,CAACC,OAAO,GAAGX,cAAc,EAAE,CAAC,KACjDU,KAAK,CAACC,OAAO,GAAG,IAAIb,WAAW,CAACU,YAAY,EAAEH,UAAU,CAAC;EAChE;EACA,oBACE,KAAC,OAAO,CAAC,QAAQ;IAAC,KAAK,EAAEK,KAAK,CAACC,OAAQ;IAAA,UACpCJ;EAAQ,EACQ;AAEvB"}
@@ -3,15 +3,8 @@
3
3
  // are still in a wide use, this polyfill is added here, and it is to be dropped
4
4
  // some time later.
5
5
  if (!Promise.allSettled) {
6
- Promise.allSettled = function (promises) {
7
- return Promise.all(promises.map(function (p) {
8
- return p instanceof Promise ? p.finally(function () {
9
- return null;
10
- }) : p;
11
- }));
12
- };
6
+ Promise.allSettled = promises => Promise.all(promises.map(p => p instanceof Promise ? p.finally(() => null) : p));
13
7
  }
14
-
15
8
  export { default as GlobalStateProvider, getGlobalState, getSsrContext } from "./GlobalStateProvider";
16
9
  export { default as useAsyncCollection } from "./useAsyncCollection";
17
10
  export { default as useAsyncData } from "./useAsyncData";
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.js"],"names":["Promise","allSettled","promises","all","map","p","finally","default","GlobalStateProvider","getGlobalState","getSsrContext","useAsyncCollection","useAsyncData","useGlobalState"],"mappings":"AAAA;AACA;AACA;AACA;AACA,IAAI,CAACA,OAAO,CAACC,UAAb,EAAyB;AACvBD,EAAAA,OAAO,CAACC,UAAR,GAAqB,UAACC,QAAD;AAAA,WAAcF,OAAO,CAACG,GAAR,CACjCD,QAAQ,CAACE,GAAT,CAAa,UAACC,CAAD;AAAA,aAAQA,CAAC,YAAYL,OAAb,GAAuBK,CAAC,CAACC,OAAF,CAAU;AAAA,eAAM,IAAN;AAAA,OAAV,CAAvB,GAA+CD,CAAvD;AAAA,KAAb,CADiC,CAAd;AAAA,GAArB;AAGD;;AAED,SACEE,OAAO,IAAIC,mBADb,EAEEC,cAFF,EAGEC,aAHF;AAMA,SAASH,OAAO,IAAII,kBAApB;AACA,SAASJ,OAAO,IAAIK,YAApB;AACA,SAASL,OAAO,IAAIM,cAApB","sourcesContent":["// TODO: This is a temporary polyfill for `Promise.allSettled(..)` method,\n// which is supported natively by NodeJS >= v12.9.0. As earlier NodeJS version\n// are still in a wide use, this polyfill is added here, and it is to be dropped\n// some time later.\nif (!Promise.allSettled) {\n Promise.allSettled = (promises) => Promise.all(\n promises.map((p) => (p instanceof Promise ? p.finally(() => null) : p)),\n );\n}\n\nexport {\n default as GlobalStateProvider,\n getGlobalState,\n getSsrContext,\n} from './GlobalStateProvider';\n\nexport { default as useAsyncCollection } from './useAsyncCollection';\nexport { default as useAsyncData } from './useAsyncData';\nexport { default as useGlobalState } from './useGlobalState';\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":["Promise","allSettled","promises","all","map","p","finally","default","GlobalStateProvider","getGlobalState","getSsrContext","useAsyncCollection","useAsyncData","useGlobalState"],"sources":["../../src/index.js"],"sourcesContent":["// TODO: This is a temporary polyfill for `Promise.allSettled(..)` method,\n// which is supported natively by NodeJS >= v12.9.0. As earlier NodeJS version\n// are still in a wide use, this polyfill is added here, and it is to be dropped\n// some time later.\nif (!Promise.allSettled) {\n Promise.allSettled = (promises) => Promise.all(\n promises.map((p) => (p instanceof Promise ? p.finally(() => null) : p)),\n );\n}\n\nexport {\n default as GlobalStateProvider,\n getGlobalState,\n getSsrContext,\n} from './GlobalStateProvider';\n\nexport { default as useAsyncCollection } from './useAsyncCollection';\nexport { default as useAsyncData } from './useAsyncData';\nexport { default as useGlobalState } from './useGlobalState';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,IAAI,CAACA,OAAO,CAACC,UAAU,EAAE;EACvBD,OAAO,CAACC,UAAU,GAAIC,QAAQ,IAAKF,OAAO,CAACG,GAAG,CAC5CD,QAAQ,CAACE,GAAG,CAAEC,CAAC,IAAMA,CAAC,YAAYL,OAAO,GAAGK,CAAC,CAACC,OAAO,CAAC,MAAM,IAAI,CAAC,GAAGD,CAAE,CAAC,CACxE;AACH;AAEA,SACEE,OAAO,IAAIC,mBAAmB,EAC9BC,cAAc,EACdC,aAAa;AAGf,SAASH,OAAO,IAAII,kBAAkB;AACtC,SAASJ,OAAO,IAAIK,YAAY;AAChC,SAASL,OAAO,IAAIM,cAAc"}
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Loads and uses an item in an async collection.
3
3
  */
4
+
4
5
  import useAsyncData from "./useAsyncData";
6
+
5
7
  /**
6
8
  * Resolves and stores at the given `path` of global state elements of
7
9
  * an asynchronous data collection. In other words, it is an auxiliar wrapper
@@ -48,12 +50,9 @@ import useAsyncData from "./useAsyncData";
48
50
  * _e.g._ {@link useGlobalState}, but doing so you may interfere with related
49
51
  * `useAsyncData()` hooks logic.
50
52
  */
51
-
52
53
  export default function useAsyncCollection(id, path, loader) {
53
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
54
- var itemPath = path ? "".concat(path, ".").concat(id) : id;
55
- return useAsyncData(itemPath, function (oldData) {
56
- return loader(id, oldData);
57
- }, options);
54
+ let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
55
+ const itemPath = path ? `${path}.${id}` : id;
56
+ return useAsyncData(itemPath, oldData => loader(id, oldData), options);
58
57
  }
59
58
  //# sourceMappingURL=useAsyncCollection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/useAsyncCollection.js"],"names":["useAsyncData","useAsyncCollection","id","path","loader","options","itemPath","oldData"],"mappings":"AAAA;AACA;AACA;AAEA,OAAOA,YAAP;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,kBAAT,CACbC,EADa,EAEbC,IAFa,EAGbC,MAHa,EAKb;AAAA,MADAC,OACA,uEADU,EACV;AACA,MAAMC,QAAQ,GAAGH,IAAI,aAAMA,IAAN,cAAcD,EAAd,IAAqBA,EAA1C;AACA,SAAOF,YAAY,CAACM,QAAD,EAAW,UAACC,OAAD;AAAA,WAAaH,MAAM,CAACF,EAAD,EAAKK,OAAL,CAAnB;AAAA,GAAX,EAA6CF,OAA7C,CAAnB;AACD","sourcesContent":["/**\n * Loads and uses an item in an async collection.\n */\n\nimport useAsyncData from './useAsyncData';\n\n/**\n * Resolves and stores at the given `path` of global state elements of\n * an asynchronous data collection. In other words, it is an auxiliar wrapper\n * around {@link useAsyncData}, which uses a loader which resolves to different\n * data, based on ID argument passed in, and stores data fetched for different\n * IDs in the state.\n * @param {string} id ID of the collection item to load & use.\n * @param {string} path The global state path where entire collection should be\n * stored.\n * @param {AsyncCollectionLoader} loader A loader function, which takes an\n * ID of data to load, and resolves to the corresponding data.\n * @param {object} [options] Additional options.\n * @param {any[]} [options.deps=[]] An array of dependencies, which trigger\n * data reload when changed. Given dependency changes are watched shallowly\n * (similarly to the standard React's\n * [useEffect()](https://reactjs.org/docs/hooks-reference.html#useeffect)).\n * @param {boolean} [options.noSSR] If `true`, this hook won't load data during\n * server-side rendering.\n * @param {number} [options.garbageCollectAge=maxage] The maximum age of data\n * (in milliseconds), after which they are dropped from the state when the last\n * component referencing them via `useAsyncData()` hook unmounts. Defaults to\n * `maxage` option value.\n * @param {number} [options.maxage=5 x 60 x 1000] The maximum age of\n * data (in milliseconds) acceptable to the hook's caller. If loaded data are\n * older than this value, `null` is returned instead. Defaults to 5 minutes.\n * @param {number} [options.refreshAge=maxage] The maximum age of data\n * (in milliseconds), after which their refreshment will be triggered when\n * any component referencing them via `useAsyncData()` hook (re-)renders.\n * Defaults to `maxage` value.\n * @return {{\n * data: any,\n * loading: boolean,\n * timestamp: number\n * }} Returns an object with three fields: `data` holds the actual result of\n * last `loader` invokation, if any, and if satisfies `maxage` limit; `loading`\n * is a boolean flag, which is `true` if data are being loaded (the hook is\n * waiting for `loader` function resolution); `timestamp` (in milliseconds)\n * is Unix timestamp of related data currently loaded into the global state.\n *\n * Note that loaded data, if any, are stored at the given `path` of global state\n * along with related meta-information, using slightly different state segment\n * structure (see {@link AsyncDataEnvelope}). That segment of the global state\n * can be accessed, and even modified using other hooks,\n * _e.g._ {@link useGlobalState}, but doing so you may interfere with related\n * `useAsyncData()` hooks logic.\n */\nexport default function useAsyncCollection(\n id,\n path,\n loader,\n options = {},\n) {\n const itemPath = path ? `${path}.${id}` : id;\n return useAsyncData(itemPath, (oldData) => loader(id, oldData), options);\n}\n"],"file":"useAsyncCollection.js"}
1
+ {"version":3,"file":"useAsyncCollection.js","names":["useAsyncData","useAsyncCollection","id","path","loader","options","itemPath","oldData"],"sources":["../../src/useAsyncCollection.js"],"sourcesContent":["/**\n * Loads and uses an item in an async collection.\n */\n\nimport useAsyncData from './useAsyncData';\n\n/**\n * Resolves and stores at the given `path` of global state elements of\n * an asynchronous data collection. In other words, it is an auxiliar wrapper\n * around {@link useAsyncData}, which uses a loader which resolves to different\n * data, based on ID argument passed in, and stores data fetched for different\n * IDs in the state.\n * @param {string} id ID of the collection item to load & use.\n * @param {string} path The global state path where entire collection should be\n * stored.\n * @param {AsyncCollectionLoader} loader A loader function, which takes an\n * ID of data to load, and resolves to the corresponding data.\n * @param {object} [options] Additional options.\n * @param {any[]} [options.deps=[]] An array of dependencies, which trigger\n * data reload when changed. Given dependency changes are watched shallowly\n * (similarly to the standard React's\n * [useEffect()](https://reactjs.org/docs/hooks-reference.html#useeffect)).\n * @param {boolean} [options.noSSR] If `true`, this hook won't load data during\n * server-side rendering.\n * @param {number} [options.garbageCollectAge=maxage] The maximum age of data\n * (in milliseconds), after which they are dropped from the state when the last\n * component referencing them via `useAsyncData()` hook unmounts. Defaults to\n * `maxage` option value.\n * @param {number} [options.maxage=5 x 60 x 1000] The maximum age of\n * data (in milliseconds) acceptable to the hook's caller. If loaded data are\n * older than this value, `null` is returned instead. Defaults to 5 minutes.\n * @param {number} [options.refreshAge=maxage] The maximum age of data\n * (in milliseconds), after which their refreshment will be triggered when\n * any component referencing them via `useAsyncData()` hook (re-)renders.\n * Defaults to `maxage` value.\n * @return {{\n * data: any,\n * loading: boolean,\n * timestamp: number\n * }} Returns an object with three fields: `data` holds the actual result of\n * last `loader` invokation, if any, and if satisfies `maxage` limit; `loading`\n * is a boolean flag, which is `true` if data are being loaded (the hook is\n * waiting for `loader` function resolution); `timestamp` (in milliseconds)\n * is Unix timestamp of related data currently loaded into the global state.\n *\n * Note that loaded data, if any, are stored at the given `path` of global state\n * along with related meta-information, using slightly different state segment\n * structure (see {@link AsyncDataEnvelope}). That segment of the global state\n * can be accessed, and even modified using other hooks,\n * _e.g._ {@link useGlobalState}, but doing so you may interfere with related\n * `useAsyncData()` hooks logic.\n */\nexport default function useAsyncCollection(\n id,\n path,\n loader,\n options = {},\n) {\n const itemPath = path ? `${path}.${id}` : id;\n return useAsyncData(itemPath, (oldData) => loader(id, oldData), options);\n}\n"],"mappings":"AAAA;AACA;AACA;;AAEA,OAAOA,YAAY;;AAEnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkB,CACxCC,EAAE,EACFC,IAAI,EACJC,MAAM,EAEN;EAAA,IADAC,OAAO,uEAAG,CAAC,CAAC;EAEZ,MAAMC,QAAQ,GAAGH,IAAI,GAAI,GAAEA,IAAK,IAAGD,EAAG,EAAC,GAAGA,EAAE;EAC5C,OAAOF,YAAY,CAACM,QAAQ,EAAGC,OAAO,IAAKH,MAAM,CAACF,EAAE,EAAEK,OAAO,CAAC,EAAEF,OAAO,CAAC;AAC1E"}