use-sync-external-store 1.4.0-rc.0 → 1.4.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/cjs/use-sync-external-store-shim/with-selector.development.js +83 -150
- package/cjs/use-sync-external-store-shim/with-selector.production.js +1 -1
- package/cjs/use-sync-external-store-shim.development.js +77 -233
- package/cjs/use-sync-external-store-shim.native.development.js +71 -222
- package/cjs/use-sync-external-store-with-selector.development.js +82 -149
- package/cjs/use-sync-external-store-with-selector.production.js +1 -1
- package/cjs/use-sync-external-store.development.js +16 -84
- package/package.json +2 -2
|
@@ -8,157 +8,90 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
hasValue: false,
|
|
55
|
-
value: null
|
|
56
|
-
};
|
|
57
|
-
instRef.current = inst;
|
|
58
|
-
} else {
|
|
59
|
-
inst = instRef.current;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
var _useMemo = useMemo(function () {
|
|
63
|
-
// Track the memoized state using closure variables that are local to this
|
|
64
|
-
// memoized instance of a getSnapshot function. Intentionally not using a
|
|
65
|
-
// useRef hook, because that state would be shared across all concurrent
|
|
66
|
-
// copies of the hook/component.
|
|
67
|
-
var hasMemo = false;
|
|
68
|
-
var memoizedSnapshot;
|
|
69
|
-
var memoizedSelection;
|
|
70
|
-
|
|
71
|
-
var memoizedSelector = function (nextSnapshot) {
|
|
72
|
-
if (!hasMemo) {
|
|
73
|
-
// The first time the hook is called, there is no memoized result.
|
|
74
|
-
hasMemo = true;
|
|
75
|
-
memoizedSnapshot = nextSnapshot;
|
|
76
|
-
|
|
77
|
-
var _nextSelection = selector(nextSnapshot);
|
|
78
|
-
|
|
79
|
-
if (isEqual !== undefined) {
|
|
80
|
-
// Even if the selector has changed, the currently rendered selection
|
|
81
|
-
// may be equal to the new selection. We should attempt to reuse the
|
|
82
|
-
// current value if possible, to preserve downstream memoizations.
|
|
83
|
-
if (inst.hasValue) {
|
|
84
|
-
var currentSelection = inst.value;
|
|
85
|
-
|
|
86
|
-
if (isEqual(currentSelection, _nextSelection)) {
|
|
87
|
-
memoizedSelection = currentSelection;
|
|
88
|
-
return currentSelection;
|
|
11
|
+
"use strict";
|
|
12
|
+
"production" !== process.env.NODE_ENV &&
|
|
13
|
+
(function () {
|
|
14
|
+
function is(x, y) {
|
|
15
|
+
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|
16
|
+
}
|
|
17
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
18
|
+
"function" ===
|
|
19
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
|
|
20
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
21
|
+
var React = require("react"),
|
|
22
|
+
shim = require("use-sync-external-store/shim"),
|
|
23
|
+
objectIs = "function" === typeof Object.is ? Object.is : is,
|
|
24
|
+
useSyncExternalStore = shim.useSyncExternalStore,
|
|
25
|
+
useRef = React.useRef,
|
|
26
|
+
useEffect = React.useEffect,
|
|
27
|
+
useMemo = React.useMemo,
|
|
28
|
+
useDebugValue = React.useDebugValue;
|
|
29
|
+
exports.useSyncExternalStoreWithSelector = function (
|
|
30
|
+
subscribe,
|
|
31
|
+
getSnapshot,
|
|
32
|
+
getServerSnapshot,
|
|
33
|
+
selector,
|
|
34
|
+
isEqual
|
|
35
|
+
) {
|
|
36
|
+
var instRef = useRef(null);
|
|
37
|
+
if (null === instRef.current) {
|
|
38
|
+
var inst = { hasValue: !1, value: null };
|
|
39
|
+
instRef.current = inst;
|
|
40
|
+
} else inst = instRef.current;
|
|
41
|
+
instRef = useMemo(
|
|
42
|
+
function () {
|
|
43
|
+
function memoizedSelector(nextSnapshot) {
|
|
44
|
+
if (!hasMemo) {
|
|
45
|
+
hasMemo = !0;
|
|
46
|
+
memoizedSnapshot = nextSnapshot;
|
|
47
|
+
nextSnapshot = selector(nextSnapshot);
|
|
48
|
+
if (void 0 !== isEqual && inst.hasValue) {
|
|
49
|
+
var currentSelection = inst.value;
|
|
50
|
+
if (isEqual(currentSelection, nextSnapshot))
|
|
51
|
+
return (memoizedSelection = currentSelection);
|
|
52
|
+
}
|
|
53
|
+
return (memoizedSelection = nextSnapshot);
|
|
89
54
|
}
|
|
55
|
+
currentSelection = memoizedSelection;
|
|
56
|
+
if (objectIs(memoizedSnapshot, nextSnapshot))
|
|
57
|
+
return currentSelection;
|
|
58
|
+
var nextSelection = selector(nextSnapshot);
|
|
59
|
+
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|
60
|
+
return (memoizedSnapshot = nextSnapshot), currentSelection;
|
|
61
|
+
memoizedSnapshot = nextSnapshot;
|
|
62
|
+
return (memoizedSelection = nextSelection);
|
|
90
63
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return prevSelection;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
memoizedSnapshot = nextSnapshot;
|
|
123
|
-
memoizedSelection = nextSelection;
|
|
124
|
-
return nextSelection;
|
|
125
|
-
}; // Assigning this to a constant so that Flow knows it can't change.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// Assigning this to a constant so that Flow knows it can't change.
|
|
129
|
-
var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
|
130
|
-
|
|
131
|
-
var getSnapshotWithSelector = function () {
|
|
132
|
-
return memoizedSelector(getSnapshot());
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
|
|
136
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
64
|
+
var hasMemo = !1,
|
|
65
|
+
memoizedSnapshot,
|
|
66
|
+
memoizedSelection,
|
|
67
|
+
maybeGetServerSnapshot =
|
|
68
|
+
void 0 === getServerSnapshot ? null : getServerSnapshot;
|
|
69
|
+
return [
|
|
70
|
+
function () {
|
|
71
|
+
return memoizedSelector(getSnapshot());
|
|
72
|
+
},
|
|
73
|
+
null === maybeGetServerSnapshot
|
|
74
|
+
? void 0
|
|
75
|
+
: function () {
|
|
76
|
+
return memoizedSelector(maybeGetServerSnapshot());
|
|
77
|
+
}
|
|
78
|
+
];
|
|
79
|
+
},
|
|
80
|
+
[getSnapshot, getServerSnapshot, selector, isEqual]
|
|
81
|
+
);
|
|
82
|
+
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
|
|
83
|
+
useEffect(
|
|
84
|
+
function () {
|
|
85
|
+
inst.hasValue = !0;
|
|
86
|
+
inst.value = value;
|
|
87
|
+
},
|
|
88
|
+
[value]
|
|
89
|
+
);
|
|
90
|
+
useDebugValue(value);
|
|
91
|
+
return value;
|
|
137
92
|
};
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
144
|
-
useEffect(function () {
|
|
145
|
-
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported
|
|
146
|
-
inst.hasValue = true; // $FlowFixMe[incompatible-type]
|
|
147
|
-
|
|
148
|
-
inst.value = value;
|
|
149
|
-
}, [value]);
|
|
150
|
-
useDebugValue(value);
|
|
151
|
-
return value;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
155
|
-
if (
|
|
156
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
157
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
158
|
-
'function'
|
|
159
|
-
) {
|
|
160
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
161
|
-
}
|
|
162
|
-
|
|
93
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
94
|
+
"function" ===
|
|
95
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
|
|
96
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
163
97
|
})();
|
|
164
|
-
}
|
|
@@ -50,7 +50,7 @@ exports.useSyncExternalStoreWithSelector = function (
|
|
|
50
50
|
if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
|
|
51
51
|
var nextSelection = selector(nextSnapshot);
|
|
52
52
|
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|
53
|
-
return currentSelection;
|
|
53
|
+
return (memoizedSnapshot = nextSnapshot), currentSelection;
|
|
54
54
|
memoizedSnapshot = nextSnapshot;
|
|
55
55
|
return (memoizedSelection = nextSelection);
|
|
56
56
|
}
|
|
@@ -8,244 +8,88 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
18
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
19
|
-
'function'
|
|
20
|
-
) {
|
|
21
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
22
|
-
}
|
|
23
|
-
var React = require('react');
|
|
24
|
-
|
|
25
|
-
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
26
|
-
|
|
27
|
-
function error(format) {
|
|
28
|
-
{
|
|
29
|
-
{
|
|
30
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
31
|
-
args[_key2 - 1] = arguments[_key2];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
printWarning('error', format, args);
|
|
11
|
+
"use strict";
|
|
12
|
+
"production" !== process.env.NODE_ENV &&
|
|
13
|
+
(function () {
|
|
14
|
+
function is(x, y) {
|
|
15
|
+
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|
35
16
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (stack !== '') {
|
|
52
|
-
format += '%s';
|
|
53
|
-
args = args.concat([stack]);
|
|
17
|
+
function useSyncExternalStore$2(subscribe, getSnapshot) {
|
|
18
|
+
didWarnOld18Alpha ||
|
|
19
|
+
void 0 === React.startTransition ||
|
|
20
|
+
((didWarnOld18Alpha = !0),
|
|
21
|
+
console.error(
|
|
22
|
+
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
23
|
+
));
|
|
24
|
+
var value = getSnapshot();
|
|
25
|
+
if (!didWarnUncachedGetSnapshot) {
|
|
26
|
+
var cachedValue = getSnapshot();
|
|
27
|
+
objectIs(value, cachedValue) ||
|
|
28
|
+
(console.error(
|
|
29
|
+
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
30
|
+
),
|
|
31
|
+
(didWarnUncachedGetSnapshot = !0));
|
|
54
32
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (isErrorLogger) {
|
|
58
|
-
// Don't prefix our default logging formatting in ReactFiberErrorLoggger.
|
|
59
|
-
// Don't toString the arguments.
|
|
60
|
-
args.unshift(format);
|
|
61
|
-
} else {
|
|
62
|
-
// TODO: Remove this prefix and stop toStringing in the wrapper and
|
|
63
|
-
// instead do it at each callsite as needed.
|
|
64
|
-
// Careful: RN currently depends on this prefix
|
|
65
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
66
|
-
args = args.map(function (item) {
|
|
67
|
-
return String(item);
|
|
33
|
+
cachedValue = useState({
|
|
34
|
+
inst: { value: value, getSnapshot: getSnapshot }
|
|
68
35
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// dispatch for CommonJS interop named imports.
|
|
92
|
-
|
|
93
|
-
var useState = React.useState,
|
|
94
|
-
useEffect = React.useEffect,
|
|
95
|
-
useLayoutEffect = React.useLayoutEffect,
|
|
96
|
-
useDebugValue = React.useDebugValue;
|
|
97
|
-
var didWarnOld18Alpha = false;
|
|
98
|
-
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
99
|
-
// because of a very particular set of implementation details and assumptions
|
|
100
|
-
// -- change any one of them and it will break. The most important assumption
|
|
101
|
-
// is that updates are always synchronous, because concurrent rendering is
|
|
102
|
-
// only available in versions of React that also have a built-in
|
|
103
|
-
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
104
|
-
// does not exist.
|
|
105
|
-
//
|
|
106
|
-
// Do not assume that the clever hacks used by this hook also work in general.
|
|
107
|
-
// The point of this shim is to replace the need for hacks by other libraries.
|
|
108
|
-
|
|
109
|
-
function useSyncExternalStore$2(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
110
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
111
|
-
// will need to track that themselves and return the correct value
|
|
112
|
-
// from `getSnapshot`.
|
|
113
|
-
getServerSnapshot) {
|
|
114
|
-
{
|
|
115
|
-
if (!didWarnOld18Alpha) {
|
|
116
|
-
if (React.startTransition !== undefined) {
|
|
117
|
-
didWarnOld18Alpha = true;
|
|
118
|
-
|
|
119
|
-
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
|
|
120
|
-
}
|
|
36
|
+
var inst = cachedValue[0].inst,
|
|
37
|
+
forceUpdate = cachedValue[1];
|
|
38
|
+
useLayoutEffect(
|
|
39
|
+
function () {
|
|
40
|
+
inst.value = value;
|
|
41
|
+
inst.getSnapshot = getSnapshot;
|
|
42
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
|
|
43
|
+
},
|
|
44
|
+
[subscribe, value, getSnapshot]
|
|
45
|
+
);
|
|
46
|
+
useEffect(
|
|
47
|
+
function () {
|
|
48
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
|
|
49
|
+
return subscribe(function () {
|
|
50
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
[subscribe]
|
|
54
|
+
);
|
|
55
|
+
useDebugValue(value);
|
|
56
|
+
return value;
|
|
121
57
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
{
|
|
131
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
132
|
-
var cachedValue = getSnapshot();
|
|
133
|
-
|
|
134
|
-
if (!objectIs(value, cachedValue)) {
|
|
135
|
-
error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
136
|
-
|
|
137
|
-
didWarnUncachedGetSnapshot = true;
|
|
58
|
+
function checkIfSnapshotChanged(inst) {
|
|
59
|
+
var latestGetSnapshot = inst.getSnapshot;
|
|
60
|
+
inst = inst.value;
|
|
61
|
+
try {
|
|
62
|
+
var nextValue = latestGetSnapshot();
|
|
63
|
+
return !objectIs(inst, nextValue);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return !0;
|
|
138
66
|
}
|
|
139
67
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
// arbitrary useState hook. Then, during render, we call getSnapshot to read
|
|
143
|
-
// the current value.
|
|
144
|
-
//
|
|
145
|
-
// Because we don't actually use the state returned by the useState hook, we
|
|
146
|
-
// can save a bit of memory by storing other stuff in that slot.
|
|
147
|
-
//
|
|
148
|
-
// To implement the early bailout, we need to track some things on a mutable
|
|
149
|
-
// object. Usually, we would put that in a useRef hook, but we can stash it in
|
|
150
|
-
// our useState hook instead.
|
|
151
|
-
//
|
|
152
|
-
// To force a re-render, we call forceUpdate({inst}). That works because the
|
|
153
|
-
// new object always fails an equality check.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
var _useState = useState({
|
|
157
|
-
inst: {
|
|
158
|
-
value: value,
|
|
159
|
-
getSnapshot: getSnapshot
|
|
160
|
-
}
|
|
161
|
-
}),
|
|
162
|
-
inst = _useState[0].inst,
|
|
163
|
-
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
|
|
164
|
-
// in the layout phase so we can access it during the tearing check that
|
|
165
|
-
// happens on subscribe.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
useLayoutEffect(function () {
|
|
169
|
-
inst.value = value;
|
|
170
|
-
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
|
|
171
|
-
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
172
|
-
// this can happen all the time, but even in synchronous mode, an earlier
|
|
173
|
-
// effect may have mutated the store.
|
|
174
|
-
|
|
175
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
176
|
-
// Force a re-render.
|
|
177
|
-
forceUpdate({
|
|
178
|
-
inst: inst
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}, [subscribe, value, getSnapshot]);
|
|
182
|
-
useEffect(function () {
|
|
183
|
-
// Check for changes right before subscribing. Subsequent changes will be
|
|
184
|
-
// detected in the subscription handler.
|
|
185
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
186
|
-
// Force a re-render.
|
|
187
|
-
forceUpdate({
|
|
188
|
-
inst: inst
|
|
189
|
-
});
|
|
68
|
+
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
69
|
+
return getSnapshot();
|
|
190
70
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
216
|
-
var prevValue = inst.value;
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
var nextValue = latestGetSnapshot();
|
|
220
|
-
return !objectIs(prevValue, nextValue);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
227
|
-
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
228
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
229
|
-
// will need to track that themselves and return the correct value
|
|
230
|
-
// from `getSnapshot`.
|
|
231
|
-
return getSnapshot();
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
235
|
-
|
|
236
|
-
var isServerEnvironment = !canUseDOM;
|
|
237
|
-
|
|
238
|
-
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2;
|
|
239
|
-
var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
240
|
-
|
|
241
|
-
exports.useSyncExternalStore = useSyncExternalStore;
|
|
242
|
-
if (
|
|
243
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
244
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
245
|
-
'function'
|
|
246
|
-
) {
|
|
247
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
248
|
-
}
|
|
249
|
-
|
|
71
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
72
|
+
"function" ===
|
|
73
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
|
|
74
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
75
|
+
var React = require("react"),
|
|
76
|
+
objectIs = "function" === typeof Object.is ? Object.is : is,
|
|
77
|
+
useState = React.useState,
|
|
78
|
+
useEffect = React.useEffect,
|
|
79
|
+
useLayoutEffect = React.useLayoutEffect,
|
|
80
|
+
useDebugValue = React.useDebugValue,
|
|
81
|
+
didWarnOld18Alpha = !1,
|
|
82
|
+
didWarnUncachedGetSnapshot = !1,
|
|
83
|
+
shim =
|
|
84
|
+
"undefined" === typeof window ||
|
|
85
|
+
"undefined" === typeof window.document ||
|
|
86
|
+
"undefined" === typeof window.document.createElement
|
|
87
|
+
? useSyncExternalStore$1
|
|
88
|
+
: useSyncExternalStore$2;
|
|
89
|
+
exports.useSyncExternalStore =
|
|
90
|
+
void 0 !== React.useSyncExternalStore ? React.useSyncExternalStore : shim;
|
|
91
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
92
|
+
"function" ===
|
|
93
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
|
|
94
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
250
95
|
})();
|
|
251
|
-
}
|
|
@@ -8,232 +8,81 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
18
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
19
|
-
'function'
|
|
20
|
-
) {
|
|
21
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
22
|
-
}
|
|
23
|
-
var React = require('react');
|
|
24
|
-
|
|
25
|
-
var ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE;
|
|
26
|
-
|
|
27
|
-
function error(format) {
|
|
28
|
-
{
|
|
29
|
-
{
|
|
30
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
31
|
-
args[_key2 - 1] = arguments[_key2];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
printWarning('error', format, args);
|
|
11
|
+
"use strict";
|
|
12
|
+
"production" !== process.env.NODE_ENV &&
|
|
13
|
+
(function () {
|
|
14
|
+
function is(x, y) {
|
|
15
|
+
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|
35
16
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (stack !== '') {
|
|
52
|
-
format += '%s';
|
|
53
|
-
args = args.concat([stack]);
|
|
17
|
+
function useSyncExternalStore$1(subscribe, getSnapshot) {
|
|
18
|
+
didWarnOld18Alpha ||
|
|
19
|
+
void 0 === React.startTransition ||
|
|
20
|
+
((didWarnOld18Alpha = !0),
|
|
21
|
+
console.error(
|
|
22
|
+
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
23
|
+
));
|
|
24
|
+
var value = getSnapshot();
|
|
25
|
+
if (!didWarnUncachedGetSnapshot) {
|
|
26
|
+
var cachedValue = getSnapshot();
|
|
27
|
+
objectIs(value, cachedValue) ||
|
|
28
|
+
(console.error(
|
|
29
|
+
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
30
|
+
),
|
|
31
|
+
(didWarnUncachedGetSnapshot = !0));
|
|
54
32
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (isErrorLogger) {
|
|
58
|
-
// Don't prefix our default logging formatting in ReactFiberErrorLoggger.
|
|
59
|
-
// Don't toString the arguments.
|
|
60
|
-
args.unshift(format);
|
|
61
|
-
} else {
|
|
62
|
-
// TODO: Remove this prefix and stop toStringing in the wrapper and
|
|
63
|
-
// instead do it at each callsite as needed.
|
|
64
|
-
// Careful: RN currently depends on this prefix
|
|
65
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
66
|
-
args = args.map(function (item) {
|
|
67
|
-
return String(item);
|
|
33
|
+
cachedValue = useState({
|
|
34
|
+
inst: { value: value, getSnapshot: getSnapshot }
|
|
68
35
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// dispatch for CommonJS interop named imports.
|
|
92
|
-
|
|
93
|
-
var useState = React.useState,
|
|
94
|
-
useEffect = React.useEffect,
|
|
95
|
-
useLayoutEffect = React.useLayoutEffect,
|
|
96
|
-
useDebugValue = React.useDebugValue;
|
|
97
|
-
var didWarnOld18Alpha = false;
|
|
98
|
-
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
99
|
-
// because of a very particular set of implementation details and assumptions
|
|
100
|
-
// -- change any one of them and it will break. The most important assumption
|
|
101
|
-
// is that updates are always synchronous, because concurrent rendering is
|
|
102
|
-
// only available in versions of React that also have a built-in
|
|
103
|
-
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
104
|
-
// does not exist.
|
|
105
|
-
//
|
|
106
|
-
// Do not assume that the clever hacks used by this hook also work in general.
|
|
107
|
-
// The point of this shim is to replace the need for hacks by other libraries.
|
|
108
|
-
|
|
109
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
110
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
111
|
-
// will need to track that themselves and return the correct value
|
|
112
|
-
// from `getSnapshot`.
|
|
113
|
-
getServerSnapshot) {
|
|
114
|
-
{
|
|
115
|
-
if (!didWarnOld18Alpha) {
|
|
116
|
-
if (React.startTransition !== undefined) {
|
|
117
|
-
didWarnOld18Alpha = true;
|
|
118
|
-
|
|
119
|
-
error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
|
|
120
|
-
}
|
|
36
|
+
var inst = cachedValue[0].inst,
|
|
37
|
+
forceUpdate = cachedValue[1];
|
|
38
|
+
useLayoutEffect(
|
|
39
|
+
function () {
|
|
40
|
+
inst.value = value;
|
|
41
|
+
inst.getSnapshot = getSnapshot;
|
|
42
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
|
|
43
|
+
},
|
|
44
|
+
[subscribe, value, getSnapshot]
|
|
45
|
+
);
|
|
46
|
+
useEffect(
|
|
47
|
+
function () {
|
|
48
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
|
|
49
|
+
return subscribe(function () {
|
|
50
|
+
checkIfSnapshotChanged(inst) && forceUpdate({ inst: inst });
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
[subscribe]
|
|
54
|
+
);
|
|
55
|
+
useDebugValue(value);
|
|
56
|
+
return value;
|
|
121
57
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
{
|
|
131
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
132
|
-
var cachedValue = getSnapshot();
|
|
133
|
-
|
|
134
|
-
if (!objectIs(value, cachedValue)) {
|
|
135
|
-
error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
136
|
-
|
|
137
|
-
didWarnUncachedGetSnapshot = true;
|
|
58
|
+
function checkIfSnapshotChanged(inst) {
|
|
59
|
+
var latestGetSnapshot = inst.getSnapshot;
|
|
60
|
+
inst = inst.value;
|
|
61
|
+
try {
|
|
62
|
+
var nextValue = latestGetSnapshot();
|
|
63
|
+
return !objectIs(inst, nextValue);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return !0;
|
|
138
66
|
}
|
|
139
67
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
}),
|
|
162
|
-
inst = _useState[0].inst,
|
|
163
|
-
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
|
|
164
|
-
// in the layout phase so we can access it during the tearing check that
|
|
165
|
-
// happens on subscribe.
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
useLayoutEffect(function () {
|
|
169
|
-
inst.value = value;
|
|
170
|
-
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
|
|
171
|
-
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
172
|
-
// this can happen all the time, but even in synchronous mode, an earlier
|
|
173
|
-
// effect may have mutated the store.
|
|
174
|
-
|
|
175
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
176
|
-
// Force a re-render.
|
|
177
|
-
forceUpdate({
|
|
178
|
-
inst: inst
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
}, [subscribe, value, getSnapshot]);
|
|
182
|
-
useEffect(function () {
|
|
183
|
-
// Check for changes right before subscribing. Subsequent changes will be
|
|
184
|
-
// detected in the subscription handler.
|
|
185
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
186
|
-
// Force a re-render.
|
|
187
|
-
forceUpdate({
|
|
188
|
-
inst: inst
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var handleStoreChange = function () {
|
|
193
|
-
// TODO: Because there is no cross-renderer API for batching updates, it's
|
|
194
|
-
// up to the consumer of this library to wrap their subscription event
|
|
195
|
-
// with unstable_batchedUpdates. Should we try to detect when this isn't
|
|
196
|
-
// the case and print a warning in development?
|
|
197
|
-
// The store changed. Check if the snapshot changed since the last time we
|
|
198
|
-
// read from the store.
|
|
199
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
200
|
-
// Force a re-render.
|
|
201
|
-
forceUpdate({
|
|
202
|
-
inst: inst
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
}; // Subscribe to the store and return a clean-up function.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return subscribe(handleStoreChange);
|
|
209
|
-
}, [subscribe]);
|
|
210
|
-
useDebugValue(value);
|
|
211
|
-
return value;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function checkIfSnapshotChanged(inst) {
|
|
215
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
216
|
-
var prevValue = inst.value;
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
var nextValue = latestGetSnapshot();
|
|
220
|
-
return !objectIs(prevValue, nextValue);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
return true;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
var shim = useSyncExternalStore$1;
|
|
227
|
-
var useSyncExternalStore = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
228
|
-
|
|
229
|
-
exports.useSyncExternalStore = useSyncExternalStore;
|
|
230
|
-
if (
|
|
231
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
232
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
233
|
-
'function'
|
|
234
|
-
) {
|
|
235
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
236
|
-
}
|
|
237
|
-
|
|
68
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
69
|
+
"function" ===
|
|
70
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
|
|
71
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
72
|
+
var React = require("react"),
|
|
73
|
+
objectIs = "function" === typeof Object.is ? Object.is : is,
|
|
74
|
+
useState = React.useState,
|
|
75
|
+
useEffect = React.useEffect,
|
|
76
|
+
useLayoutEffect = React.useLayoutEffect,
|
|
77
|
+
useDebugValue = React.useDebugValue,
|
|
78
|
+
didWarnOld18Alpha = !1,
|
|
79
|
+
didWarnUncachedGetSnapshot = !1;
|
|
80
|
+
exports.useSyncExternalStore =
|
|
81
|
+
void 0 !== React.useSyncExternalStore
|
|
82
|
+
? React.useSyncExternalStore
|
|
83
|
+
: useSyncExternalStore$1;
|
|
84
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
85
|
+
"function" ===
|
|
86
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
|
|
87
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
238
88
|
})();
|
|
239
|
-
}
|
|
@@ -8,156 +8,89 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
hasValue: false,
|
|
54
|
-
value: null
|
|
55
|
-
};
|
|
56
|
-
instRef.current = inst;
|
|
57
|
-
} else {
|
|
58
|
-
inst = instRef.current;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
var _useMemo = useMemo(function () {
|
|
62
|
-
// Track the memoized state using closure variables that are local to this
|
|
63
|
-
// memoized instance of a getSnapshot function. Intentionally not using a
|
|
64
|
-
// useRef hook, because that state would be shared across all concurrent
|
|
65
|
-
// copies of the hook/component.
|
|
66
|
-
var hasMemo = false;
|
|
67
|
-
var memoizedSnapshot;
|
|
68
|
-
var memoizedSelection;
|
|
69
|
-
|
|
70
|
-
var memoizedSelector = function (nextSnapshot) {
|
|
71
|
-
if (!hasMemo) {
|
|
72
|
-
// The first time the hook is called, there is no memoized result.
|
|
73
|
-
hasMemo = true;
|
|
74
|
-
memoizedSnapshot = nextSnapshot;
|
|
75
|
-
|
|
76
|
-
var _nextSelection = selector(nextSnapshot);
|
|
77
|
-
|
|
78
|
-
if (isEqual !== undefined) {
|
|
79
|
-
// Even if the selector has changed, the currently rendered selection
|
|
80
|
-
// may be equal to the new selection. We should attempt to reuse the
|
|
81
|
-
// current value if possible, to preserve downstream memoizations.
|
|
82
|
-
if (inst.hasValue) {
|
|
83
|
-
var currentSelection = inst.value;
|
|
84
|
-
|
|
85
|
-
if (isEqual(currentSelection, _nextSelection)) {
|
|
86
|
-
memoizedSelection = currentSelection;
|
|
87
|
-
return currentSelection;
|
|
11
|
+
"use strict";
|
|
12
|
+
"production" !== process.env.NODE_ENV &&
|
|
13
|
+
(function () {
|
|
14
|
+
function is(x, y) {
|
|
15
|
+
return (x === y && (0 !== x || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|
16
|
+
}
|
|
17
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
18
|
+
"function" ===
|
|
19
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
|
|
20
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
21
|
+
var React = require("react"),
|
|
22
|
+
objectIs = "function" === typeof Object.is ? Object.is : is,
|
|
23
|
+
useSyncExternalStore = React.useSyncExternalStore,
|
|
24
|
+
useRef = React.useRef,
|
|
25
|
+
useEffect = React.useEffect,
|
|
26
|
+
useMemo = React.useMemo,
|
|
27
|
+
useDebugValue = React.useDebugValue;
|
|
28
|
+
exports.useSyncExternalStoreWithSelector = function (
|
|
29
|
+
subscribe,
|
|
30
|
+
getSnapshot,
|
|
31
|
+
getServerSnapshot,
|
|
32
|
+
selector,
|
|
33
|
+
isEqual
|
|
34
|
+
) {
|
|
35
|
+
var instRef = useRef(null);
|
|
36
|
+
if (null === instRef.current) {
|
|
37
|
+
var inst = { hasValue: !1, value: null };
|
|
38
|
+
instRef.current = inst;
|
|
39
|
+
} else inst = instRef.current;
|
|
40
|
+
instRef = useMemo(
|
|
41
|
+
function () {
|
|
42
|
+
function memoizedSelector(nextSnapshot) {
|
|
43
|
+
if (!hasMemo) {
|
|
44
|
+
hasMemo = !0;
|
|
45
|
+
memoizedSnapshot = nextSnapshot;
|
|
46
|
+
nextSnapshot = selector(nextSnapshot);
|
|
47
|
+
if (void 0 !== isEqual && inst.hasValue) {
|
|
48
|
+
var currentSelection = inst.value;
|
|
49
|
+
if (isEqual(currentSelection, nextSnapshot))
|
|
50
|
+
return (memoizedSelection = currentSelection);
|
|
51
|
+
}
|
|
52
|
+
return (memoizedSelection = nextSnapshot);
|
|
88
53
|
}
|
|
54
|
+
currentSelection = memoizedSelection;
|
|
55
|
+
if (objectIs(memoizedSnapshot, nextSnapshot))
|
|
56
|
+
return currentSelection;
|
|
57
|
+
var nextSelection = selector(nextSnapshot);
|
|
58
|
+
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|
59
|
+
return (memoizedSnapshot = nextSnapshot), currentSelection;
|
|
60
|
+
memoizedSnapshot = nextSnapshot;
|
|
61
|
+
return (memoizedSelection = nextSelection);
|
|
89
62
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
var
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return prevSelection;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
memoizedSnapshot = nextSnapshot;
|
|
122
|
-
memoizedSelection = nextSelection;
|
|
123
|
-
return nextSelection;
|
|
124
|
-
}; // Assigning this to a constant so that Flow knows it can't change.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
// Assigning this to a constant so that Flow knows it can't change.
|
|
128
|
-
var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
|
|
129
|
-
|
|
130
|
-
var getSnapshotWithSelector = function () {
|
|
131
|
-
return memoizedSelector(getSnapshot());
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
|
|
135
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
63
|
+
var hasMemo = !1,
|
|
64
|
+
memoizedSnapshot,
|
|
65
|
+
memoizedSelection,
|
|
66
|
+
maybeGetServerSnapshot =
|
|
67
|
+
void 0 === getServerSnapshot ? null : getServerSnapshot;
|
|
68
|
+
return [
|
|
69
|
+
function () {
|
|
70
|
+
return memoizedSelector(getSnapshot());
|
|
71
|
+
},
|
|
72
|
+
null === maybeGetServerSnapshot
|
|
73
|
+
? void 0
|
|
74
|
+
: function () {
|
|
75
|
+
return memoizedSelector(maybeGetServerSnapshot());
|
|
76
|
+
}
|
|
77
|
+
];
|
|
78
|
+
},
|
|
79
|
+
[getSnapshot, getServerSnapshot, selector, isEqual]
|
|
80
|
+
);
|
|
81
|
+
var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
|
|
82
|
+
useEffect(
|
|
83
|
+
function () {
|
|
84
|
+
inst.hasValue = !0;
|
|
85
|
+
inst.value = value;
|
|
86
|
+
},
|
|
87
|
+
[value]
|
|
88
|
+
);
|
|
89
|
+
useDebugValue(value);
|
|
90
|
+
return value;
|
|
136
91
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
143
|
-
useEffect(function () {
|
|
144
|
-
// $FlowFixMe[incompatible-type] changing the variant using mutation isn't supported
|
|
145
|
-
inst.hasValue = true; // $FlowFixMe[incompatible-type]
|
|
146
|
-
|
|
147
|
-
inst.value = value;
|
|
148
|
-
}, [value]);
|
|
149
|
-
useDebugValue(value);
|
|
150
|
-
return value;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
|
|
154
|
-
if (
|
|
155
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
156
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
157
|
-
'function'
|
|
158
|
-
) {
|
|
159
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
160
|
-
}
|
|
161
|
-
|
|
92
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
93
|
+
"function" ===
|
|
94
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
|
|
95
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
162
96
|
})();
|
|
163
|
-
}
|
|
@@ -49,7 +49,7 @@ exports.useSyncExternalStoreWithSelector = function (
|
|
|
49
49
|
if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
|
|
50
50
|
var nextSelection = selector(nextSnapshot);
|
|
51
51
|
if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
|
|
52
|
-
return currentSelection;
|
|
52
|
+
return (memoizedSnapshot = nextSnapshot), currentSelection;
|
|
53
53
|
memoizedSnapshot = nextSnapshot;
|
|
54
54
|
return (memoizedSelection = nextSelection);
|
|
55
55
|
}
|
|
@@ -8,88 +8,20 @@
|
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function error(format) {
|
|
28
|
-
{
|
|
29
|
-
{
|
|
30
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
31
|
-
args[_key2 - 1] = arguments[_key2];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
printWarning('error', format, args);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} // eslint-disable-next-line react-internal/no-production-logging
|
|
38
|
-
|
|
39
|
-
function printWarning(level, format, args) {
|
|
40
|
-
// When changing this logic, you might want to also
|
|
41
|
-
// update consoleWithStackDev.www.js as well.
|
|
42
|
-
{
|
|
43
|
-
var isErrorLogger = format === '%s\n\n%s\n' || format === '%o\n\n%s\n\n%s\n';
|
|
44
|
-
|
|
45
|
-
if (ReactSharedInternals.getCurrentStack) {
|
|
46
|
-
// We only add the current stack to the console when createTask is not supported.
|
|
47
|
-
// Since createTask requires DevTools to be open to work, this means that stacks
|
|
48
|
-
// can be lost while DevTools isn't open but we can't detect this.
|
|
49
|
-
var stack = ReactSharedInternals.getCurrentStack();
|
|
50
|
-
|
|
51
|
-
if (stack !== '') {
|
|
52
|
-
format += '%s';
|
|
53
|
-
args = args.concat([stack]);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (isErrorLogger) {
|
|
58
|
-
// Don't prefix our default logging formatting in ReactFiberErrorLoggger.
|
|
59
|
-
// Don't toString the arguments.
|
|
60
|
-
args.unshift(format);
|
|
61
|
-
} else {
|
|
62
|
-
// TODO: Remove this prefix and stop toStringing in the wrapper and
|
|
63
|
-
// instead do it at each callsite as needed.
|
|
64
|
-
// Careful: RN currently depends on this prefix
|
|
65
|
-
// eslint-disable-next-line react-internal/safe-string-coercion
|
|
66
|
-
args = args.map(function (item) {
|
|
67
|
-
return String(item);
|
|
68
|
-
});
|
|
69
|
-
args.unshift('Warning: ' + format);
|
|
70
|
-
} // We intentionally don't use spread (or .apply) directly because it
|
|
71
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
72
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Function.prototype.apply.call(console[level], console, args);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var useSyncExternalStore = React.useSyncExternalStore;
|
|
80
|
-
|
|
81
|
-
{
|
|
82
|
-
error("The main 'use-sync-external-store' entry point is not supported; all it " + "does is re-export useSyncExternalStore from the 'react' package, so " + 'it only works with React 18+.' + '\n\n' + 'If you wish to support React 16 and 17, import from ' + "'use-sync-external-store/shim' instead. It will fall back to a shimmed " + 'implementation when the native one is not available.' + '\n\n' + "If you only support React 18+, you can import directly from 'react'.");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
exports.useSyncExternalStore = useSyncExternalStore;
|
|
86
|
-
if (
|
|
87
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
88
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
89
|
-
'function'
|
|
90
|
-
) {
|
|
91
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
})();
|
|
11
|
+
"use strict";
|
|
12
|
+
if ("production" !== process.env.NODE_ENV) {
|
|
13
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
14
|
+
"function" ===
|
|
15
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart &&
|
|
16
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
17
|
+
var useSyncExternalStore$jscomp$inline_1 =
|
|
18
|
+
require("react").useSyncExternalStore;
|
|
19
|
+
console.error(
|
|
20
|
+
"The main 'use-sync-external-store' entry point is not supported; all it does is re-export useSyncExternalStore from the 'react' package, so it only works with React 18+.\n\nIf you wish to support React 16 and 17, import from 'use-sync-external-store/shim' instead. It will fall back to a shimmed implementation when the native one is not available.\n\nIf you only support React 18+, you can import directly from 'react'."
|
|
21
|
+
);
|
|
22
|
+
exports.useSyncExternalStore = useSyncExternalStore$jscomp$inline_1;
|
|
23
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
|
|
24
|
+
"function" ===
|
|
25
|
+
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
|
|
26
|
+
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
95
27
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-sync-external-store",
|
|
3
3
|
"description": "Backwards compatible shim for React's useSyncExternalStore. Works with any React that supports hooks.",
|
|
4
|
-
"version": "1.4.0
|
|
4
|
+
"version": "1.4.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/facebook/react.git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"react": "
|
|
22
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"react-17": "npm:react@^17",
|