@legendapp/state 3.0.0-alpha.1 → 3.0.0-alpha.3
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/.DS_Store +0 -0
- package/CHANGELOG.md +1 -831
- package/LICENSE +1 -21
- package/README.md +1 -141
- package/as/arrayAsRecord.d.mts +5 -0
- package/as/arrayAsRecord.d.ts +5 -0
- package/as/arrayAsRecord.js +28 -0
- package/as/arrayAsRecord.mjs +26 -0
- package/as/arrayAsSet.d.mts +5 -0
- package/as/arrayAsSet.d.ts +5 -0
- package/as/arrayAsSet.js +13 -0
- package/as/arrayAsSet.mjs +11 -0
- package/as/arrayAsString.d.mts +5 -0
- package/as/arrayAsString.d.ts +5 -0
- package/as/arrayAsString.js +13 -0
- package/as/arrayAsString.mjs +11 -0
- package/as/numberAsString.d.mts +5 -0
- package/as/numberAsString.d.ts +5 -0
- package/as/numberAsString.js +13 -0
- package/as/numberAsString.mjs +11 -0
- package/as/recordAsArray.d.mts +5 -0
- package/as/recordAsArray.d.ts +5 -0
- package/as/recordAsArray.js +25 -0
- package/as/recordAsArray.mjs +23 -0
- package/as/recordAsString.d.mts +5 -0
- package/as/recordAsString.d.ts +5 -0
- package/as/recordAsString.js +13 -0
- package/as/recordAsString.mjs +11 -0
- package/as/setAsArray.d.mts +5 -0
- package/as/setAsArray.d.ts +5 -0
- package/as/setAsArray.js +13 -0
- package/as/setAsArray.mjs +11 -0
- package/as/setAsString.d.mts +5 -0
- package/as/setAsString.d.ts +5 -0
- package/as/setAsString.js +13 -0
- package/as/setAsString.mjs +11 -0
- package/as/stringAsArray.d.mts +5 -0
- package/as/stringAsArray.d.ts +5 -0
- package/as/stringAsArray.js +13 -0
- package/as/stringAsArray.mjs +11 -0
- package/as/stringAsNumber.d.mts +5 -0
- package/as/stringAsNumber.d.ts +5 -0
- package/as/stringAsNumber.js +16 -0
- package/as/stringAsNumber.mjs +14 -0
- package/as/stringAsRecord.d.mts +5 -0
- package/as/stringAsRecord.d.ts +5 -0
- package/as/stringAsRecord.js +15 -0
- package/as/stringAsRecord.mjs +13 -0
- package/as/stringAsSet.d.mts +5 -0
- package/as/stringAsSet.d.ts +5 -0
- package/as/stringAsSet.js +13 -0
- package/as/stringAsSet.mjs +11 -0
- package/babel.d.mts +21 -0
- package/babel.d.ts +21 -2
- package/babel.js +57 -53
- package/babel.mjs +65 -0
- package/config/enable$GetSet.js +13 -14
- package/config/enable$GetSet.mjs +13 -14
- package/config/enableReactComponents.d.mts +9 -0
- package/config/enableReactComponents.d.ts +4 -2
- package/config/enableReactComponents.js +13 -10
- package/config/enableReactComponents.mjs +13 -10
- package/config/enableReactNativeComponents.d.mts +22 -0
- package/config/enableReactNativeComponents.d.ts +6 -4
- package/config/enableReactNativeComponents.js +43 -47
- package/config/enableReactNativeComponents.mjs +43 -47
- package/config/enableReactTracking.d.mts +7 -0
- package/config/enableReactTracking.d.ts +3 -2
- package/config/enableReactTracking.js +33 -38
- package/config/enableReactTracking.mjs +33 -38
- package/config/enableReactUse.d.mts +10 -0
- package/config/enableReactUse.d.ts +4 -1
- package/config/enableReactUse.js +15 -14
- package/config/enableReactUse.mjs +15 -14
- package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
- package/config/enable_GetSet.d.ts +10 -0
- package/config/enable_PeekAssign.d.mts +10 -0
- package/config/enable_PeekAssign.d.ts +4 -2
- package/config/enable_PeekAssign.js +13 -14
- package/config/enable_PeekAssign.mjs +13 -14
- package/helpers/pageHash.d.mts +9 -0
- package/helpers/pageHash.d.ts +2 -0
- package/helpers/pageHash.js +25 -30
- package/helpers/pageHash.mjs +25 -30
- package/helpers/pageHashParams.d.mts +9 -0
- package/helpers/pageHashParams.d.ts +2 -0
- package/helpers/pageHashParams.js +34 -37
- package/helpers/pageHashParams.mjs +34 -37
- package/helpers/time.d.mts +6 -0
- package/helpers/time.d.ts +6 -3
- package/helpers/time.js +17 -17
- package/helpers/time.mjs +17 -17
- package/helpers/trackHistory.d.mts +6 -0
- package/helpers/trackHistory.d.ts +4 -2
- package/helpers/trackHistory.js +13 -16
- package/helpers/trackHistory.mjs +13 -16
- package/helpers/undoRedo.d.mts +37 -0
- package/helpers/undoRedo.d.ts +5 -3
- package/helpers/undoRedo.js +59 -94
- package/helpers/undoRedo.mjs +59 -94
- package/index.d.mts +404 -0
- package/index.d.ts +371 -28
- package/index.js +2015 -2166
- package/index.mjs +2015 -2166
- package/package.json +254 -195
- package/persist-plugins/async-storage.d.mts +18 -0
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +79 -86
- package/persist-plugins/async-storage.mjs +79 -86
- package/persist-plugins/indexeddb.d.mts +29 -0
- package/persist-plugins/indexeddb.d.ts +6 -3
- package/persist-plugins/indexeddb.js +331 -352
- package/persist-plugins/indexeddb.mjs +331 -352
- package/persist-plugins/local-storage.d.mts +23 -0
- package/persist-plugins/local-storage.d.ts +8 -5
- package/persist-plugins/local-storage.js +74 -76
- package/persist-plugins/local-storage.mjs +74 -76
- package/persist-plugins/mmkv.d.mts +18 -0
- package/persist-plugins/mmkv.d.ts +6 -3
- package/persist-plugins/mmkv.js +82 -86
- package/persist-plugins/mmkv.mjs +82 -86
- package/react-hooks/createObservableHook.d.mts +5 -0
- package/react-hooks/createObservableHook.d.ts +4 -1
- package/react-hooks/createObservableHook.js +29 -30
- package/react-hooks/createObservableHook.mjs +25 -30
- package/react-hooks/useHover.d.mts +5 -0
- package/react-hooks/useHover.d.ts +5 -3
- package/react-hooks/useHover.js +29 -29
- package/react-hooks/useHover.mjs +29 -29
- package/react-hooks/useMeasure.d.mts +9 -0
- package/react-hooks/useMeasure.d.ts +5 -2
- package/react-hooks/useMeasure.js +30 -32
- package/react-hooks/useMeasure.mjs +30 -32
- package/react-hooks/useObservableNextRouter.d.mts +35 -0
- package/react-hooks/useObservableNextRouter.d.ts +9 -7
- package/react-hooks/useObservableNextRouter.js +64 -77
- package/react-hooks/useObservableNextRouter.mjs +60 -77
- package/react.d.mts +157 -0
- package/react.d.ts +157 -21
- package/react.js +458 -749
- package/react.mjs +457 -752
- package/sync-plugins/crud.d.mts +54 -0
- package/sync-plugins/crud.d.ts +12 -10
- package/sync-plugins/crud.js +253 -270
- package/sync-plugins/crud.mjs +253 -270
- package/sync-plugins/fetch.d.mts +21 -0
- package/sync-plugins/fetch.d.ts +7 -4
- package/sync-plugins/fetch.js +50 -37
- package/sync-plugins/fetch.mjs +50 -37
- package/sync-plugins/keel.d.mts +108 -0
- package/sync-plugins/keel.d.ts +17 -15
- package/sync-plugins/keel.js +229 -462
- package/sync-plugins/keel.mjs +227 -464
- package/sync-plugins/supabase.d.mts +39 -0
- package/sync-plugins/supabase.d.ts +16 -14
- package/sync-plugins/supabase.js +128 -128
- package/sync-plugins/supabase.mjs +128 -128
- package/sync-plugins/tanstack-query.d.mts +14 -0
- package/sync-plugins/tanstack-query.d.ts +7 -4
- package/sync-plugins/tanstack-query.js +51 -57
- package/sync-plugins/tanstack-query.mjs +51 -57
- package/sync-plugins/tanstack-react-query.d.mts +8 -0
- package/sync-plugins/tanstack-react-query.d.ts +6 -1
- package/sync-plugins/tanstack-react-query.js +2 -2
- package/sync-plugins/tanstack-react-query.mjs +2 -2
- package/sync.d.mts +351 -0
- package/sync.d.ts +349 -9
- package/sync.js +910 -964
- package/sync.mjs +920 -974
- package/trace.d.mts +9 -0
- package/trace.d.ts +9 -4
- package/trace.js +72 -62
- package/trace.mjs +72 -62
- package/types/babel.d.ts +1 -12
- package/babel.js.map +0 -1
- package/config/enable$GetSet.js.map +0 -1
- package/config/enable$GetSet.mjs.map +0 -1
- package/config/enableReactComponents.js.map +0 -1
- package/config/enableReactComponents.mjs.map +0 -1
- package/config/enableReactNativeComponents.js.map +0 -1
- package/config/enableReactNativeComponents.mjs.map +0 -1
- package/config/enableReactTracking.js.map +0 -1
- package/config/enableReactTracking.mjs.map +0 -1
- package/config/enableReactUse.js.map +0 -1
- package/config/enableReactUse.mjs.map +0 -1
- package/config/enable_PeekAssign.js.map +0 -1
- package/config/enable_PeekAssign.mjs.map +0 -1
- package/helpers/pageHash.js.map +0 -1
- package/helpers/pageHash.mjs.map +0 -1
- package/helpers/pageHashParams.js.map +0 -1
- package/helpers/pageHashParams.mjs.map +0 -1
- package/helpers/time.js.map +0 -1
- package/helpers/time.mjs.map +0 -1
- package/helpers/trackHistory.js.map +0 -1
- package/helpers/trackHistory.mjs.map +0 -1
- package/helpers/undoRedo.js.map +0 -1
- package/helpers/undoRedo.mjs.map +0 -1
- package/history.d.ts +0 -1
- package/history.js +0 -24
- package/history.js.map +0 -1
- package/history.mjs +0 -22
- package/history.mjs.map +0 -1
- package/index.js.map +0 -1
- package/index.mjs.map +0 -1
- package/persist-plugins/async-storage.js.map +0 -1
- package/persist-plugins/async-storage.mjs.map +0 -1
- package/persist-plugins/indexeddb.js.map +0 -1
- package/persist-plugins/indexeddb.mjs.map +0 -1
- package/persist-plugins/local-storage.js.map +0 -1
- package/persist-plugins/local-storage.mjs.map +0 -1
- package/persist-plugins/mmkv.js.map +0 -1
- package/persist-plugins/mmkv.mjs.map +0 -1
- package/react-hooks/createObservableHook.js.map +0 -1
- package/react-hooks/createObservableHook.mjs.map +0 -1
- package/react-hooks/useHover.js.map +0 -1
- package/react-hooks/useHover.mjs.map +0 -1
- package/react-hooks/useMeasure.js.map +0 -1
- package/react-hooks/useMeasure.mjs.map +0 -1
- package/react-hooks/useObservableNextRouter.js.map +0 -1
- package/react-hooks/useObservableNextRouter.mjs.map +0 -1
- package/react.js.map +0 -1
- package/react.mjs.map +0 -1
- package/src/ObservableObject.ts +0 -1350
- package/src/ObservablePrimitive.ts +0 -62
- package/src/babel/index.ts +0 -83
- package/src/batching.ts +0 -357
- package/src/computed.ts +0 -18
- package/src/config/enable$GetSet.ts +0 -30
- package/src/config/enableReactComponents.ts +0 -26
- package/src/config/enableReactNativeComponents.ts +0 -102
- package/src/config/enableReactTracking.ts +0 -62
- package/src/config/enableReactUse.ts +0 -32
- package/src/config/enable_PeekAssign.ts +0 -31
- package/src/config.ts +0 -47
- package/src/createObservable.ts +0 -47
- package/src/event.ts +0 -26
- package/src/globals.ts +0 -235
- package/src/helpers/pageHash.ts +0 -41
- package/src/helpers/pageHashParams.ts +0 -55
- package/src/helpers/time.ts +0 -30
- package/src/helpers/trackHistory.ts +0 -29
- package/src/helpers/undoRedo.ts +0 -111
- package/src/helpers.ts +0 -231
- package/src/is.ts +0 -63
- package/src/linked.ts +0 -17
- package/src/observable.ts +0 -32
- package/src/observableInterfaces.ts +0 -151
- package/src/observableTypes.ts +0 -232
- package/src/observe.ts +0 -89
- package/src/old-plugins/firebase.ts +0 -1053
- package/src/onChange.ts +0 -146
- package/src/persist/configureObservablePersistence.ts +0 -7
- package/src/persist/fieldTransformer.ts +0 -149
- package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
- package/src/persist/persistObservable.ts +0 -1034
- package/src/persist-plugins/async-storage.ts +0 -99
- package/src/persist-plugins/indexeddb.ts +0 -439
- package/src/persist-plugins/local-storage.ts +0 -86
- package/src/persist-plugins/mmkv.ts +0 -91
- package/src/proxy.ts +0 -28
- package/src/react/Computed.tsx +0 -8
- package/src/react/For.tsx +0 -116
- package/src/react/Memo.tsx +0 -4
- package/src/react/Reactive.tsx +0 -53
- package/src/react/Show.tsx +0 -33
- package/src/react/Switch.tsx +0 -43
- package/src/react/react-globals.ts +0 -3
- package/src/react/reactInterfaces.ts +0 -32
- package/src/react/reactive-observer.tsx +0 -210
- package/src/react/useComputed.ts +0 -36
- package/src/react/useEffectOnce.ts +0 -41
- package/src/react/useIsMounted.ts +0 -16
- package/src/react/useMount.ts +0 -15
- package/src/react/useObservable.ts +0 -24
- package/src/react/useObservableReducer.ts +0 -52
- package/src/react/useObservableState.ts +0 -30
- package/src/react/useObserve.ts +0 -54
- package/src/react/useObserveEffect.ts +0 -40
- package/src/react/usePauseProvider.tsx +0 -16
- package/src/react/useSelector.ts +0 -167
- package/src/react/useUnmount.ts +0 -8
- package/src/react/useWhen.ts +0 -9
- package/src/react-hooks/createObservableHook.ts +0 -53
- package/src/react-hooks/useHover.ts +0 -40
- package/src/react-hooks/useMeasure.ts +0 -48
- package/src/react-hooks/useObservableNextRouter.ts +0 -137
- package/src/retry.ts +0 -71
- package/src/setupTracking.ts +0 -26
- package/src/sync/activateSyncedNode.ts +0 -128
- package/src/sync/configureObservableSync.ts +0 -7
- package/src/sync/persistTypes.ts +0 -216
- package/src/sync/syncHelpers.ts +0 -180
- package/src/sync/syncObservable.ts +0 -1056
- package/src/sync/syncObservableAdapter.ts +0 -31
- package/src/sync/syncTypes.ts +0 -189
- package/src/sync/synced.ts +0 -21
- package/src/sync-plugins/crud.ts +0 -412
- package/src/sync-plugins/fetch.ts +0 -80
- package/src/sync-plugins/keel.ts +0 -495
- package/src/sync-plugins/supabase.ts +0 -249
- package/src/sync-plugins/tanstack-query.ts +0 -113
- package/src/sync-plugins/tanstack-react-query.ts +0 -12
- package/src/trace/traceHelpers.ts +0 -11
- package/src/trace/useTraceListeners.ts +0 -34
- package/src/trace/useTraceUpdates.ts +0 -24
- package/src/trace/useVerifyNotTracking.ts +0 -33
- package/src/trace/useVerifyOneRender.ts +0 -10
- package/src/trackSelector.ts +0 -52
- package/src/tracking.ts +0 -43
- package/src/types/babel.d.ts +0 -12
- package/src/when.ts +0 -75
- package/sync-plugins/crud.js.map +0 -1
- package/sync-plugins/crud.mjs.map +0 -1
- package/sync-plugins/fetch.js.map +0 -1
- package/sync-plugins/fetch.mjs.map +0 -1
- package/sync-plugins/keel.js.map +0 -1
- package/sync-plugins/keel.mjs.map +0 -1
- package/sync-plugins/supabase.js.map +0 -1
- package/sync-plugins/supabase.mjs.map +0 -1
- package/sync-plugins/tanstack-query.js.map +0 -1
- package/sync-plugins/tanstack-query.mjs.map +0 -1
- package/sync-plugins/tanstack-react-query.js.map +0 -1
- package/sync-plugins/tanstack-react-query.mjs.map +0 -1
- package/sync.js.map +0 -1
- package/sync.mjs.map +0 -1
- package/trace.js.map +0 -1
- package/trace.mjs.map +0 -1
package/react.js
CHANGED
|
@@ -1,826 +1,536 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var state = require('@legendapp/state');
|
|
4
|
-
var
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
8
|
|
|
8
|
-
var
|
|
9
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
* @license React
|
|
12
|
-
* use-sync-external-store-shim.production.min.js
|
|
13
|
-
*
|
|
14
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
15
|
-
*
|
|
16
|
-
* This source code is licensed under the MIT license found in the
|
|
17
|
-
* LICENSE file in the root directory of this source tree.
|
|
18
|
-
*/
|
|
11
|
+
// src/react/Computed.tsx
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
24
|
-
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
25
|
-
var e=require$$0;function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
|
|
26
|
-
function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
|
|
27
|
-
return useSyncExternalStoreShim_production_min;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var useSyncExternalStoreShim_development = {};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @license React
|
|
34
|
-
* use-sync-external-store-shim.development.js
|
|
35
|
-
*
|
|
36
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
37
|
-
*
|
|
38
|
-
* This source code is licensed under the MIT license found in the
|
|
39
|
-
* LICENSE file in the root directory of this source tree.
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
var hasRequiredUseSyncExternalStoreShim_development;
|
|
43
|
-
|
|
44
|
-
function requireUseSyncExternalStoreShim_development () {
|
|
45
|
-
if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
|
|
46
|
-
hasRequiredUseSyncExternalStoreShim_development = 1;
|
|
47
|
-
|
|
48
|
-
if (process.env.NODE_ENV !== "production") {
|
|
49
|
-
(function() {
|
|
50
|
-
|
|
51
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
52
|
-
if (
|
|
53
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
54
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
|
|
55
|
-
'function'
|
|
56
|
-
) {
|
|
57
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
58
|
-
}
|
|
59
|
-
var React = require$$0;
|
|
60
|
-
|
|
61
|
-
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
62
|
-
|
|
63
|
-
function error(format) {
|
|
64
|
-
{
|
|
65
|
-
{
|
|
66
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
67
|
-
args[_key2 - 1] = arguments[_key2];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
printWarning('error', format, args);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function printWarning(level, format, args) {
|
|
76
|
-
// When changing this logic, you might want to also
|
|
77
|
-
// update consoleWithStackDev.www.js as well.
|
|
78
|
-
{
|
|
79
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
|
80
|
-
var stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
81
|
-
|
|
82
|
-
if (stack !== '') {
|
|
83
|
-
format += '%s';
|
|
84
|
-
args = args.concat([stack]);
|
|
85
|
-
} // eslint-disable-next-line react-internal/safe-string-coercion
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var argsWithFormat = args.map(function (item) {
|
|
89
|
-
return String(item);
|
|
90
|
-
}); // Careful: RN currently depends on this prefix
|
|
91
|
-
|
|
92
|
-
argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
|
|
93
|
-
// breaks IE9: https://github.com/facebook/react/issues/13610
|
|
94
|
-
// eslint-disable-next-line react-internal/no-production-logging
|
|
95
|
-
|
|
96
|
-
Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
102
|
-
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
103
|
-
*/
|
|
104
|
-
function is(x, y) {
|
|
105
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
|
|
106
|
-
;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
var objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
110
|
-
|
|
111
|
-
// dispatch for CommonJS interop named imports.
|
|
112
|
-
|
|
113
|
-
var useState = React.useState,
|
|
114
|
-
useEffect = React.useEffect,
|
|
115
|
-
useLayoutEffect = React.useLayoutEffect,
|
|
116
|
-
useDebugValue = React.useDebugValue;
|
|
117
|
-
var didWarnOld18Alpha = false;
|
|
118
|
-
var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
|
|
119
|
-
// because of a very particular set of implementation details and assumptions
|
|
120
|
-
// -- change any one of them and it will break. The most important assumption
|
|
121
|
-
// is that updates are always synchronous, because concurrent rendering is
|
|
122
|
-
// only available in versions of React that also have a built-in
|
|
123
|
-
// useSyncExternalStore API. And we only use this shim when the built-in API
|
|
124
|
-
// does not exist.
|
|
125
|
-
//
|
|
126
|
-
// Do not assume that the clever hacks used by this hook also work in general.
|
|
127
|
-
// The point of this shim is to replace the need for hacks by other libraries.
|
|
128
|
-
|
|
129
|
-
function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
130
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
131
|
-
// will need to track that themselves and return the correct value
|
|
132
|
-
// from `getSnapshot`.
|
|
133
|
-
getServerSnapshot) {
|
|
134
|
-
{
|
|
135
|
-
if (!didWarnOld18Alpha) {
|
|
136
|
-
if (React.startTransition !== undefined) {
|
|
137
|
-
didWarnOld18Alpha = true;
|
|
138
|
-
|
|
139
|
-
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.');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
} // Read the current snapshot from the store on every render. Again, this
|
|
143
|
-
// breaks the rules of React, and only works here because of specific
|
|
144
|
-
// implementation details, most importantly that updates are
|
|
145
|
-
// always synchronous.
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var value = getSnapshot();
|
|
149
|
-
|
|
150
|
-
{
|
|
151
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
152
|
-
var cachedValue = getSnapshot();
|
|
153
|
-
|
|
154
|
-
if (!objectIs(value, cachedValue)) {
|
|
155
|
-
error('The result of getSnapshot should be cached to avoid an infinite loop');
|
|
156
|
-
|
|
157
|
-
didWarnUncachedGetSnapshot = true;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
} // Because updates are synchronous, we don't queue them. Instead we force a
|
|
161
|
-
// re-render whenever the subscribed state changes by updating an some
|
|
162
|
-
// arbitrary useState hook. Then, during render, we call getSnapshot to read
|
|
163
|
-
// the current value.
|
|
164
|
-
//
|
|
165
|
-
// Because we don't actually use the state returned by the useState hook, we
|
|
166
|
-
// can save a bit of memory by storing other stuff in that slot.
|
|
167
|
-
//
|
|
168
|
-
// To implement the early bailout, we need to track some things on a mutable
|
|
169
|
-
// object. Usually, we would put that in a useRef hook, but we can stash it in
|
|
170
|
-
// our useState hook instead.
|
|
171
|
-
//
|
|
172
|
-
// To force a re-render, we call forceUpdate({inst}). That works because the
|
|
173
|
-
// new object always fails an equality check.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var _useState = useState({
|
|
177
|
-
inst: {
|
|
178
|
-
value: value,
|
|
179
|
-
getSnapshot: getSnapshot
|
|
180
|
-
}
|
|
181
|
-
}),
|
|
182
|
-
inst = _useState[0].inst,
|
|
183
|
-
forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
|
|
184
|
-
// in the layout phase so we can access it during the tearing check that
|
|
185
|
-
// happens on subscribe.
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
useLayoutEffect(function () {
|
|
189
|
-
inst.value = value;
|
|
190
|
-
inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
|
|
191
|
-
// commit phase if there was an interleaved mutation. In concurrent mode
|
|
192
|
-
// this can happen all the time, but even in synchronous mode, an earlier
|
|
193
|
-
// effect may have mutated the store.
|
|
194
|
-
|
|
195
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
196
|
-
// Force a re-render.
|
|
197
|
-
forceUpdate({
|
|
198
|
-
inst: inst
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
}, [subscribe, value, getSnapshot]);
|
|
202
|
-
useEffect(function () {
|
|
203
|
-
// Check for changes right before subscribing. Subsequent changes will be
|
|
204
|
-
// detected in the subscription handler.
|
|
205
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
206
|
-
// Force a re-render.
|
|
207
|
-
forceUpdate({
|
|
208
|
-
inst: inst
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
var handleStoreChange = function () {
|
|
213
|
-
// TODO: Because there is no cross-renderer API for batching updates, it's
|
|
214
|
-
// up to the consumer of this library to wrap their subscription event
|
|
215
|
-
// with unstable_batchedUpdates. Should we try to detect when this isn't
|
|
216
|
-
// the case and print a warning in development?
|
|
217
|
-
// The store changed. Check if the snapshot changed since the last time we
|
|
218
|
-
// read from the store.
|
|
219
|
-
if (checkIfSnapshotChanged(inst)) {
|
|
220
|
-
// Force a re-render.
|
|
221
|
-
forceUpdate({
|
|
222
|
-
inst: inst
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}; // Subscribe to the store and return a clean-up function.
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return subscribe(handleStoreChange);
|
|
229
|
-
}, [subscribe]);
|
|
230
|
-
useDebugValue(value);
|
|
231
|
-
return value;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function checkIfSnapshotChanged(inst) {
|
|
235
|
-
var latestGetSnapshot = inst.getSnapshot;
|
|
236
|
-
var prevValue = inst.value;
|
|
237
|
-
|
|
238
|
-
try {
|
|
239
|
-
var nextValue = latestGetSnapshot();
|
|
240
|
-
return !objectIs(prevValue, nextValue);
|
|
241
|
-
} catch (error) {
|
|
242
|
-
return true;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
247
|
-
// Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
|
248
|
-
// React do not expose a way to check if we're hydrating. So users of the shim
|
|
249
|
-
// will need to track that themselves and return the correct value
|
|
250
|
-
// from `getSnapshot`.
|
|
251
|
-
return getSnapshot();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
|
|
255
|
-
|
|
256
|
-
var isServerEnvironment = !canUseDOM;
|
|
257
|
-
|
|
258
|
-
var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
|
|
259
|
-
var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
|
|
260
|
-
|
|
261
|
-
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
|
|
262
|
-
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
|
|
263
|
-
if (
|
|
264
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
|
|
265
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
|
|
266
|
-
'function'
|
|
267
|
-
) {
|
|
268
|
-
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
})();
|
|
272
|
-
}
|
|
273
|
-
return useSyncExternalStoreShim_development;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
(function (module) {
|
|
277
|
-
|
|
278
|
-
if (process.env.NODE_ENV === 'production') {
|
|
279
|
-
module.exports = requireUseSyncExternalStoreShim_production_min();
|
|
280
|
-
} else {
|
|
281
|
-
module.exports = requireUseSyncExternalStoreShim_development();
|
|
282
|
-
}
|
|
283
|
-
} (shim));
|
|
284
|
-
|
|
285
|
-
const reactGlobals = {
|
|
286
|
-
inObserver: false,
|
|
13
|
+
// src/react/react-globals.ts
|
|
14
|
+
var reactGlobals = {
|
|
15
|
+
inObserver: false
|
|
287
16
|
};
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return (pauseContext || (pauseContext = require$$0.createContext(null)));
|
|
17
|
+
var pauseContext = void 0;
|
|
18
|
+
var getPauseContext = () => {
|
|
19
|
+
return pauseContext || (pauseContext = React.createContext(null));
|
|
292
20
|
};
|
|
293
21
|
function usePauseProvider() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
22
|
+
const [value] = React.useState(() => state.observable(false));
|
|
23
|
+
return {
|
|
24
|
+
PauseProvider: ({ children }) => React.createElement(getPauseContext().Provider, { value }, children),
|
|
25
|
+
isPaused$: value
|
|
26
|
+
};
|
|
299
27
|
}
|
|
300
28
|
|
|
29
|
+
// src/react/useSelector.ts
|
|
301
30
|
function createSelectorFunctions(options, isPaused$) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
31
|
+
let version = 0;
|
|
32
|
+
let notify;
|
|
33
|
+
let dispose;
|
|
34
|
+
let resubscribe;
|
|
35
|
+
let _selector;
|
|
36
|
+
let prev;
|
|
37
|
+
let pendingUpdate = void 0;
|
|
38
|
+
const run = () => {
|
|
39
|
+
dispose == null ? void 0 : dispose();
|
|
40
|
+
const {
|
|
41
|
+
value,
|
|
42
|
+
dispose: _dispose,
|
|
43
|
+
resubscribe: _resubscribe
|
|
44
|
+
} = state.trackSelector(
|
|
45
|
+
_selector,
|
|
46
|
+
_update,
|
|
47
|
+
void 0,
|
|
48
|
+
void 0,
|
|
49
|
+
/*createResubscribe*/
|
|
50
|
+
true
|
|
51
|
+
);
|
|
52
|
+
dispose = _dispose;
|
|
53
|
+
resubscribe = _resubscribe;
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
const _update = ({ value }) => {
|
|
57
|
+
if (isPaused$ == null ? void 0 : isPaused$.peek()) {
|
|
58
|
+
const next = pendingUpdate;
|
|
59
|
+
pendingUpdate = value;
|
|
60
|
+
if (next === void 0) {
|
|
61
|
+
state.when(
|
|
62
|
+
() => !isPaused$.get(),
|
|
63
|
+
() => {
|
|
64
|
+
const latest = pendingUpdate;
|
|
65
|
+
pendingUpdate = void 0;
|
|
66
|
+
_update({ value: latest });
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
let changed = options == null ? void 0 : options.skipCheck;
|
|
72
|
+
if (!changed) {
|
|
73
|
+
const newValue = run();
|
|
74
|
+
if (newValue !== prev || !state.isPrimitive(newValue) && newValue === value) {
|
|
75
|
+
changed = true;
|
|
345
76
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
77
|
+
}
|
|
78
|
+
if (changed) {
|
|
79
|
+
version++;
|
|
80
|
+
notify == null ? void 0 : notify();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
subscribe: (onStoreChange) => {
|
|
86
|
+
notify = onStoreChange;
|
|
87
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && !dispose && resubscribe) {
|
|
88
|
+
dispose = resubscribe();
|
|
89
|
+
}
|
|
90
|
+
return () => {
|
|
91
|
+
dispose == null ? void 0 : dispose();
|
|
92
|
+
dispose = void 0;
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
getVersion: () => version,
|
|
96
|
+
run: (selector) => {
|
|
97
|
+
_selector = selector;
|
|
98
|
+
return prev = run();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
368
101
|
}
|
|
369
102
|
function useSelector(selector, options) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
if (options === null || options === void 0 ? void 0 : options.suspense) {
|
|
388
|
-
// Note: Although it's not possible for an observable to be a promise, the selector may be a
|
|
389
|
-
// function that returns a Promise, so we handle that case too.
|
|
390
|
-
if (state.isPromise(value) ||
|
|
391
|
-
(!value && state.isObservable(selector) && state.syncState(selector).isLoaded.get() === false)) {
|
|
392
|
-
if (require$$0.use) {
|
|
393
|
-
require$$0.use(value);
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
throw value;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
103
|
+
var _a;
|
|
104
|
+
if (reactGlobals.inObserver && state.isObservable(selector) && !(options == null ? void 0 : options.suspense)) {
|
|
105
|
+
return state.computeSelector(selector);
|
|
106
|
+
}
|
|
107
|
+
let value;
|
|
108
|
+
try {
|
|
109
|
+
const isPaused$ = React.useContext(getPauseContext());
|
|
110
|
+
const selectorFn = React.useMemo(() => createSelectorFunctions(options, isPaused$), []);
|
|
111
|
+
const { subscribe, getVersion, run } = selectorFn;
|
|
112
|
+
value = run(selector);
|
|
113
|
+
index_js.useSyncExternalStore(subscribe, getVersion, getVersion);
|
|
114
|
+
if (options == null ? void 0 : options.suspense) {
|
|
115
|
+
if (state.isPromise(value) || !value && state.isObservable(selector) && state.syncState(selector).isLoaded.get() === false) {
|
|
116
|
+
if (React__default.default.use) {
|
|
117
|
+
React__default.default.use(value);
|
|
118
|
+
} else {
|
|
119
|
+
throw value;
|
|
399
120
|
}
|
|
121
|
+
}
|
|
400
122
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
throw err;
|
|
123
|
+
} catch (err) {
|
|
124
|
+
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && ((_a = err == null ? void 0 : err.message) == null ? void 0 : _a.includes("Rendered more"))) {
|
|
125
|
+
console.warn(
|
|
126
|
+
`[legend-state]: You may want to wrap this component in \`observer\` to fix the error of ${err.message}`
|
|
127
|
+
);
|
|
407
128
|
}
|
|
408
|
-
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
return value;
|
|
409
132
|
}
|
|
410
133
|
|
|
134
|
+
// src/react/Computed.tsx
|
|
411
135
|
function Computed({ children }) {
|
|
412
|
-
|
|
136
|
+
return useSelector(() => state.computeSelector(state.computeSelector(children)), { skipCheck: true });
|
|
413
137
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
//
|
|
419
|
-
function
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
138
|
+
var hasSymbol = typeof Symbol === "function" && Symbol.for;
|
|
139
|
+
var didWarnProps = false;
|
|
140
|
+
function createReactiveComponent(component, observe3, reactive2, bindKeys) {
|
|
141
|
+
const ReactForwardRefSymbol = hasSymbol ? Symbol.for("react.forward_ref") : (
|
|
142
|
+
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
143
|
+
typeof React.forwardRef === "function" && React.forwardRef((props) => null)["$$typeof"]
|
|
144
|
+
);
|
|
145
|
+
const ReactMemoSymbol = hasSymbol ? Symbol.for("react.memo") : (
|
|
146
|
+
// eslint-disable-next-line react/display-name, @typescript-eslint/no-unused-vars
|
|
147
|
+
typeof React.forwardRef === "function" && React.memo((props) => null)["$$typeof"]
|
|
148
|
+
);
|
|
149
|
+
if (component["__legend_proxied"])
|
|
150
|
+
return component;
|
|
151
|
+
let useForwardRef = false;
|
|
152
|
+
let useMemo5 = false;
|
|
153
|
+
let render = component;
|
|
154
|
+
if (ReactMemoSymbol && render["$$typeof"] === ReactMemoSymbol && render["type"]) {
|
|
155
|
+
useMemo5 = true;
|
|
156
|
+
render = render["type"];
|
|
157
|
+
}
|
|
158
|
+
if (ReactForwardRefSymbol && render["$$typeof"] === ReactForwardRefSymbol) {
|
|
159
|
+
useForwardRef = true;
|
|
160
|
+
render = render["render"];
|
|
161
|
+
if (process.env.NODE_ENV === "development" && typeof render !== "function") {
|
|
162
|
+
throw new Error(`[legend-state] \`render\` property of ForwardRef was not a function`);
|
|
439
163
|
}
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
props[key] = useSelector(p, { skipCheck: true });
|
|
462
|
-
}
|
|
463
|
-
// Convert reactive props
|
|
464
|
-
else if (key.startsWith('$') || key.endsWith('$')) {
|
|
465
|
-
// TODOV3 Add this warning
|
|
466
|
-
// TODOV4 Remove the deprecated endsWith option
|
|
467
|
-
if (process.env.NODE_ENV === 'development' && !didWarnProps && key.endsWith('$')) {
|
|
468
|
-
didWarnProps = true;
|
|
469
|
-
console.warn(`[legend-state] Reactive props were changed to start with $ instead of end with $ in version 2.0. So please change ${key} to $${key.replace('$', '')}. See https://legendapp.com/open-source/state/migrating for more details.`);
|
|
470
|
-
}
|
|
471
|
-
const k = key.endsWith('$') ? key.slice(0, -1) : key.slice(1);
|
|
472
|
-
// Return raw value and listen to the selector for changes
|
|
473
|
-
const bind = bindKeys === null || bindKeys === void 0 ? void 0 : bindKeys[k];
|
|
474
|
-
const shouldBind = bind && state.isObservable(p);
|
|
475
|
-
propsOut[k] = shouldBind && (bind === null || bind === void 0 ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
476
|
-
// If this key is one of the bind keys set up a two-way binding
|
|
477
|
-
if (shouldBind) {
|
|
478
|
-
// Use the bind's defaultValue if value is undefined
|
|
479
|
-
if (bind.defaultValue !== undefined && propsOut[k] === undefined) {
|
|
480
|
-
propsOut[k] = bind.defaultValue;
|
|
481
|
-
}
|
|
482
|
-
if (bind.handler && bind.getValue) {
|
|
483
|
-
// Hook up the change lander
|
|
484
|
-
const handlerFn = (e) => {
|
|
485
|
-
var _a;
|
|
486
|
-
p.set(bind.getValue(e));
|
|
487
|
-
(_a = props[bind.handler]) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
488
|
-
};
|
|
489
|
-
propsOut[bind.handler] =
|
|
490
|
-
// If in development mode, don't memoize the handler. fix fast refresh bug
|
|
491
|
-
process.env.NODE_ENV === 'development'
|
|
492
|
-
? handlerFn
|
|
493
|
-
: require$$0.useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
// Delete the reactive key
|
|
497
|
-
delete propsOut[key];
|
|
498
|
-
}
|
|
499
|
-
else if (propsOut[key] === undefined) {
|
|
500
|
-
propsOut[key] = p;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
argArray[0] = propsOut;
|
|
164
|
+
}
|
|
165
|
+
const proxyHandler = {
|
|
166
|
+
apply(target, thisArg, argArray) {
|
|
167
|
+
if (reactive2) {
|
|
168
|
+
const props = argArray[0];
|
|
169
|
+
const propsOut = {};
|
|
170
|
+
const keys = Object.keys(props);
|
|
171
|
+
for (let i = 0; i < keys.length; i++) {
|
|
172
|
+
const key = keys[i];
|
|
173
|
+
const p = props[key];
|
|
174
|
+
if (key === "children" && (state.isFunction(p) || state.isObservable(p))) {
|
|
175
|
+
props[key] = useSelector(p, { skipCheck: true });
|
|
176
|
+
} else if (key.startsWith("$") || key.endsWith("$")) {
|
|
177
|
+
if (process.env.NODE_ENV === "development" && !didWarnProps && key.endsWith("$")) {
|
|
178
|
+
didWarnProps = true;
|
|
179
|
+
console.warn(
|
|
180
|
+
`[legend-state] Reactive props were changed to start with $ instead of end with $ in version 2.0. So please change ${key} to $${key.replace(
|
|
181
|
+
"$",
|
|
182
|
+
""
|
|
183
|
+
)}. See https://legendapp.com/open-source/state/migrating for more details.`
|
|
184
|
+
);
|
|
504
185
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
186
|
+
const k = key.endsWith("$") ? key.slice(0, -1) : key.slice(1);
|
|
187
|
+
const bind = bindKeys == null ? void 0 : bindKeys[k];
|
|
188
|
+
const shouldBind = bind && state.isObservable(p);
|
|
189
|
+
propsOut[k] = shouldBind && (bind == null ? void 0 : bind.selector) ? bind.selector(propsOut, p) : useSelector(p);
|
|
190
|
+
if (shouldBind) {
|
|
191
|
+
if (bind.defaultValue !== void 0 && propsOut[k] === void 0) {
|
|
192
|
+
propsOut[k] = bind.defaultValue;
|
|
193
|
+
}
|
|
194
|
+
if (bind.handler && bind.getValue) {
|
|
195
|
+
const handlerFn = (e) => {
|
|
196
|
+
var _a;
|
|
197
|
+
p.set(bind.getValue(e));
|
|
198
|
+
(_a = props[bind.handler]) == null ? void 0 : _a.call(props, e);
|
|
199
|
+
};
|
|
200
|
+
propsOut[bind.handler] = // If in development mode, don't memoize the handler. fix fast refresh bug
|
|
201
|
+
process.env.NODE_ENV === "development" ? handlerFn : React.useCallback(handlerFn, [props[bind.handler], bindKeys]);
|
|
202
|
+
}
|
|
516
203
|
}
|
|
517
|
-
|
|
518
|
-
|
|
204
|
+
delete propsOut[key];
|
|
205
|
+
} else if (propsOut[key] === void 0) {
|
|
206
|
+
propsOut[key] = p;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
argArray[0] = propsOut;
|
|
210
|
+
}
|
|
211
|
+
if (observe3) {
|
|
212
|
+
return useSelector(
|
|
213
|
+
() => {
|
|
214
|
+
reactGlobals.inObserver = true;
|
|
215
|
+
try {
|
|
216
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
217
|
+
} finally {
|
|
218
|
+
reactGlobals.inObserver = false;
|
|
519
219
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
ret['__legend_proxied'] = true;
|
|
527
|
-
}
|
|
528
|
-
else {
|
|
529
|
-
ret = proxy;
|
|
220
|
+
},
|
|
221
|
+
{ skipCheck: true }
|
|
222
|
+
);
|
|
223
|
+
} else {
|
|
224
|
+
return Reflect.apply(target, thisArg, argArray);
|
|
225
|
+
}
|
|
530
226
|
}
|
|
531
|
-
|
|
227
|
+
};
|
|
228
|
+
const proxy = new Proxy(render, proxyHandler);
|
|
229
|
+
let ret;
|
|
230
|
+
if (useForwardRef) {
|
|
231
|
+
ret = React.forwardRef(proxy);
|
|
232
|
+
ret["__legend_proxied"] = true;
|
|
233
|
+
} else {
|
|
234
|
+
ret = proxy;
|
|
235
|
+
}
|
|
236
|
+
return observe3 || useMemo5 ? React.memo(ret) : ret;
|
|
532
237
|
}
|
|
533
238
|
function observer(component) {
|
|
534
|
-
|
|
239
|
+
return createReactiveComponent(component, true);
|
|
535
240
|
}
|
|
536
241
|
function reactive(component, bindKeys) {
|
|
537
|
-
|
|
242
|
+
return createReactiveComponent(component, false, true, bindKeys);
|
|
538
243
|
}
|
|
539
244
|
function reactiveObserver(component, bindKeys) {
|
|
540
|
-
|
|
245
|
+
return createReactiveComponent(component, true, true, bindKeys);
|
|
541
246
|
}
|
|
542
247
|
function reactiveComponents(components) {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
|
|
248
|
+
return new Proxy(
|
|
249
|
+
{},
|
|
250
|
+
{
|
|
251
|
+
get(target, p) {
|
|
252
|
+
if (!target[p] && components[p]) {
|
|
253
|
+
target[p] = createReactiveComponent(components[p], false, true);
|
|
254
|
+
}
|
|
255
|
+
return target[p];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
);
|
|
551
259
|
}
|
|
552
260
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
261
|
+
// src/react/For.tsx
|
|
262
|
+
var { findIDKey, getNode, optimized } = state.internal;
|
|
263
|
+
var autoMemoCache = /* @__PURE__ */ new Map();
|
|
264
|
+
function For({
|
|
265
|
+
each,
|
|
266
|
+
optimized: isOptimized,
|
|
267
|
+
item,
|
|
268
|
+
itemProps,
|
|
269
|
+
sortValues,
|
|
270
|
+
children
|
|
271
|
+
}) {
|
|
272
|
+
var _a;
|
|
273
|
+
if (!each)
|
|
274
|
+
return null;
|
|
275
|
+
const value = useSelector(() => each.get(isOptimized ? optimized : true));
|
|
276
|
+
if (!item && children) {
|
|
277
|
+
const refChildren = React.useRef();
|
|
278
|
+
refChildren.current = children;
|
|
279
|
+
item = React.useMemo(() => observer(({ item$, id }) => refChildren.current(item$, id)), []);
|
|
280
|
+
} else {
|
|
281
|
+
if (item.$$typeof !== Symbol.for("react.memo")) {
|
|
282
|
+
let memod = autoMemoCache.get(item);
|
|
283
|
+
if (!memod) {
|
|
284
|
+
memod = React.memo(item);
|
|
285
|
+
autoMemoCache.set(item, memod);
|
|
286
|
+
}
|
|
287
|
+
item = memod;
|
|
568
288
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
289
|
+
}
|
|
290
|
+
if (!value)
|
|
291
|
+
return null;
|
|
292
|
+
const out = [];
|
|
293
|
+
const isArr = state.isArray(value);
|
|
294
|
+
if (isArr) {
|
|
295
|
+
const v0 = value[0];
|
|
296
|
+
const node = getNode(each);
|
|
297
|
+
const length = value.length;
|
|
298
|
+
const idField = length > 0 ? node && findIDKey(v0, node) || (v0.id !== void 0 ? "id" : v0.key !== void 0 ? "key" : void 0) : void 0;
|
|
299
|
+
const isIdFieldFunction = state.isFunction(idField);
|
|
300
|
+
for (let i = 0; i < length; i++) {
|
|
301
|
+
if (value[i]) {
|
|
302
|
+
const val = value[i];
|
|
303
|
+
const key = (_a = isIdFieldFunction ? idField(val) : val[idField]) != null ? _a : i;
|
|
304
|
+
const item$ = each[i];
|
|
305
|
+
const props = {
|
|
306
|
+
key,
|
|
307
|
+
id: key,
|
|
308
|
+
item$,
|
|
309
|
+
item: item$
|
|
310
|
+
};
|
|
311
|
+
out.push(React.createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
312
|
+
}
|
|
579
313
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
const isArr = state.isArray(value);
|
|
586
|
-
if (isArr) {
|
|
587
|
-
// Get the appropriate id field
|
|
588
|
-
const v0 = value[0];
|
|
589
|
-
const node = getNode(each);
|
|
590
|
-
const length = value.length;
|
|
591
|
-
const idField = length > 0
|
|
592
|
-
? (node && findIDKey(v0, node)) ||
|
|
593
|
-
(v0.id !== undefined ? 'id' : v0.key !== undefined ? 'key' : undefined)
|
|
594
|
-
: undefined;
|
|
595
|
-
const isIdFieldFunction = state.isFunction(idField);
|
|
596
|
-
for (let i = 0; i < length; i++) {
|
|
597
|
-
if (value[i]) {
|
|
598
|
-
const val = value[i];
|
|
599
|
-
const key = (_a = (isIdFieldFunction ? idField(val) : val[idField])) !== null && _a !== void 0 ? _a : i;
|
|
600
|
-
const item$ = each[i];
|
|
601
|
-
// TODOV3 Remove item
|
|
602
|
-
const props = {
|
|
603
|
-
key,
|
|
604
|
-
id: key,
|
|
605
|
-
item$,
|
|
606
|
-
item: item$,
|
|
607
|
-
};
|
|
608
|
-
out.push(require$$0.createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
609
|
-
}
|
|
610
|
-
}
|
|
314
|
+
} else {
|
|
315
|
+
const asMap = state.isMap(value);
|
|
316
|
+
const keys = asMap ? Array.from(value.keys()) : Object.keys(value);
|
|
317
|
+
if (sortValues) {
|
|
318
|
+
keys.sort((A, B) => sortValues(asMap ? value.get(A) : value[A], asMap ? value.get(B) : value[B], A, B));
|
|
611
319
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
key,
|
|
625
|
-
id: key,
|
|
626
|
-
item$,
|
|
627
|
-
item: item$,
|
|
628
|
-
};
|
|
629
|
-
out.push(require$$0.createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
630
|
-
}
|
|
631
|
-
}
|
|
320
|
+
for (let i = 0; i < keys.length; i++) {
|
|
321
|
+
const key = keys[i];
|
|
322
|
+
if (asMap ? value.get(key) : value[key]) {
|
|
323
|
+
const item$ = asMap ? each.get(key) : each[key];
|
|
324
|
+
const props = {
|
|
325
|
+
key,
|
|
326
|
+
id: key,
|
|
327
|
+
item$,
|
|
328
|
+
item: item$
|
|
329
|
+
};
|
|
330
|
+
out.push(React.createElement(item, itemProps ? Object.assign(props, itemProps) : props));
|
|
331
|
+
}
|
|
632
332
|
}
|
|
633
|
-
|
|
333
|
+
}
|
|
334
|
+
return out;
|
|
634
335
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
336
|
+
var Memo = React.memo(Computed, () => true);
|
|
337
|
+
var ReactiveFns = /* @__PURE__ */ new Map();
|
|
338
|
+
var ReactiveFnBinders = /* @__PURE__ */ new Map();
|
|
339
|
+
var Reactive = new Proxy(
|
|
340
|
+
{},
|
|
341
|
+
{
|
|
641
342
|
get(target, p) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
}
|
|
655
|
-
return target[p];
|
|
656
|
-
},
|
|
657
|
-
});
|
|
658
|
-
function configureReactive({ components, binders, }) {
|
|
659
|
-
if (components) {
|
|
660
|
-
for (const key in components) {
|
|
661
|
-
ReactiveFns.set(key, components[key]);
|
|
662
|
-
}
|
|
343
|
+
if (!target[p]) {
|
|
344
|
+
const Component = ReactiveFns.get(p) || p;
|
|
345
|
+
const render = React.forwardRef((props, ref) => {
|
|
346
|
+
const propsOut = { ...props };
|
|
347
|
+
if (ref && (state.isFunction(ref) || !state.isEmpty(ref))) {
|
|
348
|
+
propsOut.ref = ref;
|
|
349
|
+
}
|
|
350
|
+
return React.createElement(Component, propsOut);
|
|
351
|
+
});
|
|
352
|
+
target[p] = reactive(render, ReactiveFnBinders.get(p));
|
|
353
|
+
}
|
|
354
|
+
return target[p];
|
|
663
355
|
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
356
|
+
}
|
|
357
|
+
);
|
|
358
|
+
function configureReactive({
|
|
359
|
+
components,
|
|
360
|
+
binders
|
|
361
|
+
}) {
|
|
362
|
+
if (components) {
|
|
363
|
+
for (const key in components) {
|
|
364
|
+
ReactiveFns.set(key, components[key]);
|
|
668
365
|
}
|
|
366
|
+
}
|
|
367
|
+
if (binders) {
|
|
368
|
+
for (const key in binders) {
|
|
369
|
+
ReactiveFnBinders.set(key, binders[key]);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
669
372
|
}
|
|
670
|
-
|
|
671
373
|
function Show({ if: if_, ifReady, else: else_, wrap, children }) {
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
374
|
+
const value = useSelector(if_ != null ? if_ : ifReady);
|
|
375
|
+
const show = ifReady !== void 0 ? state.isObservableValueReady(value) : value;
|
|
376
|
+
const child = useSelector(
|
|
377
|
+
show ? state.isFunction(children) ? () => children(value) : children : else_ != null ? else_ : null,
|
|
378
|
+
{ skipCheck: true }
|
|
379
|
+
);
|
|
380
|
+
return wrap ? React.createElement(wrap, void 0, child) : child;
|
|
676
381
|
}
|
|
677
382
|
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
383
|
+
// src/react/Switch.tsx
|
|
384
|
+
function Switch({
|
|
385
|
+
value,
|
|
386
|
+
children
|
|
387
|
+
}) {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
const child = children[useSelector(value)];
|
|
390
|
+
return (_b = child ? child() : (_a = children["default"]) == null ? void 0 : _a.call(children)) != null ? _b : null;
|
|
683
391
|
}
|
|
684
|
-
|
|
685
392
|
function useComputed(compute, set, deps) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
393
|
+
if (!deps && state.isArray(set)) {
|
|
394
|
+
deps = set;
|
|
395
|
+
set = void 0;
|
|
396
|
+
}
|
|
397
|
+
const ref = React.useRef({});
|
|
398
|
+
ref.current.compute = compute;
|
|
399
|
+
ref.current.set = set;
|
|
400
|
+
return React.useMemo(
|
|
401
|
+
() => state.computed(
|
|
402
|
+
() => state.isFunction(ref.current.compute) ? ref.current.compute() : ref.current.compute,
|
|
403
|
+
set ? (value) => ref.current.set(value) : void 0
|
|
404
|
+
),
|
|
405
|
+
deps || []
|
|
406
|
+
);
|
|
694
407
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
if (ret && state.isFunction(ret)) {
|
|
723
|
-
current.dispose = ret;
|
|
724
|
-
return () => queueMicrotask(dispose);
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
else {
|
|
728
|
-
return dispose;
|
|
729
|
-
}
|
|
730
|
-
}, deps);
|
|
731
|
-
}
|
|
732
|
-
else {
|
|
733
|
-
require$$0.useEffect(effect, deps);
|
|
734
|
-
}
|
|
408
|
+
var useEffectOnce = (effect, deps) => {
|
|
409
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
410
|
+
const refDispose = React.useRef({ num: 0 });
|
|
411
|
+
React.useEffect(() => {
|
|
412
|
+
var _a;
|
|
413
|
+
const { current } = refDispose;
|
|
414
|
+
current.num++;
|
|
415
|
+
const dispose = () => {
|
|
416
|
+
if (current.dispose && current.num < 2) {
|
|
417
|
+
current.dispose();
|
|
418
|
+
current.dispose = void 0;
|
|
419
|
+
}
|
|
420
|
+
current.num--;
|
|
421
|
+
};
|
|
422
|
+
if (current.dispose === void 0) {
|
|
423
|
+
const ret = (_a = effect()) != null ? _a : null;
|
|
424
|
+
if (ret && state.isFunction(ret)) {
|
|
425
|
+
current.dispose = ret;
|
|
426
|
+
return () => queueMicrotask(dispose);
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
return dispose;
|
|
430
|
+
}
|
|
431
|
+
}, deps);
|
|
432
|
+
} else {
|
|
433
|
+
React.useEffect(effect, deps);
|
|
434
|
+
}
|
|
735
435
|
};
|
|
736
|
-
|
|
737
436
|
function useMount(fn) {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
}, []);
|
|
437
|
+
return useEffectOnce(() => {
|
|
438
|
+
const ret = fn();
|
|
439
|
+
if (!state.isPromise(ret)) {
|
|
440
|
+
return ret;
|
|
441
|
+
}
|
|
442
|
+
}, []);
|
|
745
443
|
}
|
|
746
|
-
|
|
747
|
-
const useMountOnce = useMount;
|
|
748
|
-
|
|
444
|
+
var useMountOnce = useMount;
|
|
749
445
|
function useObservable(initialValue) {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
return ref.current;
|
|
446
|
+
const ref = React.useRef();
|
|
447
|
+
if (!ref.current) {
|
|
448
|
+
ref.current = state.observable(initialValue);
|
|
449
|
+
}
|
|
450
|
+
return ref.current;
|
|
756
451
|
}
|
|
757
452
|
|
|
453
|
+
// src/react/useIsMounted.ts
|
|
758
454
|
function useIsMounted() {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
455
|
+
const obs = useObservable(false);
|
|
456
|
+
const { set } = obs;
|
|
457
|
+
useMountOnce(() => {
|
|
458
|
+
set(true);
|
|
459
|
+
return () => set(false);
|
|
460
|
+
});
|
|
461
|
+
return obs;
|
|
766
462
|
}
|
|
767
|
-
|
|
768
463
|
function useObservableReducer(reducer, initializerArg, initializer) {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
464
|
+
const obs = useObservable(
|
|
465
|
+
() => initializerArg !== void 0 && state.isFunction(initializerArg) ? initializer(initializerArg) : initializerArg
|
|
466
|
+
);
|
|
467
|
+
const dispatch = (action) => {
|
|
468
|
+
obs.set(reducer(obs.get(), action));
|
|
469
|
+
};
|
|
470
|
+
return [obs, dispatch];
|
|
774
471
|
}
|
|
775
472
|
|
|
473
|
+
// src/react/useUnmount.ts
|
|
776
474
|
function useUnmount(fn) {
|
|
777
|
-
|
|
475
|
+
return useMount(() => fn);
|
|
778
476
|
}
|
|
779
|
-
|
|
780
|
-
const useUnmountOnce = useUnmount;
|
|
477
|
+
var useUnmountOnce = useUnmount;
|
|
781
478
|
|
|
479
|
+
// src/react/useObserve.ts
|
|
782
480
|
function useObserve(selector, reactionOrOptions, options) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
useUnmountOnce(() => {
|
|
481
|
+
let reaction;
|
|
482
|
+
if (state.isFunction(reactionOrOptions)) {
|
|
483
|
+
reaction = reactionOrOptions;
|
|
484
|
+
} else {
|
|
485
|
+
options = reactionOrOptions;
|
|
486
|
+
}
|
|
487
|
+
const ref = React.useRef({});
|
|
488
|
+
ref.current.selector = selector;
|
|
489
|
+
ref.current.reaction = reaction;
|
|
490
|
+
if (!ref.current.dispose) {
|
|
491
|
+
ref.current.dispose = state.observe(
|
|
492
|
+
(e) => state.computeSelector(ref.current.selector, e),
|
|
493
|
+
(e) => {
|
|
797
494
|
var _a, _b;
|
|
798
|
-
(_b = (_a = ref.current)
|
|
799
|
-
|
|
800
|
-
|
|
495
|
+
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
496
|
+
},
|
|
497
|
+
options
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
useUnmountOnce(() => {
|
|
501
|
+
var _a, _b;
|
|
502
|
+
(_b = (_a = ref.current) == null ? void 0 : _a.dispose) == null ? void 0 : _b.call(_a);
|
|
503
|
+
});
|
|
504
|
+
return ref.current.dispose;
|
|
801
505
|
}
|
|
802
|
-
|
|
803
506
|
function useObserveEffect(selector, reactionOrOptions, options) {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
507
|
+
let reaction;
|
|
508
|
+
if (state.isFunction(reactionOrOptions)) {
|
|
509
|
+
reaction = reactionOrOptions;
|
|
510
|
+
} else {
|
|
511
|
+
options = reactionOrOptions;
|
|
512
|
+
}
|
|
513
|
+
const ref = React.useRef({ selector });
|
|
514
|
+
ref.current = { selector, reaction };
|
|
515
|
+
useMountOnce(
|
|
516
|
+
() => state.observe(
|
|
517
|
+
(e) => {
|
|
518
|
+
const { selector: selector2 } = ref.current;
|
|
519
|
+
return state.isFunction(selector2) ? selector2(e) : selector2;
|
|
520
|
+
},
|
|
521
|
+
(e) => {
|
|
522
|
+
var _a, _b;
|
|
523
|
+
return (_b = (_a = ref.current).reaction) == null ? void 0 : _b.call(_a, e);
|
|
524
|
+
},
|
|
525
|
+
options
|
|
526
|
+
)
|
|
527
|
+
);
|
|
817
528
|
}
|
|
818
|
-
|
|
819
529
|
function useWhen(predicate, effect) {
|
|
820
|
-
|
|
530
|
+
return React.useMemo(() => state.when(predicate, effect), []);
|
|
821
531
|
}
|
|
822
532
|
function useWhenReady(predicate, effect) {
|
|
823
|
-
|
|
533
|
+
return React.useMemo(() => state.whenReady(predicate, effect), []);
|
|
824
534
|
}
|
|
825
535
|
|
|
826
536
|
exports.Computed = Computed;
|
|
@@ -850,4 +560,3 @@ exports.useUnmount = useUnmount;
|
|
|
850
560
|
exports.useUnmountOnce = useUnmountOnce;
|
|
851
561
|
exports.useWhen = useWhen;
|
|
852
562
|
exports.useWhenReady = useWhenReady;
|
|
853
|
-
//# sourceMappingURL=react.js.map
|