@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.
Files changed (327) hide show
  1. package/.DS_Store +0 -0
  2. package/CHANGELOG.md +1 -831
  3. package/LICENSE +1 -21
  4. package/README.md +1 -141
  5. package/as/arrayAsRecord.d.mts +5 -0
  6. package/as/arrayAsRecord.d.ts +5 -0
  7. package/as/arrayAsRecord.js +28 -0
  8. package/as/arrayAsRecord.mjs +26 -0
  9. package/as/arrayAsSet.d.mts +5 -0
  10. package/as/arrayAsSet.d.ts +5 -0
  11. package/as/arrayAsSet.js +13 -0
  12. package/as/arrayAsSet.mjs +11 -0
  13. package/as/arrayAsString.d.mts +5 -0
  14. package/as/arrayAsString.d.ts +5 -0
  15. package/as/arrayAsString.js +13 -0
  16. package/as/arrayAsString.mjs +11 -0
  17. package/as/numberAsString.d.mts +5 -0
  18. package/as/numberAsString.d.ts +5 -0
  19. package/as/numberAsString.js +13 -0
  20. package/as/numberAsString.mjs +11 -0
  21. package/as/recordAsArray.d.mts +5 -0
  22. package/as/recordAsArray.d.ts +5 -0
  23. package/as/recordAsArray.js +25 -0
  24. package/as/recordAsArray.mjs +23 -0
  25. package/as/recordAsString.d.mts +5 -0
  26. package/as/recordAsString.d.ts +5 -0
  27. package/as/recordAsString.js +13 -0
  28. package/as/recordAsString.mjs +11 -0
  29. package/as/setAsArray.d.mts +5 -0
  30. package/as/setAsArray.d.ts +5 -0
  31. package/as/setAsArray.js +13 -0
  32. package/as/setAsArray.mjs +11 -0
  33. package/as/setAsString.d.mts +5 -0
  34. package/as/setAsString.d.ts +5 -0
  35. package/as/setAsString.js +13 -0
  36. package/as/setAsString.mjs +11 -0
  37. package/as/stringAsArray.d.mts +5 -0
  38. package/as/stringAsArray.d.ts +5 -0
  39. package/as/stringAsArray.js +13 -0
  40. package/as/stringAsArray.mjs +11 -0
  41. package/as/stringAsNumber.d.mts +5 -0
  42. package/as/stringAsNumber.d.ts +5 -0
  43. package/as/stringAsNumber.js +16 -0
  44. package/as/stringAsNumber.mjs +14 -0
  45. package/as/stringAsRecord.d.mts +5 -0
  46. package/as/stringAsRecord.d.ts +5 -0
  47. package/as/stringAsRecord.js +15 -0
  48. package/as/stringAsRecord.mjs +13 -0
  49. package/as/stringAsSet.d.mts +5 -0
  50. package/as/stringAsSet.d.ts +5 -0
  51. package/as/stringAsSet.js +13 -0
  52. package/as/stringAsSet.mjs +11 -0
  53. package/babel.d.mts +21 -0
  54. package/babel.d.ts +21 -2
  55. package/babel.js +57 -53
  56. package/babel.mjs +65 -0
  57. package/config/enable$GetSet.js +13 -14
  58. package/config/enable$GetSet.mjs +13 -14
  59. package/config/enableReactComponents.d.mts +9 -0
  60. package/config/enableReactComponents.d.ts +4 -2
  61. package/config/enableReactComponents.js +13 -10
  62. package/config/enableReactComponents.mjs +13 -10
  63. package/config/enableReactNativeComponents.d.mts +22 -0
  64. package/config/enableReactNativeComponents.d.ts +6 -4
  65. package/config/enableReactNativeComponents.js +43 -47
  66. package/config/enableReactNativeComponents.mjs +43 -47
  67. package/config/enableReactTracking.d.mts +7 -0
  68. package/config/enableReactTracking.d.ts +3 -2
  69. package/config/enableReactTracking.js +33 -38
  70. package/config/enableReactTracking.mjs +33 -38
  71. package/config/enableReactUse.d.mts +10 -0
  72. package/config/enableReactUse.d.ts +4 -1
  73. package/config/enableReactUse.js +15 -14
  74. package/config/enableReactUse.mjs +15 -14
  75. package/config/{enable$GetSet.d.ts → enable_GetSet.d.mts} +4 -2
  76. package/config/enable_GetSet.d.ts +10 -0
  77. package/config/enable_PeekAssign.d.mts +10 -0
  78. package/config/enable_PeekAssign.d.ts +4 -2
  79. package/config/enable_PeekAssign.js +13 -14
  80. package/config/enable_PeekAssign.mjs +13 -14
  81. package/helpers/pageHash.d.mts +9 -0
  82. package/helpers/pageHash.d.ts +2 -0
  83. package/helpers/pageHash.js +25 -30
  84. package/helpers/pageHash.mjs +25 -30
  85. package/helpers/pageHashParams.d.mts +9 -0
  86. package/helpers/pageHashParams.d.ts +2 -0
  87. package/helpers/pageHashParams.js +34 -37
  88. package/helpers/pageHashParams.mjs +34 -37
  89. package/helpers/time.d.mts +6 -0
  90. package/helpers/time.d.ts +6 -3
  91. package/helpers/time.js +17 -17
  92. package/helpers/time.mjs +17 -17
  93. package/helpers/trackHistory.d.mts +6 -0
  94. package/helpers/trackHistory.d.ts +4 -2
  95. package/helpers/trackHistory.js +13 -16
  96. package/helpers/trackHistory.mjs +13 -16
  97. package/helpers/undoRedo.d.mts +37 -0
  98. package/helpers/undoRedo.d.ts +5 -3
  99. package/helpers/undoRedo.js +59 -94
  100. package/helpers/undoRedo.mjs +59 -94
  101. package/index.d.mts +404 -0
  102. package/index.d.ts +371 -28
  103. package/index.js +2015 -2166
  104. package/index.mjs +2015 -2166
  105. package/package.json +254 -195
  106. package/persist-plugins/async-storage.d.mts +18 -0
  107. package/persist-plugins/async-storage.d.ts +6 -3
  108. package/persist-plugins/async-storage.js +79 -86
  109. package/persist-plugins/async-storage.mjs +79 -86
  110. package/persist-plugins/indexeddb.d.mts +29 -0
  111. package/persist-plugins/indexeddb.d.ts +6 -3
  112. package/persist-plugins/indexeddb.js +331 -352
  113. package/persist-plugins/indexeddb.mjs +331 -352
  114. package/persist-plugins/local-storage.d.mts +23 -0
  115. package/persist-plugins/local-storage.d.ts +8 -5
  116. package/persist-plugins/local-storage.js +74 -76
  117. package/persist-plugins/local-storage.mjs +74 -76
  118. package/persist-plugins/mmkv.d.mts +18 -0
  119. package/persist-plugins/mmkv.d.ts +6 -3
  120. package/persist-plugins/mmkv.js +82 -86
  121. package/persist-plugins/mmkv.mjs +82 -86
  122. package/react-hooks/createObservableHook.d.mts +5 -0
  123. package/react-hooks/createObservableHook.d.ts +4 -1
  124. package/react-hooks/createObservableHook.js +29 -30
  125. package/react-hooks/createObservableHook.mjs +25 -30
  126. package/react-hooks/useHover.d.mts +5 -0
  127. package/react-hooks/useHover.d.ts +5 -3
  128. package/react-hooks/useHover.js +29 -29
  129. package/react-hooks/useHover.mjs +29 -29
  130. package/react-hooks/useMeasure.d.mts +9 -0
  131. package/react-hooks/useMeasure.d.ts +5 -2
  132. package/react-hooks/useMeasure.js +30 -32
  133. package/react-hooks/useMeasure.mjs +30 -32
  134. package/react-hooks/useObservableNextRouter.d.mts +35 -0
  135. package/react-hooks/useObservableNextRouter.d.ts +9 -7
  136. package/react-hooks/useObservableNextRouter.js +64 -77
  137. package/react-hooks/useObservableNextRouter.mjs +60 -77
  138. package/react.d.mts +157 -0
  139. package/react.d.ts +157 -21
  140. package/react.js +458 -749
  141. package/react.mjs +457 -752
  142. package/sync-plugins/crud.d.mts +54 -0
  143. package/sync-plugins/crud.d.ts +12 -10
  144. package/sync-plugins/crud.js +253 -270
  145. package/sync-plugins/crud.mjs +253 -270
  146. package/sync-plugins/fetch.d.mts +21 -0
  147. package/sync-plugins/fetch.d.ts +7 -4
  148. package/sync-plugins/fetch.js +50 -37
  149. package/sync-plugins/fetch.mjs +50 -37
  150. package/sync-plugins/keel.d.mts +108 -0
  151. package/sync-plugins/keel.d.ts +17 -15
  152. package/sync-plugins/keel.js +229 -462
  153. package/sync-plugins/keel.mjs +227 -464
  154. package/sync-plugins/supabase.d.mts +39 -0
  155. package/sync-plugins/supabase.d.ts +16 -14
  156. package/sync-plugins/supabase.js +128 -128
  157. package/sync-plugins/supabase.mjs +128 -128
  158. package/sync-plugins/tanstack-query.d.mts +14 -0
  159. package/sync-plugins/tanstack-query.d.ts +7 -4
  160. package/sync-plugins/tanstack-query.js +51 -57
  161. package/sync-plugins/tanstack-query.mjs +51 -57
  162. package/sync-plugins/tanstack-react-query.d.mts +8 -0
  163. package/sync-plugins/tanstack-react-query.d.ts +6 -1
  164. package/sync-plugins/tanstack-react-query.js +2 -2
  165. package/sync-plugins/tanstack-react-query.mjs +2 -2
  166. package/sync.d.mts +351 -0
  167. package/sync.d.ts +349 -9
  168. package/sync.js +910 -964
  169. package/sync.mjs +920 -974
  170. package/trace.d.mts +9 -0
  171. package/trace.d.ts +9 -4
  172. package/trace.js +72 -62
  173. package/trace.mjs +72 -62
  174. package/types/babel.d.ts +1 -12
  175. package/babel.js.map +0 -1
  176. package/config/enable$GetSet.js.map +0 -1
  177. package/config/enable$GetSet.mjs.map +0 -1
  178. package/config/enableReactComponents.js.map +0 -1
  179. package/config/enableReactComponents.mjs.map +0 -1
  180. package/config/enableReactNativeComponents.js.map +0 -1
  181. package/config/enableReactNativeComponents.mjs.map +0 -1
  182. package/config/enableReactTracking.js.map +0 -1
  183. package/config/enableReactTracking.mjs.map +0 -1
  184. package/config/enableReactUse.js.map +0 -1
  185. package/config/enableReactUse.mjs.map +0 -1
  186. package/config/enable_PeekAssign.js.map +0 -1
  187. package/config/enable_PeekAssign.mjs.map +0 -1
  188. package/helpers/pageHash.js.map +0 -1
  189. package/helpers/pageHash.mjs.map +0 -1
  190. package/helpers/pageHashParams.js.map +0 -1
  191. package/helpers/pageHashParams.mjs.map +0 -1
  192. package/helpers/time.js.map +0 -1
  193. package/helpers/time.mjs.map +0 -1
  194. package/helpers/trackHistory.js.map +0 -1
  195. package/helpers/trackHistory.mjs.map +0 -1
  196. package/helpers/undoRedo.js.map +0 -1
  197. package/helpers/undoRedo.mjs.map +0 -1
  198. package/history.d.ts +0 -1
  199. package/history.js +0 -24
  200. package/history.js.map +0 -1
  201. package/history.mjs +0 -22
  202. package/history.mjs.map +0 -1
  203. package/index.js.map +0 -1
  204. package/index.mjs.map +0 -1
  205. package/persist-plugins/async-storage.js.map +0 -1
  206. package/persist-plugins/async-storage.mjs.map +0 -1
  207. package/persist-plugins/indexeddb.js.map +0 -1
  208. package/persist-plugins/indexeddb.mjs.map +0 -1
  209. package/persist-plugins/local-storage.js.map +0 -1
  210. package/persist-plugins/local-storage.mjs.map +0 -1
  211. package/persist-plugins/mmkv.js.map +0 -1
  212. package/persist-plugins/mmkv.mjs.map +0 -1
  213. package/react-hooks/createObservableHook.js.map +0 -1
  214. package/react-hooks/createObservableHook.mjs.map +0 -1
  215. package/react-hooks/useHover.js.map +0 -1
  216. package/react-hooks/useHover.mjs.map +0 -1
  217. package/react-hooks/useMeasure.js.map +0 -1
  218. package/react-hooks/useMeasure.mjs.map +0 -1
  219. package/react-hooks/useObservableNextRouter.js.map +0 -1
  220. package/react-hooks/useObservableNextRouter.mjs.map +0 -1
  221. package/react.js.map +0 -1
  222. package/react.mjs.map +0 -1
  223. package/src/ObservableObject.ts +0 -1350
  224. package/src/ObservablePrimitive.ts +0 -62
  225. package/src/babel/index.ts +0 -83
  226. package/src/batching.ts +0 -357
  227. package/src/computed.ts +0 -18
  228. package/src/config/enable$GetSet.ts +0 -30
  229. package/src/config/enableReactComponents.ts +0 -26
  230. package/src/config/enableReactNativeComponents.ts +0 -102
  231. package/src/config/enableReactTracking.ts +0 -62
  232. package/src/config/enableReactUse.ts +0 -32
  233. package/src/config/enable_PeekAssign.ts +0 -31
  234. package/src/config.ts +0 -47
  235. package/src/createObservable.ts +0 -47
  236. package/src/event.ts +0 -26
  237. package/src/globals.ts +0 -235
  238. package/src/helpers/pageHash.ts +0 -41
  239. package/src/helpers/pageHashParams.ts +0 -55
  240. package/src/helpers/time.ts +0 -30
  241. package/src/helpers/trackHistory.ts +0 -29
  242. package/src/helpers/undoRedo.ts +0 -111
  243. package/src/helpers.ts +0 -231
  244. package/src/is.ts +0 -63
  245. package/src/linked.ts +0 -17
  246. package/src/observable.ts +0 -32
  247. package/src/observableInterfaces.ts +0 -151
  248. package/src/observableTypes.ts +0 -232
  249. package/src/observe.ts +0 -89
  250. package/src/old-plugins/firebase.ts +0 -1053
  251. package/src/onChange.ts +0 -146
  252. package/src/persist/configureObservablePersistence.ts +0 -7
  253. package/src/persist/fieldTransformer.ts +0 -149
  254. package/src/persist/observablePersistRemoteFunctionsAdapter.ts +0 -39
  255. package/src/persist/persistObservable.ts +0 -1034
  256. package/src/persist-plugins/async-storage.ts +0 -99
  257. package/src/persist-plugins/indexeddb.ts +0 -439
  258. package/src/persist-plugins/local-storage.ts +0 -86
  259. package/src/persist-plugins/mmkv.ts +0 -91
  260. package/src/proxy.ts +0 -28
  261. package/src/react/Computed.tsx +0 -8
  262. package/src/react/For.tsx +0 -116
  263. package/src/react/Memo.tsx +0 -4
  264. package/src/react/Reactive.tsx +0 -53
  265. package/src/react/Show.tsx +0 -33
  266. package/src/react/Switch.tsx +0 -43
  267. package/src/react/react-globals.ts +0 -3
  268. package/src/react/reactInterfaces.ts +0 -32
  269. package/src/react/reactive-observer.tsx +0 -210
  270. package/src/react/useComputed.ts +0 -36
  271. package/src/react/useEffectOnce.ts +0 -41
  272. package/src/react/useIsMounted.ts +0 -16
  273. package/src/react/useMount.ts +0 -15
  274. package/src/react/useObservable.ts +0 -24
  275. package/src/react/useObservableReducer.ts +0 -52
  276. package/src/react/useObservableState.ts +0 -30
  277. package/src/react/useObserve.ts +0 -54
  278. package/src/react/useObserveEffect.ts +0 -40
  279. package/src/react/usePauseProvider.tsx +0 -16
  280. package/src/react/useSelector.ts +0 -167
  281. package/src/react/useUnmount.ts +0 -8
  282. package/src/react/useWhen.ts +0 -9
  283. package/src/react-hooks/createObservableHook.ts +0 -53
  284. package/src/react-hooks/useHover.ts +0 -40
  285. package/src/react-hooks/useMeasure.ts +0 -48
  286. package/src/react-hooks/useObservableNextRouter.ts +0 -137
  287. package/src/retry.ts +0 -71
  288. package/src/setupTracking.ts +0 -26
  289. package/src/sync/activateSyncedNode.ts +0 -128
  290. package/src/sync/configureObservableSync.ts +0 -7
  291. package/src/sync/persistTypes.ts +0 -216
  292. package/src/sync/syncHelpers.ts +0 -180
  293. package/src/sync/syncObservable.ts +0 -1056
  294. package/src/sync/syncObservableAdapter.ts +0 -31
  295. package/src/sync/syncTypes.ts +0 -189
  296. package/src/sync/synced.ts +0 -21
  297. package/src/sync-plugins/crud.ts +0 -412
  298. package/src/sync-plugins/fetch.ts +0 -80
  299. package/src/sync-plugins/keel.ts +0 -495
  300. package/src/sync-plugins/supabase.ts +0 -249
  301. package/src/sync-plugins/tanstack-query.ts +0 -113
  302. package/src/sync-plugins/tanstack-react-query.ts +0 -12
  303. package/src/trace/traceHelpers.ts +0 -11
  304. package/src/trace/useTraceListeners.ts +0 -34
  305. package/src/trace/useTraceUpdates.ts +0 -24
  306. package/src/trace/useVerifyNotTracking.ts +0 -33
  307. package/src/trace/useVerifyOneRender.ts +0 -10
  308. package/src/trackSelector.ts +0 -52
  309. package/src/tracking.ts +0 -43
  310. package/src/types/babel.d.ts +0 -12
  311. package/src/when.ts +0 -75
  312. package/sync-plugins/crud.js.map +0 -1
  313. package/sync-plugins/crud.mjs.map +0 -1
  314. package/sync-plugins/fetch.js.map +0 -1
  315. package/sync-plugins/fetch.mjs.map +0 -1
  316. package/sync-plugins/keel.js.map +0 -1
  317. package/sync-plugins/keel.mjs.map +0 -1
  318. package/sync-plugins/supabase.js.map +0 -1
  319. package/sync-plugins/supabase.mjs.map +0 -1
  320. package/sync-plugins/tanstack-query.js.map +0 -1
  321. package/sync-plugins/tanstack-query.mjs.map +0 -1
  322. package/sync-plugins/tanstack-react-query.js.map +0 -1
  323. package/sync-plugins/tanstack-react-query.mjs.map +0 -1
  324. package/sync.js.map +0 -1
  325. package/sync.mjs.map +0 -1
  326. package/trace.js.map +0 -1
  327. package/trace.mjs.map +0 -1
