@dr.pogodin/react-global-state 0.8.3 → 0.9.0
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/build/module/GlobalState.js +125 -56
- package/build/module/GlobalState.js.map +1 -1
- package/build/module/GlobalStateProvider.js +5 -17
- package/build/module/GlobalStateProvider.js.map +1 -1
- package/build/module/index.js.map +1 -1
- package/build/module/useAsyncCollection.js.map +1 -1
- package/build/module/useAsyncData.js +11 -14
- package/build/module/useAsyncData.js.map +1 -1
- package/build/module/useGlobalState.js +43 -57
- package/build/module/useGlobalState.js.map +1 -1
- package/build/module/utils.js.map +1 -1
- package/build/node/GlobalState.js +85 -62
- package/build/node/GlobalState.js.map +1 -1
- package/build/node/GlobalStateProvider.js +5 -9
- package/build/node/GlobalStateProvider.js.map +1 -1
- package/build/node/index.js.map +1 -1
- package/build/node/useAsyncCollection.js.map +1 -1
- package/build/node/useAsyncData.js +11 -14
- package/build/node/useAsyncData.js.map +1 -1
- package/build/node/useGlobalState.js +36 -45
- package/build/node/useGlobalState.js.map +1 -1
- package/build/node/utils.js.map +1 -1
- package/package.json +18 -18
|
@@ -2,24 +2,30 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
4
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _classPrivateFieldGet from "@babel/runtime/helpers/classPrivateFieldGet";
|
|
6
|
+
import _classPrivateFieldSet from "@babel/runtime/helpers/classPrivateFieldSet";
|
|
5
7
|
|
|
6
8
|
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
9
|
|
|
8
10
|
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
11
|
|
|
10
|
-
|
|
12
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
13
|
+
|
|
14
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
15
|
+
|
|
16
|
+
import { cloneDeep, get as _get, isFunction, isObject, isNil, set as _set, toPath } from 'lodash';
|
|
11
17
|
import { isDebugMode } from "./utils";
|
|
12
18
|
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
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
var _initialState = /*#__PURE__*/new WeakMap();
|
|
21
|
+
|
|
22
|
+
var _nextNotifierId = /*#__PURE__*/new WeakMap();
|
|
23
|
+
|
|
24
|
+
var _ssrContext = /*#__PURE__*/new WeakMap();
|
|
25
|
+
|
|
26
|
+
var _currentState = /*#__PURE__*/new WeakMap();
|
|
27
|
+
|
|
28
|
+
var _watchers = /*#__PURE__*/new WeakMap();
|
|
23
29
|
|
|
24
30
|
var GlobalState = /*#__PURE__*/function () {
|
|
25
31
|
/**
|
|
@@ -30,16 +36,43 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
30
36
|
function GlobalState(initialState, ssrContext) {
|
|
31
37
|
_classCallCheck(this, GlobalState);
|
|
32
38
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
_classPrivateFieldInitSpec(this, _initialState, {
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
_classPrivateFieldInitSpec(this, _nextNotifierId, {
|
|
45
|
+
writable: true,
|
|
46
|
+
value: null
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
_classPrivateFieldInitSpec(this, _ssrContext, {
|
|
50
|
+
writable: true,
|
|
51
|
+
value: void 0
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
_classPrivateFieldInitSpec(this, _currentState, {
|
|
55
|
+
writable: true,
|
|
56
|
+
value: void 0
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
_classPrivateFieldInitSpec(this, _watchers, {
|
|
60
|
+
writable: true,
|
|
61
|
+
value: []
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
_classPrivateFieldSet(this, _currentState, initialState);
|
|
65
|
+
|
|
66
|
+
_classPrivateFieldSet(this, _initialState, initialState);
|
|
37
67
|
|
|
38
68
|
if (ssrContext) {
|
|
69
|
+
/* eslint-disable no-param-reassign */
|
|
39
70
|
ssrContext.dirty = false;
|
|
40
71
|
ssrContext.pending = [];
|
|
41
|
-
ssrContext.state = this
|
|
42
|
-
|
|
72
|
+
ssrContext.state = _classPrivateFieldGet(this, _currentState);
|
|
73
|
+
/* eslint-enable no-param-reassign */
|
|
74
|
+
|
|
75
|
+
_classPrivateFieldSet(this, _ssrContext, ssrContext);
|
|
43
76
|
}
|
|
44
77
|
|
|
45
78
|
if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
|
|
@@ -51,22 +84,40 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
51
84
|
console.groupEnd();
|
|
52
85
|
/* eslint-enable no-console */
|
|
53
86
|
}
|
|
54
|
-
/* eslint-enable no-param-reassign */
|
|
55
|
-
|
|
56
87
|
}
|
|
57
88
|
/**
|
|
58
|
-
* Gets
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
89
|
+
* Gets current or initial value at the specified "path" of the global state.
|
|
90
|
+
* Allows to get the entire global state, and automatically set default value
|
|
91
|
+
* at the "path".
|
|
92
|
+
* @param {string} [path] Dot-delimitered state path. Pass it "null",
|
|
93
|
+
* or "undefined" to refer the entire global state.
|
|
94
|
+
* @param {object} [options={}] Additional options.
|
|
95
|
+
* @param {boolean} [options.initialState] If "true" the value will be read
|
|
96
|
+
* from the initial state instead of the current one.
|
|
97
|
+
* @param {any} [options.initialValue] If the value read from the "path" is
|
|
98
|
+
* "undefined", this "initialValue" will be returned instead. In such case
|
|
99
|
+
* "initialValue" will also be written to the "path" of the current global
|
|
100
|
+
* state (no matter "initialState" flag), if "undefined" is stored there.
|
|
101
|
+
* @return {any} Retrieved value.
|
|
63
102
|
*/
|
|
64
103
|
|
|
65
104
|
|
|
66
105
|
_createClass(GlobalState, [{
|
|
67
106
|
key: "get",
|
|
68
107
|
value: function get(path) {
|
|
69
|
-
|
|
108
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
109
|
+
initialState = _ref.initialState,
|
|
110
|
+
initialValue = _ref.initialValue;
|
|
111
|
+
|
|
112
|
+
var state = initialState ? _classPrivateFieldGet(this, _initialState) : _classPrivateFieldGet(this, _currentState);
|
|
113
|
+
var value = isNil(path) ? state : _get(state, path);
|
|
114
|
+
|
|
115
|
+
if (value === undefined && initialValue !== undefined) {
|
|
116
|
+
value = isFunction(initialValue) ? initialValue() : initialValue;
|
|
117
|
+
if (!initialState || this.get(path) === undefined) this.set(path, value);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return value;
|
|
70
121
|
}
|
|
71
122
|
/**
|
|
72
123
|
* Writes the `value` to given global state `path`.
|
|
@@ -81,9 +132,7 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
81
132
|
value: function set(path, value) {
|
|
82
133
|
var _this = this;
|
|
83
134
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (value !== _get(this, p)) {
|
|
135
|
+
if (value !== this.get(path)) {
|
|
87
136
|
if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
|
|
88
137
|
/* eslint-disable no-console */
|
|
89
138
|
console.groupCollapsed("ReactGlobalState update. Path: \"".concat(path || '', "\""));
|
|
@@ -91,39 +140,51 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
91
140
|
/* eslint-enable no-console */
|
|
92
141
|
}
|
|
93
142
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
143
|
+
if (isNil(path)) _classPrivateFieldSet(this, _currentState, value);else {
|
|
144
|
+
var root = {
|
|
145
|
+
state: _classPrivateFieldGet(this, _currentState)
|
|
146
|
+
};
|
|
147
|
+
var segIdx = 0;
|
|
148
|
+
var pos = root;
|
|
149
|
+
var pathSegments = toPath("state.".concat(path));
|
|
150
|
+
|
|
151
|
+
for (; segIdx < pathSegments.length - 1; segIdx += 1) {
|
|
152
|
+
var seg = pathSegments[segIdx];
|
|
153
|
+
var next = pos[seg];
|
|
154
|
+
if (Array.isArray(next)) pos[seg] = _toConsumableArray(next);else if (isObject(next)) pos[seg] = _objectSpread({}, next);else {
|
|
155
|
+
// We arrived to a state sub-segment, where the remaining part of
|
|
156
|
+
// the update path does not exist yet. We rely on lodash's set()
|
|
157
|
+
// function to create the remaining path, and set the value.
|
|
158
|
+
_set(pos, pathSegments.slice(segIdx), value);
|
|
159
|
+
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
pos = pos[seg];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (segIdx === pathSegments.length - 1) {
|
|
166
|
+
pos[pathSegments[segIdx]] = value;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
_classPrivateFieldSet(this, _currentState, root.state);
|
|
170
|
+
}
|
|
110
171
|
|
|
111
|
-
if (this
|
|
112
|
-
this.
|
|
113
|
-
this.
|
|
114
|
-
} else if (!this
|
|
115
|
-
this
|
|
116
|
-
_this
|
|
172
|
+
if (_classPrivateFieldGet(this, _ssrContext)) {
|
|
173
|
+
_classPrivateFieldGet(this, _ssrContext).dirty = true;
|
|
174
|
+
_classPrivateFieldGet(this, _ssrContext).state = _classPrivateFieldGet(this, _currentState);
|
|
175
|
+
} else if (!_classPrivateFieldGet(this, _nextNotifierId)) {
|
|
176
|
+
_classPrivateFieldSet(this, _nextNotifierId, setTimeout(function () {
|
|
177
|
+
_classPrivateFieldSet(_this, _nextNotifierId, null);
|
|
117
178
|
|
|
118
|
-
_toConsumableArray(_this
|
|
179
|
+
_toConsumableArray(_classPrivateFieldGet(_this, _watchers)).forEach(function (w) {
|
|
119
180
|
return w();
|
|
120
181
|
});
|
|
121
|
-
});
|
|
182
|
+
}));
|
|
122
183
|
}
|
|
123
184
|
|
|
124
185
|
if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
|
|
125
186
|
/* eslint-disable no-console */
|
|
126
|
-
console.log('New state:', cloneDeep(this
|
|
187
|
+
console.log('New state:', cloneDeep(_classPrivateFieldGet(this, _currentState)));
|
|
127
188
|
console.groupEnd();
|
|
128
189
|
/* eslint-enable no-console */
|
|
129
190
|
}
|
|
@@ -142,8 +203,10 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
142
203
|
}, {
|
|
143
204
|
key: "unWatch",
|
|
144
205
|
value: function unWatch(callback) {
|
|
145
|
-
if (this
|
|
146
|
-
|
|
206
|
+
if (_classPrivateFieldGet(this, _ssrContext)) throw new Error(ERR_NO_SSR_WATCH);
|
|
207
|
+
|
|
208
|
+
var watchers = _classPrivateFieldGet(this, _watchers);
|
|
209
|
+
|
|
147
210
|
var pos = watchers.indexOf(callback);
|
|
148
211
|
|
|
149
212
|
if (pos >= 0) {
|
|
@@ -151,6 +214,11 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
151
214
|
watchers.pop();
|
|
152
215
|
}
|
|
153
216
|
}
|
|
217
|
+
}, {
|
|
218
|
+
key: "ssrContext",
|
|
219
|
+
get: function get() {
|
|
220
|
+
return _classPrivateFieldGet(this, _ssrContext);
|
|
221
|
+
}
|
|
154
222
|
/**
|
|
155
223
|
* Subscribes `callback` to watch state updates; no operation if
|
|
156
224
|
* `callback` is already subscribed to this state instance.
|
|
@@ -165,8 +233,9 @@ var GlobalState = /*#__PURE__*/function () {
|
|
|
165
233
|
}, {
|
|
166
234
|
key: "watch",
|
|
167
235
|
value: function watch(callback) {
|
|
168
|
-
if (this
|
|
169
|
-
|
|
236
|
+
if (_classPrivateFieldGet(this, _ssrContext)) throw new Error(ERR_NO_SSR_WATCH);
|
|
237
|
+
|
|
238
|
+
var watchers = _classPrivateFieldGet(this, _watchers);
|
|
170
239
|
|
|
171
240
|
if (watchers.indexOf(callback) < 0) {
|
|
172
241
|
watchers.push(callback);
|
|
@@ -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,gB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,\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","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","callback","Error","watchers","indexOf","pop","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,SADF,EAEEC,GAAG,IAAHA,IAFF,EAGEC,UAHF,EAIEC,QAJF,EAKEC,KALF,EAMEC,GAAG,IAAHA,IANF,EAOEC,MAPF,QAQO,QARP;AAUA,SAASC,WAAT;AAEA,IAAMC,gBAAgB,GAAG,gDAAzB;;;;;;;;;;;;IAEqBC,W;EAWnB;AACF;AACA;AACA;AACA;EACE,qBAAYC,YAAZ,EAA0BC,UAA1B,EAAsC;IAAA;;IAAA;MAAA;MAAA;IAAA;;IAAA;MAAA;MAAA,OAbpB;IAaoB;;IAAA;MAAA;MAAA;IAAA;;IAAA;MAAA;MAAA;IAAA;;IAAA;MAAA;MAAA,OAP1B;IAO0B;;IACpC,2CAAqBD,YAArB;;IACA,2CAAqBA,YAArB;;IAEA,IAAIC,UAAJ,EAAgB;MACd;MACAA,UAAU,CAACC,KAAX,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CAAN;;MAEtB,IAAMkC,QAAQ,yBAAG,IAAH,YAAd;;MACA,IAAIA,QAAQ,CAACC,OAAT,CAAiBH,QAAjB,IAA6B,CAAjC,EAAoC;QAClCE,QAAQ,CAACG,IAAT,CAAcL,QAAd;MACD;IACF;;;;;;SAxKkB/B,W"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
|
|
3
1
|
/* eslint-disable react/prop-types */
|
|
4
|
-
import { createContext, useContext,
|
|
2
|
+
import { createContext, useContext, useRef } from 'react';
|
|
5
3
|
import GlobalState from "./GlobalState";
|
|
6
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
5
|
var context = /*#__PURE__*/createContext();
|
|
@@ -72,24 +70,14 @@ export default function GlobalStateProvider(_ref) {
|
|
|
72
70
|
initialState = _ref.initialState,
|
|
73
71
|
ssrContext = _ref.ssrContext,
|
|
74
72
|
stateProxy = _ref.stateProxy;
|
|
75
|
-
var state
|
|
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 */
|
|
73
|
+
var state = useRef();
|
|
81
74
|
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var _useState2 = _slicedToArray(_useState, 1);
|
|
86
|
-
|
|
87
|
-
state = _useState2[0];
|
|
75
|
+
if (!state.current) {
|
|
76
|
+
if (stateProxy instanceof GlobalState) state.current = stateProxy;else if (stateProxy) state.current = getGlobalState();else state.current = new GlobalState(initialState, ssrContext);
|
|
88
77
|
}
|
|
89
|
-
/* eslint-enable react-hooks/rules-of-hooks */
|
|
90
78
|
|
|
91
79
|
return /*#__PURE__*/_jsx(context.Provider, {
|
|
92
|
-
value: state,
|
|
80
|
+
value: state.current,
|
|
93
81
|
children: children
|
|
94
82
|
});
|
|
95
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 <GlobalStateProvider>} (hence the state) is missing.\n * @returns {SsrContext} SSR context.\n * @throws\n * - If current component has no parent {@link <GlobalStateProvider>}\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 <GlobalStateProvider>}.\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,aAAT,EAAwBC,UAAxB,EAAoCC,MAApC,QAAkD,OAAlD;AAEA,OAAOC,WAAP;;AAEA,IAAMC,OAAO,gBAAGJ,aAAa,EAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASK,cAAT,GAA0B;EAC/B;EACA;EACA;EACA;EACA;;EACA;EACA,IAAMC,WAAW,GAAGL,UAAU,CAACG,OAAD,CAA9B;EACA;;EACA,IAAI,CAACE,WAAL,EAAkB,MAAM,IAAIC,KAAJ,CAAU,6BAAV,CAAN;EAClB,OAAOD,WAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,aAAT,GAAsD;EAAA,IAA/BC,sBAA+B,uEAAN,IAAM;;EAC3D,sBAAuBJ,cAAc,EAArC;EAAA,IAAQK,UAAR,mBAAQA,UAAR;;EACA,IAAI,CAACA,UAAD,IAAeD,sBAAnB,EAA2C;IACzC,MAAM,IAAIF,KAAJ,CAAU,sBAAV,CAAN;EACD;;EACD,OAAOG,UAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,mBAAT,OAKZ;EAAA,IAJDC,QAIC,QAJDA,QAIC;EAAA,IAHDC,YAGC,QAHDA,YAGC;EAAA,IAFDH,UAEC,QAFDA,UAEC;EAAA,IADDI,UACC,QADDA,UACC;EACD,IAAMC,KAAK,GAAGb,MAAM,EAApB;;EACA,IAAI,CAACa,KAAK,CAACC,OAAX,EAAoB;IAClB,IAAIF,UAAU,YAAYX,WAA1B,EAAuCY,KAAK,CAACC,OAAN,GAAgBF,UAAhB,CAAvC,KACK,IAAIA,UAAJ,EAAgBC,KAAK,CAACC,OAAN,GAAgBX,cAAc,EAA9B,CAAhB,KACAU,KAAK,CAACC,OAAN,GAAgB,IAAIb,WAAJ,CAAgBU,YAAhB,EAA8BH,UAA9B,CAAhB;EACN;;EACD,oBACE,KAAC,OAAD,CAAS,QAAT;IAAkB,KAAK,EAAEK,KAAK,CAACC,OAA/B;IAAA,UACGJ;EADH,EADF;AAKD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,UAAb,EAAyB;EACvBD,OAAO,CAACC,UAAR,GAAqB,UAACC,QAAD;IAAA,OAAcF,OAAO,CAACG,GAAR,CACjCD,QAAQ,CAACE,GAAT,CAAa,UAACC,CAAD;MAAA,OAAQA,CAAC,YAAYL,OAAb,GAAuBK,CAAC,CAACC,OAAF,CAAU;QAAA,OAAM,IAAN;MAAA,CAAV,CAAvB,GAA+CD,CAAvD;IAAA,CAAb,CADiC,CAAd;EAAA,CAArB;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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,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;EAAA,IADAC,OACA,uEADU,EACV;EACA,IAAMC,QAAQ,GAAGH,IAAI,aAAMA,IAAN,cAAcD,EAAd,IAAqBA,EAA1C;EACA,OAAOF,YAAY,CAACM,QAAD,EAAW,UAACC,OAAD;IAAA,OAAaH,MAAM,CAACF,EAAD,EAAKK,OAAL,CAAnB;EAAA,CAAX,EAA6CF,OAA7C,CAAnB;AACD"}
|
|
@@ -161,17 +161,14 @@ export default function useAsyncData(path, loader) {
|
|
|
161
161
|
// because that way we'll have issues with SSR (see details below).
|
|
162
162
|
|
|
163
163
|
var globalState = getGlobalState();
|
|
164
|
-
var state = globalState.get(path
|
|
165
|
-
|
|
166
|
-
if (state === undefined) {
|
|
167
|
-
state = {
|
|
164
|
+
var state = globalState.get(path, {
|
|
165
|
+
initialValue: {
|
|
168
166
|
data: null,
|
|
169
167
|
numRefs: 0,
|
|
170
168
|
operationId: '',
|
|
171
169
|
timestamp: 0
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
175
172
|
|
|
176
173
|
if (globalState.ssrContext && !options.noSSR) {
|
|
177
174
|
if (!state.timestamp && !state.operationId) {
|
|
@@ -228,14 +225,14 @@ export default function useAsyncData(path, loader) {
|
|
|
228
225
|
// eslint-disable-line react-hooks/rules-of-hooks
|
|
229
226
|
if (!loadTriggered && deps.length) load(path, loader, globalState);
|
|
230
227
|
}, deps); // eslint-disable-line react-hooks/exhaustive-deps
|
|
231
|
-
}
|
|
232
|
-
// here, after the possible initialization of the loading operation, to take
|
|
233
|
-
// into effect the resulting loading state. This mostly ensures the correct
|
|
234
|
-
// SSR in the edge case when the loading starts, but times out, and incomplete
|
|
235
|
-
// render has to be served.
|
|
236
|
-
|
|
228
|
+
}
|
|
237
229
|
|
|
238
|
-
var _useGlobalState = useGlobalState(path
|
|
230
|
+
var _useGlobalState = useGlobalState(path, {
|
|
231
|
+
data: null,
|
|
232
|
+
numRefs: 0,
|
|
233
|
+
operationId: '',
|
|
234
|
+
timestamp: 0
|
|
235
|
+
}),
|
|
239
236
|
_useGlobalState2 = _slicedToArray(_useGlobalState, 1),
|
|
240
237
|
localState = _useGlobalState2[0];
|
|
241
238
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useAsyncData.js"],"names":["cloneDeep","useEffect","v4","uuid","getGlobalState","useGlobalState","isDebugMode","DEFAULT_MAXAGE","load","path","loader","globalState","oldData","opIdPrefix","process","env","NODE_ENV","console","log","operationId","operationIdPath","set","get","data","state","groupCollapsed","timestamp","Date","now","groupEnd","useAsyncData","options","garbageCollectAge","maxage","refreshAge","undefined","numRefs","ssrContext","noSSR","pending","push","numRefsPath","state2","loadTriggered","charAt","deps","length","localState","loading","Boolean"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAEA,SAASA,SAAT,QAA0B,QAA1B;AACA,SAASC,SAAT,QAA0B,OAA1B;AACA,SAASC,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA,SAASC,cAAT;AACA,OAAOC,cAAP;AACA,SAASC,WAAT;AAEA,IAAMC,cAAc,GAAG,IAAI,EAAJ,GAAS,IAAhC,C,CAAsC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;SACeC,I;;;AAsCf;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;AACA;AACA;AACA;AACA;;;;mEAxFA,iBAAoBC,IAApB,EAA0BC,MAA1B,EAAkCC,WAAlC,EAA+CC,OAA/C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAwDC,YAAAA,UAAxD,2DAAqE,GAArE;;AACE,gBAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,IAAyCV,WAAW,EAAxD,EAA4D;AAC1D;AACAW,cAAAA,OAAO,CAACC,GAAR,qEAC8DT,IAAI,IAAI,EADtE;AAGA;AACD;;AACKU,YAAAA,WARR,GAQsBN,UAAU,GAAGV,IAAI,EARvC;AASQiB,Y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Q,CAAT;AASA,QAAME,IAAI,GAAGd,OAAO,CAACc,IAAR,IAAgB,EAA7B;AACA5C,IAAAA,SAAS,CAAC,YAAM;AAAE;AAChB,UAAI,CAAC0C,aAAD,IAAkBE,IAAI,CAACC,MAA3B,EAAmCtC,IAAI,CAACC,IAAD,EAAOC,MAAP,EAAeC,WAAf,CAAJ;AACpC,KAFQ,EAENkC,IAFM,CAAT,CAtDK,CAwDK;AACX,GAnFD,CAqFA;AACA;AACA;AACA;AACA;;;AACA,wBAAqBxC,cAAc,CAACI,IAAD,CAAnC;AAAA;AAAA,MAAOsC,UAAP;;AAEA,SAAO;AACLxB,IAAAA,IAAI,EAAEU,MAAM,GAAGN,IAAI,CAACC,GAAL,KAAamB,UAAU,CAACrB,SAAjC,GAA6C,IAA7C,GAAoDqB,UAAU,CAACxB,IADhE;AAELyB,IAAAA,OAAO,EAAEC,OAAO,CAACF,UAAU,CAAC5B,WAAZ,CAFX;AAGLO,IAAAA,SAAS,EAAEqB,UAAU,CAACrB;AAHjB,GAAP;AAKD","sourcesContent":["/**\n * Loads and uses async data into the GlobalState path.\n */\n\nimport { cloneDeep } from 'lodash';\nimport { useEffect } from 'react';\nimport { v4 as uuid } from 'uuid';\n\nimport { getGlobalState } from './GlobalStateProvider';\nimport useGlobalState from './useGlobalState';\nimport { isDebugMode } from './utils';\n\nconst DEFAULT_MAXAGE = 5 * 60 * 1000; // 5 minutes.\n\n/**\n * Executes the data loading operation.\n * @param {string} path Data segment path inside the global state.\n * @param {function} loader Data loader.\n * @param {GlobalState} globalState The global state instance.\n * @param {any} [oldData] Optional. Previously fetched data, currently stored in\n * the state, if already fetched by the caller; otherwise, they will be fetched\n * by the load() function itself.\n * @param {string} [opIdPrefix='C'] operationId prefix to use, which should be\n * 'C' at the client-side (default), or 'S' at the server-side (within SSR\n * context).\n * @return {Promise} Resolves once the operation is done.\n * @ignore\n */\nasync function load(path, loader, globalState, oldData, opIdPrefix = 'C') {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log(\n `ReactGlobalState: useAsyncData data (re-)loading. Path: \"${path || ''}\"`,\n );\n /* eslint-enable no-console */\n }\n const operationId = opIdPrefix + uuid();\n const operationIdPath = path ? `${path}.operationId` : 'operationId';\n globalState.set(operationIdPath, operationId);\n const data = await loader(oldData || globalState.get(path).data);\n const state = globalState.get(path);\n if (operationId === state.operationId) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState: useAsyncData data (re-)loaded. Path: \"${\n path || ''\n }\"`,\n );\n console.log('Data:', cloneDeep(data));\n /* eslint-enable no-console */\n }\n globalState.set(path, {\n ...state,\n data,\n operationId: '',\n timestamp: Date.now(),\n });\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n}\n\n/**\n * Resolves asynchronous data, and stores them at given `path` of global\n * state. When multiple components rely on asynchronous data at the same `path`,\n * the data are resolved once, and reused until their age is within specified\n * bounds. Once the data are stale, the hook allows to refresh them. It also\n * garbage-collects stale data from the global state when the last component\n * relying on them is unmounted.\n * @param {string} path Dot-delimitered state path, where data envelop is\n * stored.\n * @param {AsyncDataLoader} loader Asynchronous function which resolves (loads)\n * data, which should be stored at the global state `path`. When multiple\n * components\n * use `useAsyncData()` hook for the same `path`, the library assumes that all\n * hook instances are called with the same `loader` (_i.e._ whichever of these\n * loaders is used to resolve async data, the result is acceptable to be reused\n * in all related components).\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 useAsyncData(\n path,\n loader,\n options = {},\n) {\n let { garbageCollectAge, maxage, refreshAge } = options;\n if (maxage === undefined) maxage = DEFAULT_MAXAGE;\n if (refreshAge === undefined) refreshAge = maxage;\n if (garbageCollectAge === undefined) garbageCollectAge = maxage;\n\n // Note: here we can't depend on useGlobalState() to init the initial value,\n // because that way we'll have issues with SSR (see details below).\n const globalState = getGlobalState();\n let state = globalState.get(path);\n if (state === undefined) {\n state = {\n data: null,\n numRefs: 0,\n operationId: '',\n timestamp: 0,\n };\n globalState.set(path, state);\n }\n\n if (globalState.ssrContext && !options.noSSR) {\n if (!state.timestamp && !state.operationId) {\n globalState.ssrContext.pending.push(\n load(path, loader, globalState, state.data, 'S'),\n );\n }\n } else {\n // This takes care about the client-side reference counting, and garbage\n // collection.\n //\n // Note: the Rules of Hook below are violated by conditional call to a hook,\n // but as the condition is actually server-side or client-side environment,\n // it is effectively non-conditional at the runtime.\n //\n // TODO: Though, maybe there is a way to refactor it into a cleaner code.\n // The same applies to other useEffect() hooks below.\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n const numRefsPath = path ? `${path}.numRefs` : 'numRefs';\n const numRefs = globalState.get(numRefsPath);\n globalState.set(numRefsPath, numRefs + 1);\n return () => {\n const state2 = globalState.get(path);\n if (\n state2.numRefs === 1\n && garbageCollectAge < Date.now() - state2.timestamp\n ) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log(\n `ReactGlobalState - useAsyncData garbage collected at path ${\n path || ''\n }`,\n );\n /* eslint-enable no-console */\n }\n globalState.set(path, {\n ...state2,\n data: null,\n numRefs: 0,\n timestamp: 0,\n });\n } else globalState.set(numRefsPath, state2.numRefs - 1);\n };\n }, [garbageCollectAge, globalState, path]);\n\n // Note: a bunch of Rules of Hooks ignored belows because in our very\n // special case the otherwise wrong behavior is actually what we need.\n\n // Data loading and refreshing.\n let loadTriggered = false;\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n const state2 = globalState.get(path);\n if (refreshAge < Date.now() - state2.timestamp\n && (!state2.operationId || state2.operationId.charAt() === 'S')) {\n load(path, loader, globalState, state2.data);\n loadTriggered = true; // eslint-disable-line react-hooks/exhaustive-deps\n }\n });\n\n const deps = options.deps || [];\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n if (!loadTriggered && deps.length) load(path, loader, globalState);\n }, deps); // eslint-disable-line react-hooks/exhaustive-deps\n }\n\n // Note: this subscription to updates of the global state segment must be\n // here, after the possible initialization of the loading operation, to take\n // into effect the resulting loading state. This mostly ensures the correct\n // SSR in the edge case when the loading starts, but times out, and incomplete\n // render has to be served.\n const [localState] = useGlobalState(path);\n\n return {\n data: maxage < Date.now() - localState.timestamp ? null : localState.data,\n loading: Boolean(localState.operationId),\n timestamp: localState.timestamp,\n };\n}\n"],"file":"useAsyncData.js"}
|
|
1
|
+
{"version":3,"file":"useAsyncData.js","names":["cloneDeep","useEffect","v4","uuid","getGlobalState","useGlobalState","isDebugMode","DEFAULT_MAXAGE","load","path","loader","globalState","oldData","opIdPrefix","process","env","NODE_ENV","console","log","operationId","operationIdPath","set","get","data","state","groupCollapsed","timestamp","Date","now","groupEnd","useAsyncData","options","garbageCollectAge","maxage","refreshAge","undefined","initialValue","numRefs","ssrContext","noSSR","pending","push","numRefsPath","state2","loadTriggered","charAt","deps","length","localState","loading","Boolean"],"sources":["../../src/useAsyncData.js"],"sourcesContent":["/**\n * Loads and uses async data into the GlobalState path.\n */\n\nimport { cloneDeep } from 'lodash';\nimport { useEffect } from 'react';\nimport { v4 as uuid } from 'uuid';\n\nimport { getGlobalState } from './GlobalStateProvider';\nimport useGlobalState from './useGlobalState';\nimport { isDebugMode } from './utils';\n\nconst DEFAULT_MAXAGE = 5 * 60 * 1000; // 5 minutes.\n\n/**\n * Executes the data loading operation.\n * @param {string} path Data segment path inside the global state.\n * @param {function} loader Data loader.\n * @param {GlobalState} globalState The global state instance.\n * @param {any} [oldData] Optional. Previously fetched data, currently stored in\n * the state, if already fetched by the caller; otherwise, they will be fetched\n * by the load() function itself.\n * @param {string} [opIdPrefix='C'] operationId prefix to use, which should be\n * 'C' at the client-side (default), or 'S' at the server-side (within SSR\n * context).\n * @return {Promise} Resolves once the operation is done.\n * @ignore\n */\nasync function load(path, loader, globalState, oldData, opIdPrefix = 'C') {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log(\n `ReactGlobalState: useAsyncData data (re-)loading. Path: \"${path || ''}\"`,\n );\n /* eslint-enable no-console */\n }\n const operationId = opIdPrefix + uuid();\n const operationIdPath = path ? `${path}.operationId` : 'operationId';\n globalState.set(operationIdPath, operationId);\n const data = await loader(oldData || globalState.get(path).data);\n const state = globalState.get(path);\n if (operationId === state.operationId) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState: useAsyncData data (re-)loaded. Path: \"${\n path || ''\n }\"`,\n );\n console.log('Data:', cloneDeep(data));\n /* eslint-enable no-console */\n }\n globalState.set(path, {\n ...state,\n data,\n operationId: '',\n timestamp: Date.now(),\n });\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n}\n\n/**\n * Resolves asynchronous data, and stores them at given `path` of global\n * state. When multiple components rely on asynchronous data at the same `path`,\n * the data are resolved once, and reused until their age is within specified\n * bounds. Once the data are stale, the hook allows to refresh them. It also\n * garbage-collects stale data from the global state when the last component\n * relying on them is unmounted.\n * @param {string} path Dot-delimitered state path, where data envelop is\n * stored.\n * @param {AsyncDataLoader} loader Asynchronous function which resolves (loads)\n * data, which should be stored at the global state `path`. When multiple\n * components\n * use `useAsyncData()` hook for the same `path`, the library assumes that all\n * hook instances are called with the same `loader` (_i.e._ whichever of these\n * loaders is used to resolve async data, the result is acceptable to be reused\n * in all related components).\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 useAsyncData(\n path,\n loader,\n options = {},\n) {\n let { garbageCollectAge, maxage, refreshAge } = options;\n if (maxage === undefined) maxage = DEFAULT_MAXAGE;\n if (refreshAge === undefined) refreshAge = maxage;\n if (garbageCollectAge === undefined) garbageCollectAge = maxage;\n\n // Note: here we can't depend on useGlobalState() to init the initial value,\n // because that way we'll have issues with SSR (see details below).\n const globalState = getGlobalState();\n const state = globalState.get(path, {\n initialValue: {\n data: null,\n numRefs: 0,\n operationId: '',\n timestamp: 0,\n },\n });\n\n if (globalState.ssrContext && !options.noSSR) {\n if (!state.timestamp && !state.operationId) {\n globalState.ssrContext.pending.push(\n load(path, loader, globalState, state.data, 'S'),\n );\n }\n } else {\n // This takes care about the client-side reference counting, and garbage\n // collection.\n //\n // Note: the Rules of Hook below are violated by conditional call to a hook,\n // but as the condition is actually server-side or client-side environment,\n // it is effectively non-conditional at the runtime.\n //\n // TODO: Though, maybe there is a way to refactor it into a cleaner code.\n // The same applies to other useEffect() hooks below.\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n const numRefsPath = path ? `${path}.numRefs` : 'numRefs';\n const numRefs = globalState.get(numRefsPath);\n globalState.set(numRefsPath, numRefs + 1);\n return () => {\n const state2 = globalState.get(path);\n if (\n state2.numRefs === 1\n && garbageCollectAge < Date.now() - state2.timestamp\n ) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log(\n `ReactGlobalState - useAsyncData garbage collected at path ${\n path || ''\n }`,\n );\n /* eslint-enable no-console */\n }\n globalState.set(path, {\n ...state2,\n data: null,\n numRefs: 0,\n timestamp: 0,\n });\n } else globalState.set(numRefsPath, state2.numRefs - 1);\n };\n }, [garbageCollectAge, globalState, path]);\n\n // Note: a bunch of Rules of Hooks ignored belows because in our very\n // special case the otherwise wrong behavior is actually what we need.\n\n // Data loading and refreshing.\n let loadTriggered = false;\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n const state2 = globalState.get(path);\n if (refreshAge < Date.now() - state2.timestamp\n && (!state2.operationId || state2.operationId.charAt() === 'S')) {\n load(path, loader, globalState, state2.data);\n loadTriggered = true; // eslint-disable-line react-hooks/exhaustive-deps\n }\n });\n\n const deps = options.deps || [];\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n if (!loadTriggered && deps.length) load(path, loader, globalState);\n }, deps); // eslint-disable-line react-hooks/exhaustive-deps\n }\n\n const [localState] = useGlobalState(path, {\n data: null,\n numRefs: 0,\n operationId: '',\n timestamp: 0,\n });\n\n return {\n data: maxage < Date.now() - localState.timestamp ? null : localState.data,\n loading: Boolean(localState.operationId),\n timestamp: localState.timestamp,\n };\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AAEA,SAASA,SAAT,QAA0B,QAA1B;AACA,SAASC,SAAT,QAA0B,OAA1B;AACA,SAASC,EAAE,IAAIC,IAAf,QAA2B,MAA3B;AAEA,SAASC,cAAT;AACA,OAAOC,cAAP;AACA,SAASC,WAAT;AAEA,IAAMC,cAAc,GAAG,IAAI,EAAJ,GAAS,IAAhC,C,CAAsC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;SACeC,I;;;AAsCf;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;A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