@dr.pogodin/react-global-state 0.9.0 → 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.
- package/build/module/GlobalState.js +107 -166
- package/build/module/GlobalState.js.map +1 -1
- package/build/module/GlobalStateProvider.js +17 -20
- package/build/module/GlobalStateProvider.js.map +1 -1
- package/build/module/index.js +1 -8
- package/build/module/index.js.map +1 -1
- package/build/module/useAsyncCollection.js +5 -6
- package/build/module/useAsyncCollection.js.map +1 -1
- package/build/module/useAsyncData.js +67 -106
- package/build/module/useAsyncData.js.map +1 -1
- package/build/module/useGlobalState.js +23 -32
- package/build/module/useGlobalState.js.map +1 -1
- package/build/module/utils.js.map +1 -1
- package/build/node/GlobalState.js +7 -28
- package/build/node/GlobalState.js.map +1 -1
- package/build/node/GlobalStateProvider.js +4 -16
- package/build/node/GlobalStateProvider.js.map +1 -1
- package/build/node/index.js +0 -8
- package/build/node/index.js.map +1 -1
- package/build/node/useAsyncCollection.js +0 -3
- package/build/node/useAsyncCollection.js.map +1 -1
- package/build/node/useAsyncData.js +14 -22
- package/build/node/useAsyncData.js.map +1 -1
- package/build/node/useGlobalState.js +0 -9
- package/build/node/useGlobalState.js.map +1 -1
- package/build/node/utils.js +0 -2
- package/build/node/utils.js.map +1 -1
- package/package.json +18 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalState.js","names":["ERR_NO_SSR_WATCH","GlobalState","initialState","nextNotifierId","ssrContext","currentState","watchers","constructor","dirty","pending","state","process","env","NODE_ENV","isDebugMode","msg","console","groupCollapsed","log","cloneDeep","groupEnd","get","path","initialValue","value","isNil","undefined","isFunction","set","root","segIdx","pos","pathSegments","toPath","length","seg","next","Array","isArray","isObject","slice","setTimeout","forEach","w","unWatch","callback","Error","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;;AAUA;;AAEA,MAAMA,gBAAgB,GAAG,gDAAzB;;AAEe,MAAMC,WAAN,CAAkB;EAC/B,CAACC,YAAD;EAEA,CAACC,cAAD,GAAkB,IAAlB;EAEA,CAACC,UAAD;EAEA,CAACC,YAAD;EAEA,CAACC,QAAD,GAAY,EAAZ;EAEA;AACF;AACA;AACA;AACA;;EACEC,WAAW,CAACL,YAAD,EAAeE,UAAf,EAA2B;IACpC,KAAK,CAACC,YAAN,GAAqBH,YAArB;IACA,KAAK,CAACA,YAAN,GAAqBA,YAArB;;IAEA,IAAIE,UAAJ,EAAgB;MACd;MACAA,UAAU,CAACI,KAAX,GAAmB,KAAnB;MACAJ,UAAU,CAACK,OAAX,GAAqB,EAArB;MACAL,UAAU,CAACM,KAAX,GAAmB,KAAK,CAACL,YAAzB;MACA;;MAEA,KAAK,CAACD,UAAN,GAAmBA,UAAnB;IACD;;IAED,IAAIO,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,IAAyC,IAAAC,kBAAA,GAA7C,EAA4D;MAC1D;MACA,IAAIC,GAAG,GAAG,8BAAV;MACA,IAAIX,UAAJ,EAAgBW,GAAG,IAAI,aAAP;MAChBC,OAAO,CAACC,cAAR,CAAuBF,GAAvB;MACAC,OAAO,CAACE,GAAR,CAAY,gBAAZ,EAA8B,IAA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;MAClCvC,QAAQ,CAAC4C,IAAT,CAAcL,QAAd;IACD;EACF;;AAxK8B"}
|
|
1
|
+
{"version":3,"file":"GlobalState.js","names":["ERR_NO_SSR_WATCH","GlobalState","initialState","nextNotifierId","ssrContext","currentState","watchers","constructor","dirty","pending","state","process","env","NODE_ENV","isDebugMode","msg","console","groupCollapsed","log","cloneDeep","groupEnd","get","path","initialValue","value","isNil","undefined","isFunction","set","root","segIdx","pos","pathSegments","toPath","length","seg","next","Array","isArray","isObject","slice","setTimeout","forEach","w","unWatch","callback","Error","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;AAUA;AAEA,MAAMA,gBAAgB,GAAG,gDAAgD;AAE1D,MAAMC,WAAW,CAAC;EAC/B,CAACC,YAAY;EAEb,CAACC,cAAc,GAAG,IAAI;EAEtB,CAACC,UAAU;EAEX,CAACC,YAAY;EAEb,CAACC,QAAQ,GAAG,EAAE;;EAEd;AACF;AACA;AACA;AACA;EACEC,WAAW,CAACL,YAAY,EAAEE,UAAU,EAAE;IACpC,IAAI,CAAC,CAACC,YAAY,GAAGH,YAAY;IACjC,IAAI,CAAC,CAACA,YAAY,GAAGA,YAAY;IAEjC,IAAIE,UAAU,EAAE;MAC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MyB,GAAG,GAAGzB,QAAQ,CAACyC,OAAO,CAACF,QAAQ,CAAC;IACtC,IAAId,GAAG,IAAI,CAAC,EAAE;MACZzB,QAAQ,CAACyB,GAAG,CAAC,GAAGzB,QAAQ,CAACA,QAAQ,CAAC4B,MAAM,GAAG,CAAC,CAAC;MAC7C5B,QAAQ,CAAC0C,GAAG,EAAE;IAChB;EACF;EAEA,IAAI5C,UAAU,GAAG;IAAE,OAAO,IAAI,CAAC,CAACA,UAAU;EAAE;;EAE5C;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE6C,KAAK,CAACJ,QAAQ,EAAE;IACd,IAAI,IAAI,CAAC,CAACzC,UAAU,EAAE,MAAM,IAAI0C,KAAK,CAAC9C,gBAAgB,CAAC;IAEvD,MAAMM,QAAQ,GAAG,IAAI,CAAC,CAACA,QAAQ;IAC/B,IAAIA,QAAQ,CAACyC,OAAO,CAACF,QAAQ,CAAC,GAAG,CAAC,EAAE;MAClCvC,QAAQ,CAAC4C,IAAI,CAACL,QAAQ,CAAC;IACzB;EACF;AACF;AAAC"}
|
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = GlobalStateProvider;
|
|
9
8
|
exports.getGlobalState = getGlobalState;
|
|
10
9
|
exports.getSsrContext = getSsrContext;
|
|
11
|
-
|
|
12
10
|
var _react = require("react");
|
|
13
|
-
|
|
14
11
|
var _GlobalState = _interopRequireDefault(require("./GlobalState"));
|
|
15
|
-
|
|
16
12
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
17
|
-
|
|
18
13
|
/* eslint-disable react/prop-types */
|
|
14
|
+
|
|
19
15
|
const context = /*#__PURE__*/(0, _react.createContext)();
|
|
16
|
+
|
|
20
17
|
/**
|
|
21
18
|
* Gets {@link GlobalState} instance from the context. In most cases
|
|
22
19
|
* you should use {@link useGlobalState}, and other hooks to interact with
|
|
23
20
|
* the global state, instead of accessing it directly.
|
|
24
21
|
* @return {GlobalState}
|
|
25
22
|
*/
|
|
26
|
-
|
|
27
23
|
function getGlobalState() {
|
|
28
24
|
// Here Rules of Hooks are violated because "getGlobalState()" does not follow
|
|
29
25
|
// convention that hook names should start with use... This is intentional in
|
|
30
26
|
// our case, as getGlobalState() hook is intended for advance scenarious,
|
|
31
27
|
// while the normal interaction with the global state should happen via
|
|
32
28
|
// another hook, useGlobalState().
|
|
33
|
-
|
|
34
29
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
35
30
|
const globalState = (0, _react.useContext)(context);
|
|
36
31
|
/* eslint-enable react-hooks/rules-of-hooks */
|
|
37
|
-
|
|
38
32
|
if (!globalState) throw new Error('Missing GlobalStateProvider');
|
|
39
33
|
return globalState;
|
|
40
34
|
}
|
|
35
|
+
|
|
41
36
|
/**
|
|
42
37
|
* @category Hooks
|
|
43
38
|
* @desc Gets SSR context.
|
|
@@ -52,19 +47,16 @@ function getGlobalState() {
|
|
|
52
47
|
* - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached
|
|
53
48
|
* to the global state provided by {@link <GlobalStateProvider>}.
|
|
54
49
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
57
50
|
function getSsrContext(throwWithoutSsrContext = true) {
|
|
58
51
|
const {
|
|
59
52
|
ssrContext
|
|
60
53
|
} = getGlobalState();
|
|
61
|
-
|
|
62
54
|
if (!ssrContext && throwWithoutSsrContext) {
|
|
63
55
|
throw new Error('No SSR context found');
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
return ssrContext;
|
|
67
58
|
}
|
|
59
|
+
|
|
68
60
|
/**
|
|
69
61
|
* Provides global state to its children.
|
|
70
62
|
* @prop {ReactNode} [children] Component children, which will be provided with
|
|
@@ -78,8 +70,6 @@ function getSsrContext(throwWithoutSsrContext = true) {
|
|
|
78
70
|
* - If `GlobalState` instance, it will be used by this provider.
|
|
79
71
|
* - If not given, a new `GlobalState` instance will be created and used.
|
|
80
72
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
73
|
function GlobalStateProvider({
|
|
84
74
|
children,
|
|
85
75
|
initialState,
|
|
@@ -87,11 +77,9 @@ function GlobalStateProvider({
|
|
|
87
77
|
stateProxy
|
|
88
78
|
}) {
|
|
89
79
|
const state = (0, _react.useRef)();
|
|
90
|
-
|
|
91
80
|
if (!state.current) {
|
|
92
81
|
if (stateProxy instanceof _GlobalState.default) state.current = stateProxy;else if (stateProxy) state.current = getGlobalState();else state.current = new _GlobalState.default(initialState, ssrContext);
|
|
93
82
|
}
|
|
94
|
-
|
|
95
83
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(context.Provider, {
|
|
96
84
|
value: state.current,
|
|
97
85
|
children: children
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GlobalStateProvider.js","names":["context","createContext","getGlobalState","globalState","useContext","Error","getSsrContext","throwWithoutSsrContext","ssrContext","GlobalStateProvider","children","initialState","stateProxy","state","useRef","current","GlobalState"],"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":"
|
|
1
|
+
{"version":3,"file":"GlobalStateProvider.js","names":["context","createContext","getGlobalState","globalState","useContext","Error","getSsrContext","throwWithoutSsrContext","ssrContext","GlobalStateProvider","children","initialState","stateProxy","state","useRef","current","GlobalState"],"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":";;;;;;;;;AAEA;AAEA;AAAwC;AAJxC;;AAMA,MAAMA,OAAO,gBAAG,IAAAC,oBAAa,GAAE;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,cAAc,GAAG;EAC/B;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,WAAW,GAAG,IAAAC,iBAAU,EAACJ,OAAO,CAAC;EACvC;EACA,IAAI,CAACG,WAAW,EAAE,MAAM,IAAIE,KAAK,CAAC,6BAA6B,CAAC;EAChE,OAAOF,WAAW;AACpB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,aAAa,CAACC,sBAAsB,GAAG,IAAI,EAAE;EAC3D,MAAM;IAAEC;EAAW,CAAC,GAAGN,cAAc,EAAE;EACvC,IAAI,CAACM,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;AACe,SAASC,mBAAmB,CAAC;EAC1CC,QAAQ;EACRC,YAAY;EACZH,UAAU;EACVI;AACF,CAAC,EAAE;EACD,MAAMC,KAAK,GAAG,IAAAC,aAAM,GAAE;EACtB,IAAI,CAACD,KAAK,CAACE,OAAO,EAAE;IAClB,IAAIH,UAAU,YAAYI,oBAAW,EAAEH,KAAK,CAACE,OAAO,GAAGH,UAAU,CAAC,KAC7D,IAAIA,UAAU,EAAEC,KAAK,CAACE,OAAO,GAAGb,cAAc,EAAE,CAAC,KACjDW,KAAK,CAACE,OAAO,GAAG,IAAIC,oBAAW,CAACL,YAAY,EAAEH,UAAU,CAAC;EAChE;EACA,oBACE,qBAAC,OAAO,CAAC,QAAQ;IAAC,KAAK,EAAEK,KAAK,CAACE,OAAQ;IAAA,UACpCL;EAAQ,EACQ;AAEvB"}
|
package/build/node/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -41,19 +40,12 @@ Object.defineProperty(exports, "useGlobalState", {
|
|
|
41
40
|
return _useGlobalState.default;
|
|
42
41
|
}
|
|
43
42
|
});
|
|
44
|
-
|
|
45
43
|
var _GlobalStateProvider = _interopRequireWildcard(require("./GlobalStateProvider"));
|
|
46
|
-
|
|
47
44
|
var _useAsyncCollection = _interopRequireDefault(require("./useAsyncCollection"));
|
|
48
|
-
|
|
49
45
|
var _useAsyncData = _interopRequireDefault(require("./useAsyncData"));
|
|
50
|
-
|
|
51
46
|
var _useGlobalState = _interopRequireDefault(require("./useGlobalState"));
|
|
52
|
-
|
|
53
47
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
54
|
-
|
|
55
48
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
56
|
-
|
|
57
49
|
// TODO: This is a temporary polyfill for `Promise.allSettled(..)` method,
|
|
58
50
|
// which is supported natively by NodeJS >= v12.9.0. As earlier NodeJS version
|
|
59
51
|
// are still in a wide use, this polyfill is added here, and it is to be dropped
|
package/build/node/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Promise","allSettled","promises","all","map","p","finally"],"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":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["Promise","allSettled","promises","all","map","p","finally"],"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA;AAMA;AACA;AACA;AAA6D;AAAA;AAlB7D;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"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = useAsyncCollection;
|
|
9
|
-
|
|
10
8
|
var _useAsyncData = _interopRequireDefault(require("./useAsyncData"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Loads and uses an item in an async collection.
|
|
14
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncCollection.js","names":["useAsyncCollection","id","path","loader","options","itemPath","useAsyncData","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":"
|
|
1
|
+
{"version":3,"file":"useAsyncCollection.js","names":["useAsyncCollection","id","path","loader","options","itemPath","useAsyncData","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":";;;;;;;AAIA;AAJA;AACA;AACA;;AAIA;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;AACe,SAASA,kBAAkB,CACxCC,EAAE,EACFC,IAAI,EACJC,MAAM,EACNC,OAAO,GAAG,CAAC,CAAC,EACZ;EACA,MAAMC,QAAQ,GAAGH,IAAI,GAAI,GAAEA,IAAK,IAAGD,EAAG,EAAC,GAAGA,EAAE;EAC5C,OAAO,IAAAK,qBAAY,EAACD,QAAQ,EAAGE,OAAO,IAAKJ,MAAM,CAACF,EAAE,EAAEM,OAAO,CAAC,EAAEH,OAAO,CAAC;AAC1E"}
|
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = useAsyncData;
|
|
9
|
-
|
|
10
8
|
var _lodash = require("lodash");
|
|
11
|
-
|
|
12
9
|
var _react = require("react");
|
|
13
|
-
|
|
14
10
|
var _uuid = require("uuid");
|
|
15
|
-
|
|
16
11
|
var _GlobalStateProvider = require("./GlobalStateProvider");
|
|
17
|
-
|
|
18
12
|
var _useGlobalState = _interopRequireDefault(require("./useGlobalState"));
|
|
19
|
-
|
|
20
13
|
var _utils = require("./utils");
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* Loads and uses async data into the GlobalState path.
|
|
24
16
|
*/
|
|
17
|
+
|
|
25
18
|
const DEFAULT_MAXAGE = 5 * 60 * 1000; // 5 minutes.
|
|
26
19
|
|
|
27
20
|
/**
|
|
@@ -38,7 +31,6 @@ const DEFAULT_MAXAGE = 5 * 60 * 1000; // 5 minutes.
|
|
|
38
31
|
* @return {Promise} Resolves once the operation is done.
|
|
39
32
|
* @ignore
|
|
40
33
|
*/
|
|
41
|
-
|
|
42
34
|
async function load(path, loader, globalState, oldData, opIdPrefix = 'C') {
|
|
43
35
|
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
44
36
|
/* eslint-disable no-console */
|
|
@@ -51,7 +43,6 @@ async function load(path, loader, globalState, oldData, opIdPrefix = 'C') {
|
|
|
51
43
|
globalState.set(operationIdPath, operationId);
|
|
52
44
|
const data = await loader(oldData || globalState.get(path).data);
|
|
53
45
|
const state = globalState.get(path);
|
|
54
|
-
|
|
55
46
|
if (operationId === state.operationId) {
|
|
56
47
|
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
57
48
|
/* eslint-disable no-console */
|
|
@@ -60,12 +51,12 @@ async function load(path, loader, globalState, oldData, opIdPrefix = 'C') {
|
|
|
60
51
|
/* eslint-enable no-console */
|
|
61
52
|
}
|
|
62
53
|
|
|
63
|
-
globalState.set(path, {
|
|
54
|
+
globalState.set(path, {
|
|
55
|
+
...state,
|
|
64
56
|
data,
|
|
65
57
|
operationId: '',
|
|
66
58
|
timestamp: Date.now()
|
|
67
59
|
});
|
|
68
|
-
|
|
69
60
|
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
70
61
|
/* eslint-disable no-console */
|
|
71
62
|
console.groupEnd();
|
|
@@ -73,6 +64,7 @@ async function load(path, loader, globalState, oldData, opIdPrefix = 'C') {
|
|
|
73
64
|
}
|
|
74
65
|
}
|
|
75
66
|
}
|
|
67
|
+
|
|
76
68
|
/**
|
|
77
69
|
* Resolves asynchronous data, and stores them at given `path` of global
|
|
78
70
|
* state. When multiple components rely on asynchronous data at the same `path`,
|
|
@@ -124,8 +116,6 @@ async function load(path, loader, globalState, oldData, opIdPrefix = 'C') {
|
|
|
124
116
|
* _e.g._ {@link useGlobalState}, but doing so you may interfere with related
|
|
125
117
|
* `useAsyncData()` hooks logic.
|
|
126
118
|
*/
|
|
127
|
-
|
|
128
|
-
|
|
129
119
|
function useAsyncData(path, loader, options = {}) {
|
|
130
120
|
let {
|
|
131
121
|
garbageCollectAge,
|
|
@@ -134,9 +124,10 @@ function useAsyncData(path, loader, options = {}) {
|
|
|
134
124
|
} = options;
|
|
135
125
|
if (maxage === undefined) maxage = DEFAULT_MAXAGE;
|
|
136
126
|
if (refreshAge === undefined) refreshAge = maxage;
|
|
137
|
-
if (garbageCollectAge === undefined) garbageCollectAge = maxage;
|
|
138
|
-
// because that way we'll have issues with SSR (see details below).
|
|
127
|
+
if (garbageCollectAge === undefined) garbageCollectAge = maxage;
|
|
139
128
|
|
|
129
|
+
// Note: here we can't depend on useGlobalState() to init the initial value,
|
|
130
|
+
// because that way we'll have issues with SSR (see details below).
|
|
140
131
|
const globalState = (0, _GlobalStateProvider.getGlobalState)();
|
|
141
132
|
const state = globalState.get(path, {
|
|
142
133
|
initialValue: {
|
|
@@ -146,7 +137,6 @@ function useAsyncData(path, loader, options = {}) {
|
|
|
146
137
|
timestamp: 0
|
|
147
138
|
}
|
|
148
139
|
});
|
|
149
|
-
|
|
150
140
|
if (globalState.ssrContext && !options.noSSR) {
|
|
151
141
|
if (!state.timestamp && !state.operationId) {
|
|
152
142
|
globalState.ssrContext.pending.push(load(path, loader, globalState, state.data, 'S'));
|
|
@@ -168,7 +158,6 @@ function useAsyncData(path, loader, options = {}) {
|
|
|
168
158
|
globalState.set(numRefsPath, numRefs + 1);
|
|
169
159
|
return () => {
|
|
170
160
|
const state2 = globalState.get(path);
|
|
171
|
-
|
|
172
161
|
if (state2.numRefs === 1 && garbageCollectAge < Date.now() - state2.timestamp) {
|
|
173
162
|
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
174
163
|
/* eslint-disable no-console */
|
|
@@ -176,27 +165,30 @@ function useAsyncData(path, loader, options = {}) {
|
|
|
176
165
|
/* eslint-enable no-console */
|
|
177
166
|
}
|
|
178
167
|
|
|
179
|
-
globalState.set(path, {
|
|
168
|
+
globalState.set(path, {
|
|
169
|
+
...state2,
|
|
180
170
|
data: null,
|
|
181
171
|
numRefs: 0,
|
|
182
172
|
timestamp: 0
|
|
183
173
|
});
|
|
184
174
|
} else globalState.set(numRefsPath, state2.numRefs - 1);
|
|
185
175
|
};
|
|
186
|
-
}, [garbageCollectAge, globalState, path]);
|
|
176
|
+
}, [garbageCollectAge, globalState, path]);
|
|
177
|
+
|
|
178
|
+
// Note: a bunch of Rules of Hooks ignored belows because in our very
|
|
187
179
|
// special case the otherwise wrong behavior is actually what we need.
|
|
188
|
-
// Data loading and refreshing.
|
|
189
180
|
|
|
181
|
+
// Data loading and refreshing.
|
|
190
182
|
let loadTriggered = false;
|
|
191
183
|
(0, _react.useEffect)(() => {
|
|
192
184
|
// eslint-disable-line react-hooks/rules-of-hooks
|
|
193
185
|
const state2 = globalState.get(path);
|
|
194
|
-
|
|
195
186
|
if (refreshAge < Date.now() - state2.timestamp && (!state2.operationId || state2.operationId.charAt() === 'S')) {
|
|
196
187
|
load(path, loader, globalState, state2.data);
|
|
197
188
|
loadTriggered = true; // eslint-disable-line react-hooks/exhaustive-deps
|
|
198
189
|
}
|
|
199
190
|
});
|
|
191
|
+
|
|
200
192
|
const deps = options.deps || [];
|
|
201
193
|
(0, _react.useEffect)(() => {
|
|
202
194
|
// eslint-disable-line react-hooks/rules-of-hooks
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAsyncData.js","names":["DEFAULT_MAXAGE","load","path","loader","globalState","oldData","opIdPrefix","process","env","NODE_ENV","isDebugMode","console","log","operationId","uuid","operationIdPath","set","data","get","state","groupCollapsed","cloneDeep","timestamp","Date","now","groupEnd","useAsyncData","options","garbageCollectAge","maxage","refreshAge","undefined","getGlobalState","initialValue","numRefs","ssrContext","noSSR","pending","push","useEffect","numRefsPath","state2","loadTriggered","charAt","deps","length","localState","useGlobalState","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":";;;;;;;;;AAIA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AAVA;AACA;AACA;AAUA,MAAMA,cAAc,GAAG,IAAI,EAAJ,GAAS,IAAhC,C,CAAsC;;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeC,IAAf,CAAoBC,IAApB,EAA0BC,MAA1B,EAAkCC,WAAlC,EAA+CC,OAA/C,EAAwDC,UAAU,GAAG,GAArE,EAA0E;EACxE,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAAzB,IAAyC,IAAAC,kBAAA,GAA7C,EAA4D;IAC1D;IACAC,OAAO,CAACC,GAAR,CACG,4DAA2DV,IAAI,IAAI,EAAG,GADzE;IAGA;EACD;;EACD,MAAMW,WAAW,GAAGP,UAAU,GAAG,IAAAQ,QAAA,GAAjC;EACA,MAAMC,eAAe,GAAGb,IAAI,GAAI,GAAEA,IAAK,cAAX,GAA2B,aAAvD;EACAE,WAAW,CAACY,GAAZ,CAAgBD,eAAhB,EAAiCF,WAAjC;EACA,MAAMI,IAAI,GAAG,MAAMd,MAAM,CAACE,OAAO,IAAID,WAAW,CAACc,GAAZ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AAM,CAACE,UAAD,IAAe,IAAAC,uBAAA,EAAe7C,IAAf,EAAqB;IACxCe,IAAI,EAAE,IADkC;IAExCiB,OAAO,EAAE,CAF+B;IAGxCrB,WAAW,EAAE,EAH2B;IAIxCS,SAAS,EAAE;EAJ6B,CAArB,CAArB;EAOA,OAAO;IACLL,IAAI,EAAEY,MAAM,GAAGN,IAAI,CAACC,GAAL,KAAasB,UAAU,CAACxB,SAAjC,GAA6C,IAA7C,GAAoDwB,UAAU,CAAC7B,IADhE;IAEL+B,OAAO,EAAEC,OAAO,CAACH,UAAU,CAACjC,WAAZ,CAFX;IAGLS,SAAS,EAAEwB,UAAU,CAACxB;EAHjB,CAAP;AAKD"}
|
|
1
|
+
{"version":3,"file":"useAsyncData.js","names":["DEFAULT_MAXAGE","load","path","loader","globalState","oldData","opIdPrefix","process","env","NODE_ENV","isDebugMode","console","log","operationId","uuid","operationIdPath","set","data","get","state","groupCollapsed","cloneDeep","timestamp","Date","now","groupEnd","useAsyncData","options","garbageCollectAge","maxage","refreshAge","undefined","getGlobalState","initialValue","numRefs","ssrContext","noSSR","pending","push","useEffect","numRefsPath","state2","loadTriggered","charAt","deps","length","localState","useGlobalState","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":";;;;;;;AAIA;AACA;AACA;AAEA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,GAAG,CAAChB,IAAI,CAAC;MACpC,IAAI4B,UAAU,GAAGP,IAAI,CAACC,GAAG,EAAE,GAAGiB,MAAM,CAACnB,SAAS,KAC1C,CAACmB,MAAM,CAAC5B,WAAW,IAAI4B,MAAM,CAAC5B,WAAW,CAAC8B,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE;QAC/D1C,IAAI,CAACC,IAAI,EAAEC,MAAM,EAAEC,WAAW,EAAEqC,MAAM,CAACxB,IAAI,CAAC;QAC5CyB,aAAa,GAAG,IAAI,CAAC,CAAC;MACxB;IACF,CAAC,CAAC;;IAEF,MAAME,IAAI,GAAGjB,OAAO,CAACiB,IAAI,IAAI,EAAE;IAC/B,IAAAL,gBAAS,EAAC,MAAM;MAAE;MAChB,IAAI,CAACG,aAAa,IAAIE,IAAI,CAACC,MAAM,EAAE5C,IAAI,CAACC,IAAI,EAAEC,MAAM,EAAEC,WAAW,CAAC;IACpE,CAAC,EAAEwC,IAAI,CAAC,CAAC,CAAC;EACZ;;EAEA,MAAM,CAACE,UAAU,CAAC,GAAG,IAAAC,uBAAc,EAAC7C,IAAI,EAAE;IACxCe,IAAI,EAAE,IAAI;IACViB,OAAO,EAAE,CAAC;IACVrB,WAAW,EAAE,EAAE;IACfS,SAAS,EAAE;EACb,CAAC,CAAC;EAEF,OAAO;IACLL,IAAI,EAAEY,MAAM,GAAGN,IAAI,CAACC,GAAG,EAAE,GAAGsB,UAAU,CAACxB,SAAS,GAAG,IAAI,GAAGwB,UAAU,CAAC7B,IAAI;IACzE+B,OAAO,EAAEC,OAAO,CAACH,UAAU,CAACjC,WAAW,CAAC;IACxCS,SAAS,EAAEwB,UAAU,CAACxB;EACxB,CAAC;AACH"}
|
|
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = useGlobalState;
|
|
7
|
-
|
|
8
7
|
var _lodash = require("lodash");
|
|
9
|
-
|
|
10
8
|
var _react = require("react");
|
|
11
|
-
|
|
12
9
|
var _GlobalStateProvider = require("./GlobalStateProvider");
|
|
13
|
-
|
|
14
10
|
var _utils = require("./utils");
|
|
15
|
-
|
|
16
11
|
// Hook for updates of global state.
|
|
17
12
|
|
|
18
13
|
/**
|
|
@@ -67,14 +62,12 @@ var _utils = require("./utils");
|
|
|
67
62
|
*/
|
|
68
63
|
function useGlobalState(path, initialValue) {
|
|
69
64
|
const ref = (0, _react.useRef)();
|
|
70
|
-
|
|
71
65
|
if (!ref.current) {
|
|
72
66
|
ref.current = {
|
|
73
67
|
callbacks: [],
|
|
74
68
|
setter: value => {
|
|
75
69
|
const rc = ref.current;
|
|
76
70
|
const newState = (0, _lodash.isFunction)(value) ? value(rc.state) : value;
|
|
77
|
-
|
|
78
71
|
if (process.env.NODE_ENV !== 'production' && (0, _utils.isDebugMode)()) {
|
|
79
72
|
/* eslint-disable no-console */
|
|
80
73
|
console.groupCollapsed(`ReactGlobalState - useGlobalState setter triggered for path ${rc.path || ''}`);
|
|
@@ -88,7 +81,6 @@ function useGlobalState(path, initialValue) {
|
|
|
88
81
|
watcher: () => {
|
|
89
82
|
const rc = ref.current;
|
|
90
83
|
const state = rc.globalState.get(rc.path);
|
|
91
|
-
|
|
92
84
|
if (state !== rc.state) {
|
|
93
85
|
for (let i = 0; i < rc.callbacks.length; ++i) {
|
|
94
86
|
rc.callbacks[i]();
|
|
@@ -97,7 +89,6 @@ function useGlobalState(path, initialValue) {
|
|
|
97
89
|
}
|
|
98
90
|
};
|
|
99
91
|
}
|
|
100
|
-
|
|
101
92
|
const rc = ref.current;
|
|
102
93
|
const globalState = (0, _GlobalStateProvider.getGlobalState)();
|
|
103
94
|
rc.globalState = globalState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGlobalState.js","names":["useGlobalState","path","initialValue","ref","useRef","current","callbacks","setter","value","rc","newState","isFunction","state","process","env","NODE_ENV","isDebugMode","console","groupCollapsed","log","cloneDeep","groupEnd","globalState","set","watcher","get","i","length","getGlobalState","useSyncExternalStore","cb","push","initialState","useEffect","watch","unWatch"],"sources":["../../src/useGlobalState.js"],"sourcesContent":["// Hook for updates of global state.\n\nimport { cloneDeep, isFunction } from 'lodash';\nimport { useEffect, useRef, useSyncExternalStore } from 'react';\n\nimport { getGlobalState } from './GlobalStateProvider';\nimport { isDebugMode } from './utils';\n\n/**\n * The primary hook for interacting with the global state, modeled after\n * the standard React's\n * [useState](https://reactjs.org/docs/hooks-reference.html#usestate).\n * It subscribes a component to a given `path` of global state, and provides\n * a function to update it. Each time the value at `path` changes, the hook\n * triggers re-render of its host component.\n *\n * **Note:**\n * - For performance, the library does not copy objects written to / read from\n * global state paths. You MUST NOT manually mutate returned state values,\n * or change objects already written into the global state, without explicitly\n * clonning them first yourself.\n * - State update notifications are asynchronous. When your code does multiple\n * global state updates in the same React rendering cycle, all state update\n * notifications are queued and dispatched together, after the current\n * rendering cycle. In other words, in any given rendering cycle the global\n * state values are \"fixed\", and all changes becomes visible at once in the\n * next triggered rendering pass.\n *\n * @param {string} [path] Dot-delimitered state path. It can be undefined to\n * subscribe for entire state.\n *\n * Under-the-hood state values are read and written using `lodash`\n * [_.get()](https://lodash.com/docs/4.17.15#get) and\n * [_.set()](https://lodash.com/docs/4.17.15#set) methods, thus it is safe\n * to access state paths which have not been created before.\n * @param {any} [initialValue] Initial value to set at the `path`, or its\n * factory:\n * - If a function is given, it will act similar to\n * [the lazy initial state of the standard React's useState()](https://reactjs.org/docs/hooks-reference.html#lazy-initial-state):\n * only if the value at `path` is `undefined`, the function will be executed,\n * and the value it returns will be written to the `path`.\n * - Otherwise, the given value itself will be written to the `path`,\n * if the current value at `path` is `undefined`.\n * @return {Array} It returs an array with two elements: `[value, setValue]`:\n *\n * - The `value` is the current value at given `path`.\n *\n * - The `setValue()` is setter function to write a new value to the `path`.\n *\n * Similar to the standard React's `useState()`, it supports\n * [functional value updates](https://reactjs.org/docs/hooks-reference.html#functional-updates):\n * if `setValue()` is called with a function as argument, that function will\n * be called and its return value will be written to `path`. Otherwise,\n * the argument of `setValue()` itself is written to `path`.\n *\n * Also, similar to the standard React's state setters, `setValue()` is\n * stable function: it does not change between component re-renders.\n */\nexport default function useGlobalState(path, initialValue) {\n const ref = useRef();\n if (!ref.current) {\n ref.current = {\n callbacks: [],\n setter: (value) => {\n const rc = ref.current;\n const newState = isFunction(value) ? value(rc.state) : value;\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState - useGlobalState setter triggered for path ${\n rc.path || ''\n }`,\n );\n console.log('New value:', cloneDeep(newState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n rc.globalState.set(rc.path, newState);\n },\n watcher: () => {\n const rc = ref.current;\n const state = rc.globalState.get(rc.path);\n if (state !== rc.state) {\n for (let i = 0; i < rc.callbacks.length; ++i) {\n rc.callbacks[i]();\n }\n }\n },\n };\n }\n\n const rc = ref.current;\n const globalState = getGlobalState();\n rc.globalState = globalState;\n rc.path = path;\n\n rc.state = useSyncExternalStore(\n (cb) => { rc.callbacks.push(cb); },\n () => rc.globalState.get(rc.path, { initialValue }),\n () => rc.globalState.get(rc.path, { initialValue, initialState: true }),\n );\n\n useEffect(() => {\n globalState.watch(rc.watcher);\n rc.watcher();\n return () => globalState.unWatch(rc.watcher);\n }, [globalState, rc]);\n\n useEffect(() => {\n rc.watcher();\n }, [path, rc]);\n\n return [rc.state, rc.setter];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGlobalState.js","names":["useGlobalState","path","initialValue","ref","useRef","current","callbacks","setter","value","rc","newState","isFunction","state","process","env","NODE_ENV","isDebugMode","console","groupCollapsed","log","cloneDeep","groupEnd","globalState","set","watcher","get","i","length","getGlobalState","useSyncExternalStore","cb","push","initialState","useEffect","watch","unWatch"],"sources":["../../src/useGlobalState.js"],"sourcesContent":["// Hook for updates of global state.\n\nimport { cloneDeep, isFunction } from 'lodash';\nimport { useEffect, useRef, useSyncExternalStore } from 'react';\n\nimport { getGlobalState } from './GlobalStateProvider';\nimport { isDebugMode } from './utils';\n\n/**\n * The primary hook for interacting with the global state, modeled after\n * the standard React's\n * [useState](https://reactjs.org/docs/hooks-reference.html#usestate).\n * It subscribes a component to a given `path` of global state, and provides\n * a function to update it. Each time the value at `path` changes, the hook\n * triggers re-render of its host component.\n *\n * **Note:**\n * - For performance, the library does not copy objects written to / read from\n * global state paths. You MUST NOT manually mutate returned state values,\n * or change objects already written into the global state, without explicitly\n * clonning them first yourself.\n * - State update notifications are asynchronous. When your code does multiple\n * global state updates in the same React rendering cycle, all state update\n * notifications are queued and dispatched together, after the current\n * rendering cycle. In other words, in any given rendering cycle the global\n * state values are \"fixed\", and all changes becomes visible at once in the\n * next triggered rendering pass.\n *\n * @param {string} [path] Dot-delimitered state path. It can be undefined to\n * subscribe for entire state.\n *\n * Under-the-hood state values are read and written using `lodash`\n * [_.get()](https://lodash.com/docs/4.17.15#get) and\n * [_.set()](https://lodash.com/docs/4.17.15#set) methods, thus it is safe\n * to access state paths which have not been created before.\n * @param {any} [initialValue] Initial value to set at the `path`, or its\n * factory:\n * - If a function is given, it will act similar to\n * [the lazy initial state of the standard React's useState()](https://reactjs.org/docs/hooks-reference.html#lazy-initial-state):\n * only if the value at `path` is `undefined`, the function will be executed,\n * and the value it returns will be written to the `path`.\n * - Otherwise, the given value itself will be written to the `path`,\n * if the current value at `path` is `undefined`.\n * @return {Array} It returs an array with two elements: `[value, setValue]`:\n *\n * - The `value` is the current value at given `path`.\n *\n * - The `setValue()` is setter function to write a new value to the `path`.\n *\n * Similar to the standard React's `useState()`, it supports\n * [functional value updates](https://reactjs.org/docs/hooks-reference.html#functional-updates):\n * if `setValue()` is called with a function as argument, that function will\n * be called and its return value will be written to `path`. Otherwise,\n * the argument of `setValue()` itself is written to `path`.\n *\n * Also, similar to the standard React's state setters, `setValue()` is\n * stable function: it does not change between component re-renders.\n */\nexport default function useGlobalState(path, initialValue) {\n const ref = useRef();\n if (!ref.current) {\n ref.current = {\n callbacks: [],\n setter: (value) => {\n const rc = ref.current;\n const newState = isFunction(value) ? value(rc.state) : value;\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState - useGlobalState setter triggered for path ${\n rc.path || ''\n }`,\n );\n console.log('New value:', cloneDeep(newState));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n rc.globalState.set(rc.path, newState);\n },\n watcher: () => {\n const rc = ref.current;\n const state = rc.globalState.get(rc.path);\n if (state !== rc.state) {\n for (let i = 0; i < rc.callbacks.length; ++i) {\n rc.callbacks[i]();\n }\n }\n },\n };\n }\n\n const rc = ref.current;\n const globalState = getGlobalState();\n rc.globalState = globalState;\n rc.path = path;\n\n rc.state = useSyncExternalStore(\n (cb) => { rc.callbacks.push(cb); },\n () => rc.globalState.get(rc.path, { initialValue }),\n () => rc.globalState.get(rc.path, { initialValue, initialState: true }),\n );\n\n useEffect(() => {\n globalState.watch(rc.watcher);\n rc.watcher();\n return () => globalState.unWatch(rc.watcher);\n }, [globalState, rc]);\n\n useEffect(() => {\n rc.watcher();\n }, [path, rc]);\n\n return [rc.state, rc.setter];\n}\n"],"mappings":";;;;;;AAEA;AACA;AAEA;AACA;AANA;;AAQA;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;AACe,SAASA,cAAc,CAACC,IAAI,EAAEC,YAAY,EAAE;EACzD,MAAMC,GAAG,GAAG,IAAAC,aAAM,GAAE;EACpB,IAAI,CAACD,GAAG,CAACE,OAAO,EAAE;IAChBF,GAAG,CAACE,OAAO,GAAG;MACZC,SAAS,EAAE,EAAE;MACbC,M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AErB,EAAE,CAACH,SAAS,CAACyB,IAAI,CAACD,EAAE,CAAC;EAAE,CAAC,EAClC,MAAMrB,EAAE,CAACa,WAAW,CAACG,GAAG,CAAChB,EAAE,CAACR,IAAI,EAAE;IAAEC;EAAa,CAAC,CAAC,EACnD,MAAMO,EAAE,CAACa,WAAW,CAACG,GAAG,CAAChB,EAAE,CAACR,IAAI,EAAE;IAAEC,YAAY;IAAE8B,YAAY,EAAE;EAAK,CAAC,CAAC,CACxE;EAED,IAAAC,gBAAS,EAAC,MAAM;IACdX,WAAW,CAACY,KAAK,CAACzB,EAAE,CAACe,OAAO,CAAC;IAC7Bf,EAAE,CAACe,OAAO,EAAE;IACZ,OAAO,MAAMF,WAAW,CAACa,OAAO,CAAC1B,EAAE,CAACe,OAAO,CAAC;EAC9C,CAAC,EAAE,CAACF,WAAW,EAAEb,EAAE,CAAC,CAAC;EAErB,IAAAwB,gBAAS,EAAC,MAAM;IACdxB,EAAE,CAACe,OAAO,EAAE;EACd,CAAC,EAAE,CAACvB,IAAI,EAAEQ,EAAE,CAAC,CAAC;EAEd,OAAO,CAACA,EAAE,CAACG,KAAK,EAAEH,EAAE,CAACF,MAAM,CAAC;AAC9B"}
|
package/build/node/utils.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.isDebugMode = isDebugMode;
|
|
8
|
-
|
|
9
8
|
// Auxiliary stuff.
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -27,7 +26,6 @@ function isDebugMode() {
|
|
|
27
26
|
return false;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
var _default = null;
|
|
32
30
|
exports.default = _default;
|
|
33
31
|
//# sourceMappingURL=utils.js.map
|
package/build/node/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["isDebugMode","process","env","NODE_ENV","REACT_GLOBAL_STATE_DEBUG","error"],"sources":["../../src/utils.js"],"sourcesContent":["// Auxiliary stuff.\n\n/**\n * Returns 'true' if debug logging should be performed; 'false' otherwise.\n *\n * BEWARE: The actual safeguards for the debug logging still should read\n * if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n * // Some debug logging\n * }\n * to ensure that debug code is stripped out by Webpack in production mode.\n *\n * @returns {boolean}\n * @ignore\n */\nexport function isDebugMode() {\n try {\n return process.env.NODE_ENV !== 'production'\n && !!process.env.REACT_GLOBAL_STATE_DEBUG;\n } catch (error) {\n return false;\n }\n}\n\nexport default null;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["isDebugMode","process","env","NODE_ENV","REACT_GLOBAL_STATE_DEBUG","error"],"sources":["../../src/utils.js"],"sourcesContent":["// Auxiliary stuff.\n\n/**\n * Returns 'true' if debug logging should be performed; 'false' otherwise.\n *\n * BEWARE: The actual safeguards for the debug logging still should read\n * if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n * // Some debug logging\n * }\n * to ensure that debug code is stripped out by Webpack in production mode.\n *\n * @returns {boolean}\n * @ignore\n */\nexport function isDebugMode() {\n try {\n return process.env.NODE_ENV !== 'production'\n && !!process.env.REACT_GLOBAL_STATE_DEBUG;\n } catch (error) {\n return false;\n }\n}\n\nexport default null;\n"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAW,GAAG;EAC5B,IAAI;IACF,OAAOC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IACvC,CAAC,CAACF,OAAO,CAACC,GAAG,CAACE,wBAAwB;EAC7C,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,OAAO,KAAK;EACd;AACF;AAAC,eAEc,IAAI;AAAA"}
|