@@ -2,54 +2,50 @@ import { useRef } from 'react';
2
2
  import { configureReactive, useSelector } from '@legendapp/state/react';
3
3
  import { ActivityIndicator, Button, FlatList, Image, Pressable, ScrollView, SectionList, Switch, Text, TextInput, TouchableWithoutFeedback, View } from 'react-native';
4
4
 
5
+ // src/config/enableReactNativeComponents.ts
5
6
  function enableReactNativeComponents() {
6
- configureReactive({
7
- components: {
8
- ActivityIndicator: ActivityIndicator,
9
- Button: Button,
10
- FlatList: FlatList,
11
- Image: Image,
12
- Pressable: Pressable,
13
- ScrollView: ScrollView,
14
- SectionList: SectionList,
15
- Switch: Switch,
16
- Text: Text,
17
- TextInput: TextInput,
18
- TouchableWithoutFeedback: TouchableWithoutFeedback,
19
- View: View,
20
- },
21
- binders: {
22
- TextInput: {
23
- value: {
24
- handler: 'onChange',
25
- getValue: (e) => e.nativeEvent.text,
26
- defaultValue: '',
27
- },
28
- },
29
- Switch: {
30
- value: {
31
- handler: 'onValueChange',
32
- getValue: (e) => e,
33
- defaultValue: false,
34
- },
35
- },
36
- FlatList: {
37
- data: {
38
- selector: (propsOut, p) => {
39
- const state = useRef(0);
40
- // Increment renderNum whenever the array changes shallowly
41
- const [renderNum, value] = useSelector(() => [state.current++, p.get(true)]);
42
- // Set extraData to renderNum so that it will re-render when renderNum changes.
43
- // This is necessary because the observable array is mutable so changes to it
44
- // won't trigger re-renders by default.
45
- propsOut.extraData = renderNum;
46
- return value;
47
- },
48
- },
49
- },
50
- },
51
- });
7
+ configureReactive({
8
+ components: {
9
+ ActivityIndicator,
10
+ Button,
11
+ FlatList,
12
+ Image,
13
+ Pressable,
14
+ ScrollView,
15
+ SectionList,
16
+ Switch,
17
+ Text,
18
+ TextInput,
19
+ TouchableWithoutFeedback,
20
+ View
21
+ },
22
+ binders: {
23
+ TextInput: {
24
+ value: {
25
+ handler: "onChange",
26
+ getValue: (e) => e.nativeEvent.text,
27
+ defaultValue: ""
28
+ }
29
+ },
30
+ Switch: {
31
+ value: {
32
+ handler: "onValueChange",
33
+ getValue: (e) => e,
34
+ defaultValue: false
35
+ }
36
+ },
37
+ FlatList: {
38
+ data: {
39
+ selector: (propsOut, p) => {
40
+ const state = useRef(0);
41
+ const [renderNum, value] = useSelector(() => [state.current++, p.get(true)]);
42
+ propsOut.extraData = renderNum;
43
+ return value;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ });
52
49
  }
53
50
 
54
51
  export { enableReactNativeComponents };
55
- //# sourceMappingURL=enableReactNativeComponents.mjs.map
@@ -0,0 +1,7 @@
1
+ interface ReactTrackingOptions {
2
+ auto?: boolean;
3
+ warnUnobserved?: boolean;
4
+ }
5
+ declare function enableReactTracking({ auto, warnUnobserved }: ReactTrackingOptions): void;
6
+
7
+ export { enableReactTracking };
@@ -2,5 +2,6 @@ interface ReactTrackingOptions {
2
2
  auto?: boolean;
3
3
  warnUnobserved?: boolean;
4
4
  }
5
- export declare function enableReactTracking({ auto, warnUnobserved }: ReactTrackingOptions): void;
6
- export {};
5
+ declare function enableReactTracking({ auto, warnUnobserved }: ReactTrackingOptions): void;
6
+
7
+ export { enableReactTracking };
@@ -4,46 +4,41 @@ var state = require('@legendapp/state');
4
4
  var react$1 = require('@legendapp/state/react');
5
5
  var react = require('react');
6
6
 
7
+ // src/config/enableReactTracking.ts
7
8
  function enableReactTracking({ auto, warnUnobserved }) {
8
- const { get } = state.internal;
9
- if (auto || (process.env.NODE_ENV === 'development' && warnUnobserved)) {
10
- const ReactRenderContext = react.createContext(0);
11
- const needsSelector = () => {
12
- // If we're already tracking then we definitely don't need useSelector
13
- if (!state.tracking.current) {
14
- try {
15
- // If there's no dispatcher we're definitely not in React
16
- // This is an optimization to not need to run useContext. If in a future React version
17
- // this works differently we can change it or just remove it.
18
- const dispatcher = react.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
19
- if (dispatcher) {
20
- // If there's a dispatcher then we may be inside of a hook.
21
- // Attempt a useContext hook, which will throw an error if outside of render.
22
- react.useContext(ReactRenderContext);
23
- return true;
24
- }
25
- }
26
- catch (_a) { } // eslint-disable-line no-empty
9
+ const { get } = state.internal;
10
+ if (auto || process.env.NODE_ENV === "development" && warnUnobserved) {
11
+ const ReactRenderContext = react.createContext(0);
12
+ const needsSelector = () => {
13
+ if (!state.tracking.current) {
14
+ try {
15
+ const dispatcher = react.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
16
+ if (dispatcher) {
17
+ react.useContext(ReactRenderContext);
18
+ return true;
19
+ }
20
+ } catch (e) {
21
+ }
22
+ }
23
+ return false;
24
+ };
25
+ state.configureLegendState({
26
+ observableFunctions: {
27
+ get: (node, options) => {
28
+ if (needsSelector()) {
29
+ if (auto) {
30
+ return react$1.useSelector(() => get(node, options), state.isObject(options) ? options : void 0);
31
+ } else if (process.env.NODE_ENV === "development" && warnUnobserved) {
32
+ console.warn(
33
+ "[legend-state] Detected a `get()` call in an unobserved component. You may want to wrap it in observer: https://legendapp.com/open-source/state/react-api/#observer-hoc"
34
+ );
27
35
  }
28
- return false;
29
- };
30
- state.configureLegendState({
31
- observableFunctions: {
32
- get: (node, options) => {
33
- if (needsSelector()) {
34
- if (auto) {
35
- return react$1.useSelector(() => get(node, options), state.isObject(options) ? options : undefined);
36
- }
37
- else if (process.env.NODE_ENV === 'development' && warnUnobserved) {
38
- console.warn('[legend-state] Detected a `get()` call in an unobserved component. You may want to wrap it in observer: https://legendapp.com/open-source/state/react-api/#observer-hoc');
39
- }
40
- }
41
- return get(node, options);
42
- },
43
- },
44
- });
45
- }
36
+ }
37
+ return get(node, options);
38
+ }
39
+ }
40
+ });
41
+ }
46
42
  }
47
43
 
48
44
  exports.enableReactTracking = enableReactTracking;
49
- //# sourceMappingURL=enableReactTracking.js.map
@@ -2,46 +2,41 @@ import { configureLegendState, isObject, internal, tracking } from '@legendapp/s
2
2
  import { useSelector } from '@legendapp/state/react';
3
3
  import { createContext, __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, useContext } from 'react';
4
4
 
5
+ // src/config/enableReactTracking.ts
5
6
  function enableReactTracking({ auto, warnUnobserved }) {
6
- const { get } = internal;
7
- if (auto || (process.env.NODE_ENV === 'development' && warnUnobserved)) {
8
- const ReactRenderContext = createContext(0);
9
- const needsSelector = () => {
10
- // If we're already tracking then we definitely don't need useSelector
11
- if (!tracking.current) {
12
- try {
13
- // If there's no dispatcher we're definitely not in React
14
- // This is an optimization to not need to run useContext. If in a future React version
15
- // this works differently we can change it or just remove it.
16
- const dispatcher = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
17
- if (dispatcher) {
18
- // If there's a dispatcher then we may be inside of a hook.
19
- // Attempt a useContext hook, which will throw an error if outside of render.
20
- useContext(ReactRenderContext);
21
- return true;
22
- }
23
- }
24
- catch (_a) { } // eslint-disable-line no-empty
7
+ const { get } = internal;
8
+ if (auto || process.env.NODE_ENV === "development" && warnUnobserved) {
9
+ const ReactRenderContext = createContext(0);
10
+ const needsSelector = () => {
11
+ if (!tracking.current) {
12
+ try {
13
+ const dispatcher = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
14
+ if (dispatcher) {
15
+ useContext(ReactRenderContext);
16
+ return true;
17
+ }
18
+ } catch (e) {
19
+ }
20
+ }
21
+ return false;
22
+ };
23
+ configureLegendState({
24
+ observableFunctions: {
25
+ get: (node, options) => {
26
+ if (needsSelector()) {
27
+ if (auto) {
28
+ return useSelector(() => get(node, options), isObject(options) ? options : void 0);
29
+ } else if (process.env.NODE_ENV === "development" && warnUnobserved) {
30
+ console.warn(
31
+ "[legend-state] Detected a `get()` call in an unobserved component. You may want to wrap it in observer: https://legendapp.com/open-source/state/react-api/#observer-hoc"
32
+ );
25
33
  }
26
- return false;
27
- };
28
- configureLegendState({
29
- observableFunctions: {
30
- get: (node, options) => {
31
- if (needsSelector()) {
32
- if (auto) {
33
- return useSelector(() => get(node, options), isObject(options) ? options : undefined);
34
- }
35
- else if (process.env.NODE_ENV === 'development' && warnUnobserved) {
36
- console.warn('[legend-state] Detected a `get()` call in an unobserved component. You may want to wrap it in observer: https://legendapp.com/open-source/state/react-api/#observer-hoc');
37
- }
38
- }
39
- return get(node, options);
40
- },
41
- },
42
- });
43
- }
34
+ }
35
+ return get(node, options);
36
+ }
37
+ }
38
+ });
39
+ }
44
40
  }
45
41
 
46
42
  export { enableReactTracking };
47
- //# sourceMappingURL=enableReactTracking.mjs.map
@@ -0,0 +1,10 @@
1
+ import { UseSelectorOptions } from '@legendapp/state/react';
2
+
3
+ declare function enableReactUse(): void;
4
+ declare module '@legendapp/state' {
5
+ interface ImmutableObservableBase<T> {
6
+ use(options?: UseSelectorOptions): T;
7
+ }
8
+ }
9
+
10
+ export { enableReactUse };
@@ -1,7 +1,10 @@
1
1
  import { UseSelectorOptions } from '@legendapp/state/react';
2
- export declare function enableReactUse(): void;
2
+
3
+ declare function enableReactUse(): void;
3
4
  declare module '@legendapp/state' {
4
5
  interface ImmutableObservableBase<T> {
5
6
  use(options?: UseSelectorOptions): T;
6
7
  }
7
8
  }
9
+
10
+ export { enableReactUse };
@@ -3,21 +3,22 @@
3
3
  var state = require('@legendapp/state');
4
4
  var react = require('@legendapp/state/react');
5
5
 
6
- // TODO: Deprecated, remove in v4
7
- let didWarn = false;
6
+ // src/config/enableReactUse.ts
7
+ var didWarn = false;
8
8
  function enableReactUse() {
9
- state.configureLegendState({
10
- observableFunctions: {
11
- use: (node, options) => {
12
- if (process.env.NODE_ENV === 'development' && !didWarn) {
13
- didWarn = true;
14
- console.warn('[legend-state] enableReactUse() is deprecated. Please switch to using get() with observer, which is safer and more efficient. See https://legendapp.com/open-source/state/v3/react/react-api/');
15
- }
16
- return react.useSelector(state.internal.getProxy(node), options);
17
- },
18
- },
19
- });
9
+ state.configureLegendState({
10
+ observableFunctions: {
11
+ use: (node, options) => {
12
+ if (process.env.NODE_ENV === "development" && !didWarn) {
13
+ didWarn = true;
14
+ console.warn(
15
+ "[legend-state] enableReactUse() is deprecated. Please switch to using get() with observer, which is safer and more efficient. See https://legendapp.com/open-source/state/v3/react/react-api/"
16
+ );
17
+ }
18
+ return react.useSelector(state.internal.getProxy(node), options);
19
+ }
20
+ }
21
+ });
20
22
  }
21
23
 
22
24
  exports.enableReactUse = enableReactUse;
23
- //# sourceMappingURL=enableReactUse.js.map
@@ -1,21 +1,22 @@
1
1
  import { configureLegendState, internal } from '@legendapp/state';
2
2
  import { useSelector } from '@legendapp/state/react';
3
3
 
4
- // TODO: Deprecated, remove in v4
5
- let didWarn = false;
4
+ // src/config/enableReactUse.ts
5
+ var didWarn = false;
6
6
  function enableReactUse() {
7
- configureLegendState({
8
- observableFunctions: {
9
- use: (node, options) => {
10
- if (process.env.NODE_ENV === 'development' && !didWarn) {
11
- didWarn = true;
12
- console.warn('[legend-state] enableReactUse() is deprecated. Please switch to using get() with observer, which is safer and more efficient. See https://legendapp.com/open-source/state/v3/react/react-api/');
13
- }
14
- return useSelector(internal.getProxy(node), options);
15
- },
16
- },
17
- });
7
+ configureLegendState({
8
+ observableFunctions: {
9
+ use: (node, options) => {
10
+ if (process.env.NODE_ENV === "development" && !didWarn) {
11
+ didWarn = true;
12
+ console.warn(
13
+ "[legend-state] enableReactUse() is deprecated. Please switch to using get() with observer, which is safer and more efficient. See https://legendapp.com/open-source/state/v3/react/react-api/"
14
+ );
15
+ }
16
+ return useSelector(internal.getProxy(node), options);
17
+ }
18
+ }
19
+ });
18
20
  }
19
21
 
20
22
  export { enableReactUse };
21
- //# sourceMappingURL=enableReactUse.mjs.map
@@ -1,8 +1,10 @@
1
- export declare function enable$GetSet(): void;
2
- export declare const enableDirectAccess: typeof enable$GetSet;
1
+ declare function enable$GetSet(): void;
2
+ declare const enableDirectAccess: typeof enable$GetSet;
3
3
  declare module '@legendapp/state' {
4
4
  interface ImmutableObservableBase<T> {
5
5
  get $(): T;
6
6
  set $(value: T | null | undefined);
7
7
  }
8
8
  }
9
+
10
+ export { enable$GetSet, enableDirectAccess };
@@ -0,0 +1,10 @@
1
+ declare function enable$GetSet(): void;
2
+ declare const enableDirectAccess: typeof enable$GetSet;
3
+ declare module '@legendapp/state' {
4
+ interface ImmutableObservableBase<T> {
5
+ get $(): T;
6
+ set $(value: T | null | undefined);
7
+ }
8
+ }
9
+
10
+ export { enable$GetSet, enableDirectAccess };
@@ -0,0 +1,10 @@
1
+ declare function enable_PeekAssign(): void;
2
+ declare const enableDirectAccess: typeof enable_PeekAssign;
3
+ declare module '@legendapp/state' {
4
+ interface ImmutableObservableBase<T> {
5
+ get _(): T;
6
+ set _(value: T | null | undefined);
7
+ }
8
+ }
9
+
10
+ export { enableDirectAccess, enable_PeekAssign };
@@ -1,8 +1,10 @@
1
- export declare function enable_PeekAssign(): void;
2
- export declare const enableDirectAccess: typeof enable_PeekAssign;
1
+ declare function enable_PeekAssign(): void;
2
+ declare const enableDirectAccess: typeof enable_PeekAssign;
3
3
  declare module '@legendapp/state' {
4
4
  interface ImmutableObservableBase<T> {
5
5
  get _(): T;
6
6
  set _(value: T | null | undefined);
7
7
  }
8
8
  }
9
+
10
+ export { enableDirectAccess, enable_PeekAssign };
@@ -2,23 +2,22 @@
2
2
 
3
3
  var state = require('@legendapp/state');
4
4
 
5
+ // src/config/enable_PeekAssign.ts
5
6
  function enable_PeekAssign() {
6
- state.configureLegendState({
7
- observableProperties: {
8
- _: {
9
- get(node) {
10
- return state.internal.peek(node);
11
- },
12
- set(node, value) {
13
- state.internal.setNodeValue(node, value);
14
- },
15
- },
7
+ state.configureLegendState({
8
+ observableProperties: {
9
+ _: {
10
+ get(node) {
11
+ return state.internal.peek(node);
16
12
  },
17
- });
13
+ set(node, value) {
14
+ state.internal.setNodeValue(node, value);
15
+ }
16
+ }
17
+ }
18
+ });
18
19
  }
19
- // TODOv4 deprecate
20
- const enableDirectAccess = enable_PeekAssign;
20
+ var enableDirectAccess = enable_PeekAssign;
21
21
 
22
22
  exports.enableDirectAccess = enableDirectAccess;
23
23
  exports.enable_PeekAssign = enable_PeekAssign;
24
- //# sourceMappingURL=enable_PeekAssign.js.map
@@ -1,21 +1,20 @@
1
1
  import { configureLegendState, internal } from '@legendapp/state';
2
2
 
3
+ // src/config/enable_PeekAssign.ts
3
4
  function enable_PeekAssign() {
4
- configureLegendState({
5
- observableProperties: {
6
- _: {
7
- get(node) {
8
- return internal.peek(node);
9
- },
10
- set(node, value) {
11
- internal.setNodeValue(node, value);
12
- },
13
- },
5
+ configureLegendState({
6
+ observableProperties: {
7
+ _: {
8
+ get(node) {
9
+ return internal.peek(node);
14
10
  },
15
- });
11
+ set(node, value) {
12
+ internal.setNodeValue(node, value);
13
+ }
14
+ }
15
+ }
16
+ });
16
17
  }
17
- // TODOv4 deprecate
18
- const enableDirectAccess = enable_PeekAssign;
18
+ var enableDirectAccess = enable_PeekAssign;
19
19
 
20
20
  export { enableDirectAccess, enable_PeekAssign };
21
- //# sourceMappingURL=enable_PeekAssign.mjs.map
@@ -0,0 +1,9 @@
1
+ import { Observable } from '@legendapp/state';
2
+
3
+ interface Options {
4
+ setter: 'pushState' | 'replaceState' | 'hash';
5
+ }
6
+ declare function configurePageHash(options: Options): void;
7
+ declare const pageHash: Observable<string>;
8
+
9
+ export { configurePageHash, pageHash };
@@ -1,7 +1,9 @@
1
1
  import { Observable } from '@legendapp/state';
2
+
2
3
  interface Options {
3
4
  setter: 'pushState' | 'replaceState' | 'hash';
4
5
  }
5
6
  declare function configurePageHash(options: Options): void;
6
7
  declare const pageHash: Observable<string>;
8
+
7
9
  export { configurePageHash, pageHash };
@@ -2,40 +2,35 @@
2
2
 
3
3
  var state = require('@legendapp/state');
4
4
 
5
- let _options = { setter: 'hash' };
5
+ // src/helpers/pageHash.ts
6
+ var _options = { setter: "hash" };
6
7
  function configurePageHash(options) {
7
- _options = options;
8
+ _options = options;
8
9
  }
9
- const hasWindow = typeof window !== 'undefined';
10
- const pageHash = state.observable(hasWindow ? window.location.hash.slice(1) : '');
10
+ var hasWindow = typeof window !== "undefined";
11
+ var pageHash = state.observable(hasWindow ? window.location.hash.slice(1) : "");
11
12
  if (hasWindow) {
12
- let isSetting = false;
13
- // Set the page hash when the observable changes
14
- pageHash.onChange(({ value }) => {
15
- if (!isSetting) {
16
- const hash = '#' + value;
17
- const setter = (_options === null || _options === void 0 ? void 0 : _options.setter) || 'hash';
18
- if (setter === 'pushState') {
19
- history.pushState(null, null, hash);
20
- }
21
- else if (setter === 'replaceState') {
22
- history.replaceState(null, null, hash);
23
- }
24
- else {
25
- location.hash = hash;
26
- }
27
- }
28
- });
29
- // Update the observable whenever the hash changes
30
- const cb = () => {
31
- isSetting = true;
32
- pageHash.set(window.location.hash.slice(1));
33
- isSetting = false;
34
- };
35
- // Subscribe to window hashChange event
36
- window.addEventListener('hashchange', cb);
13
+ let isSetting = false;
14
+ pageHash.onChange(({ value }) => {
15
+ if (!isSetting) {
16
+ const hash = "#" + value;
17
+ const setter = (_options == null ? void 0 : _options.setter) || "hash";
18
+ if (setter === "pushState") {
19
+ history.pushState(null, null, hash);
20
+ } else if (setter === "replaceState") {
21
+ history.replaceState(null, null, hash);
22
+ } else {
23
+ location.hash = hash;
24
+ }
25
+ }
26
+ });
27
+ const cb = () => {
28
+ isSetting = true;
29
+ pageHash.set(window.location.hash.slice(1));
30
+ isSetting = false;
31
+ };
32
+ window.addEventListener("hashchange", cb);
37
33
  }
38
34
 
39
35
  exports.configurePageHash = configurePageHash;
40
36
  exports.pageHash = pageHash;
41
- //# sourceMappingURL=pageHash.js.map