ccstate-react 4.13.0 → 5.2.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/coverage/base.css +224 -0
  3. package/coverage/block-navigation.js +87 -0
  4. package/coverage/clover.xml +219 -0
  5. package/coverage/coverage-final.json +8 -0
  6. package/coverage/favicon.png +0 -0
  7. package/coverage/index.html +206 -0
  8. package/coverage/index.ts.html +100 -0
  9. package/coverage/prettify.css +1 -0
  10. package/coverage/prettify.js +2 -0
  11. package/coverage/provider.ts.html +133 -0
  12. package/coverage/sort-arrow-sprite.png +0 -0
  13. package/coverage/sorter.js +196 -0
  14. package/coverage/useGet.ts.html +160 -0
  15. package/coverage/useLoadable.ts.html +403 -0
  16. package/coverage/useLoadableSet.ts.html +295 -0
  17. package/coverage/useResolved.ts.html +133 -0
  18. package/coverage/useSet.ts.html +166 -0
  19. package/dist/experimental.cjs +92 -45
  20. package/dist/experimental.d.cts +15 -6
  21. package/dist/experimental.d.ts +15 -6
  22. package/dist/experimental.js +93 -43
  23. package/dist/index.cjs +56 -125
  24. package/dist/index.d.cts +3 -3
  25. package/dist/index.d.ts +3 -3
  26. package/dist/index.js +57 -126
  27. package/package.json +9 -9
  28. package/src/__tests__/get-and-set.test.tsx +22 -13
  29. package/src/__tests__/loadable-set.test.tsx +255 -0
  30. package/src/__tests__/loadable.test.tsx +14 -6
  31. package/src/__tests__/resolved.test.tsx +6 -1
  32. package/src/experimental.ts +1 -1
  33. package/src/provider.ts +1 -2
  34. package/src/useGet.ts +19 -6
  35. package/src/useLoadable.ts +74 -95
  36. package/src/useLoadableSet.ts +72 -0
  37. package/src/useResolved.ts +2 -2
  38. package/LICENSE +0 -21
  39. package/src/__tests__/inline-atom.test.tsx +0 -139
  40. package/src/useInlineAtom.ts +0 -40
@@ -1,62 +1,109 @@
1
1
  'use strict';
2
2
 
3
- var ccstate = require('ccstate');
4
3
  var react = require('react');
5
4
 
5
+ function _arrayLikeToArray(r, a) {
6
+ (null == a || a > r.length) && (a = r.length);
7
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
8
+ return n;
9
+ }
10
+ function _arrayWithoutHoles(r) {
11
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
12
+ }
13
+ function _iterableToArray(r) {
14
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
15
+ }
16
+ function _nonIterableSpread() {
17
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
18
+ }
19
+ function _toConsumableArray(r) {
20
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
21
+ }
22
+ function _unsupportedIterableToArray(r, a) {
23
+ if (r) {
24
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
25
+ var t = {}.toString.call(r).slice(8, -1);
26
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
27
+ }
28
+ }
29
+
6
30
  var StoreContext = react.createContext(null);
7
31
  StoreContext.Provider;
8
32
  function useStore() {
9
33
  var store = react.useContext(StoreContext);
10
34
  if (!store) {
11
- return ccstate.getDefaultStore();
35
+ throw new Error('useStore must be used within a StoreProvider');
12
36
  }
13
37
  return store;
14
38
  }
15
39
 
16
- function useRefFactory(factory) {
17
- var ref = react.useRef(null);
18
- if (!ref.current) {
19
- var value = factory();
20
- ref.current = value;
21
- return value;
22
- }
23
- return ref.current;
24
- }
25
- function useCCState() {
26
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
- args[_key] = arguments[_key];
28
- }
29
- return useRefFactory(function () {
30
- return ccstate.state.apply(void 0, args);
31
- });
32
- }
33
- function useComputed() {
34
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
35
- args[_key2] = arguments[_key2];
36
- }
37
- return useRefFactory(function () {
38
- return ccstate.computed.apply(void 0, args);
39
- });
40
- }
41
- function useCommand() {
42
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
43
- args[_key3] = arguments[_key3];
44
- }
45
- return useRefFactory(function () {
46
- return ccstate.command.apply(void 0, args);
47
- });
48
- }
49
- function useSub() {
50
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
51
- args[_key4] = arguments[_key4];
52
- }
40
+ function useLoadableSet(signal) {
53
41
  var store = useStore();
54
- react.useEffect(function () {
55
- return store.sub.apply(store, args);
42
+ var resultRef = react.useRef({
43
+ state: 'idle'
44
+ });
45
+ var notifyRef = react.useRef(null);
46
+ var controllerRef = react.useRef(null);
47
+ var subscribe = react.useCallback(function (notify) {
48
+ notifyRef.current = notify;
49
+ return function () {
50
+ var _controllerRef$curren;
51
+ notifyRef.current = null;
52
+ (_controllerRef$curren = controllerRef.current) === null || _controllerRef$curren === void 0 || _controllerRef$curren.abort();
53
+ };
56
54
  }, []);
55
+ var invoke = react.useCallback(function () {
56
+ var _controllerRef$curren2;
57
+ (_controllerRef$curren2 = controllerRef.current) === null || _controllerRef$curren2 === void 0 || _controllerRef$curren2.abort();
58
+ var controller = new AbortController();
59
+ controllerRef.current = controller;
60
+ var abortSignal = controller.signal;
61
+ function updateResult(result) {
62
+ var _notifyRef$current;
63
+ if (abortSignal.aborted) return;
64
+ resultRef.current = result;
65
+ (_notifyRef$current = notifyRef.current) === null || _notifyRef$current === void 0 || _notifyRef$current.call(notifyRef);
66
+ }
67
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
68
+ args[_key] = arguments[_key];
69
+ }
70
+ if ('write' in signal) {
71
+ var result = store.set.apply(store, [signal].concat(_toConsumableArray(args)));
72
+ if (result instanceof Promise) {
73
+ updateResult({
74
+ state: 'loading'
75
+ });
76
+ void result.then(function (data) {
77
+ updateResult({
78
+ state: 'hasData',
79
+ data: data
80
+ });
81
+ }, function (error) {
82
+ updateResult({
83
+ state: 'hasError',
84
+ error: error
85
+ });
86
+ });
87
+ } else {
88
+ updateResult({
89
+ state: 'hasData',
90
+ data: result
91
+ });
92
+ }
93
+ return result;
94
+ } else {
95
+ store.set.apply(store, [signal].concat(_toConsumableArray(args)));
96
+ updateResult({
97
+ state: 'hasData',
98
+ data: undefined
99
+ });
100
+ return undefined;
101
+ }
102
+ }, [store, signal]);
103
+ var loadable = react.useSyncExternalStore(subscribe, function () {
104
+ return resultRef.current;
105
+ });
106
+ return [loadable, invoke];
57
107
  }
58
108
 
59
- exports.useCCState = useCCState;
60
- exports.useCommand = useCommand;
61
- exports.useComputed = useComputed;
62
- exports.useSub = useSub;
109
+ exports.useLoadableSet = useLoadableSet;
@@ -1,8 +1,17 @@
1
- import { state, State, computed, Computed, command, Command, Subscribe } from 'ccstate';
1
+ import { State, StateArg, Command } from 'ccstate';
2
2
 
3
- declare function useCCState<T>(...args: Parameters<typeof state<T>>): State<T>;
4
- declare function useComputed<T>(...args: Parameters<typeof computed<T>>): Computed<T>;
5
- declare function useCommand<T, Args extends unknown[]>(...args: Parameters<typeof command<T, Args>>): Command<T, Args>;
6
- declare function useSub(...args: Parameters<Subscribe>): void;
3
+ type LoadableSetResult<T> = {
4
+ state: 'idle';
5
+ } | {
6
+ state: 'loading';
7
+ } | {
8
+ state: 'hasData';
9
+ data: Awaited<T>;
10
+ } | {
11
+ state: 'hasError';
12
+ error: unknown;
13
+ };
14
+ declare function useLoadableSet<T>(signal: State<T>): [LoadableSetResult<void>, (val: StateArg<T>) => void];
15
+ declare function useLoadableSet<T, CommandArgs extends unknown[]>(signal: Command<T, CommandArgs>): [LoadableSetResult<Awaited<T>>, (...args: CommandArgs) => T];
7
16
 
8
- export { useCCState, useCommand, useComputed, useSub };
17
+ export { useLoadableSet };
@@ -1,8 +1,17 @@
1
- import { state, State, computed, Computed, command, Command, Subscribe } from 'ccstate';
1
+ import { State, StateArg, Command } from 'ccstate';
2
2
 
3
- declare function useCCState<T>(...args: Parameters<typeof state<T>>): State<T>;
4
- declare function useComputed<T>(...args: Parameters<typeof computed<T>>): Computed<T>;
5
- declare function useCommand<T, Args extends unknown[]>(...args: Parameters<typeof command<T, Args>>): Command<T, Args>;
6
- declare function useSub(...args: Parameters<Subscribe>): void;
3
+ type LoadableSetResult<T> = {
4
+ state: 'idle';
5
+ } | {
6
+ state: 'loading';
7
+ } | {
8
+ state: 'hasData';
9
+ data: Awaited<T>;
10
+ } | {
11
+ state: 'hasError';
12
+ error: unknown;
13
+ };
14
+ declare function useLoadableSet<T>(signal: State<T>): [LoadableSetResult<void>, (val: StateArg<T>) => void];
15
+ declare function useLoadableSet<T, CommandArgs extends unknown[]>(signal: Command<T, CommandArgs>): [LoadableSetResult<Awaited<T>>, (...args: CommandArgs) => T];
7
16
 
8
- export { useCCState, useCommand, useComputed, useSub };
17
+ export { useLoadableSet };
@@ -1,57 +1,107 @@
1
- import { getDefaultStore, state, computed, command } from 'ccstate';
2
- import { createContext, useContext, useEffect, useRef } from 'react';
1
+ import { createContext, useContext, useRef, useCallback, useSyncExternalStore } from 'react';
2
+
3
+ function _arrayLikeToArray(r, a) {
4
+ (null == a || a > r.length) && (a = r.length);
5
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
+ return n;
7
+ }
8
+ function _arrayWithoutHoles(r) {
9
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
10
+ }
11
+ function _iterableToArray(r) {
12
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
13
+ }
14
+ function _nonIterableSpread() {
15
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
16
+ }
17
+ function _toConsumableArray(r) {
18
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
19
+ }
20
+ function _unsupportedIterableToArray(r, a) {
21
+ if (r) {
22
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
23
+ var t = {}.toString.call(r).slice(8, -1);
24
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
25
+ }
26
+ }
3
27
 
4
28
  var StoreContext = createContext(null);
5
29
  StoreContext.Provider;
6
30
  function useStore() {
7
31
  var store = useContext(StoreContext);
8
32
  if (!store) {
9
- return getDefaultStore();
33
+ throw new Error('useStore must be used within a StoreProvider');
10
34
  }
11
35
  return store;
12
36
  }
13
37
 
14
- function useRefFactory(factory) {
15
- var ref = useRef(null);
16
- if (!ref.current) {
17
- var value = factory();
18
- ref.current = value;
19
- return value;
20
- }
21
- return ref.current;
22
- }
23
- function useCCState() {
24
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
25
- args[_key] = arguments[_key];
26
- }
27
- return useRefFactory(function () {
28
- return state.apply(void 0, args);
29
- });
30
- }
31
- function useComputed() {
32
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
33
- args[_key2] = arguments[_key2];
34
- }
35
- return useRefFactory(function () {
36
- return computed.apply(void 0, args);
37
- });
38
- }
39
- function useCommand() {
40
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
41
- args[_key3] = arguments[_key3];
42
- }
43
- return useRefFactory(function () {
44
- return command.apply(void 0, args);
45
- });
46
- }
47
- function useSub() {
48
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
49
- args[_key4] = arguments[_key4];
50
- }
38
+ function useLoadableSet(signal) {
51
39
  var store = useStore();
52
- useEffect(function () {
53
- return store.sub.apply(store, args);
40
+ var resultRef = useRef({
41
+ state: 'idle'
42
+ });
43
+ var notifyRef = useRef(null);
44
+ var controllerRef = useRef(null);
45
+ var subscribe = useCallback(function (notify) {
46
+ notifyRef.current = notify;
47
+ return function () {
48
+ var _controllerRef$curren;
49
+ notifyRef.current = null;
50
+ (_controllerRef$curren = controllerRef.current) === null || _controllerRef$curren === void 0 || _controllerRef$curren.abort();
51
+ };
54
52
  }, []);
53
+ var invoke = useCallback(function () {
54
+ var _controllerRef$curren2;
55
+ (_controllerRef$curren2 = controllerRef.current) === null || _controllerRef$curren2 === void 0 || _controllerRef$curren2.abort();
56
+ var controller = new AbortController();
57
+ controllerRef.current = controller;
58
+ var abortSignal = controller.signal;
59
+ function updateResult(result) {
60
+ var _notifyRef$current;
61
+ if (abortSignal.aborted) return;
62
+ resultRef.current = result;
63
+ (_notifyRef$current = notifyRef.current) === null || _notifyRef$current === void 0 || _notifyRef$current.call(notifyRef);
64
+ }
65
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
66
+ args[_key] = arguments[_key];
67
+ }
68
+ if ('write' in signal) {
69
+ var result = store.set.apply(store, [signal].concat(_toConsumableArray(args)));
70
+ if (result instanceof Promise) {
71
+ updateResult({
72
+ state: 'loading'
73
+ });
74
+ void result.then(function (data) {
75
+ updateResult({
76
+ state: 'hasData',
77
+ data: data
78
+ });
79
+ }, function (error) {
80
+ updateResult({
81
+ state: 'hasError',
82
+ error: error
83
+ });
84
+ });
85
+ } else {
86
+ updateResult({
87
+ state: 'hasData',
88
+ data: result
89
+ });
90
+ }
91
+ return result;
92
+ } else {
93
+ store.set.apply(store, [signal].concat(_toConsumableArray(args)));
94
+ updateResult({
95
+ state: 'hasData',
96
+ data: undefined
97
+ });
98
+ return undefined;
99
+ }
100
+ }, [store, signal]);
101
+ var loadable = useSyncExternalStore(subscribe, function () {
102
+ return resultRef.current;
103
+ });
104
+ return [loadable, invoke];
55
105
  }
56
106
 
57
- export { useCCState, useCommand, useComputed, useSub };
107
+ export { useLoadableSet };
package/dist/index.cjs CHANGED
@@ -1,23 +1,32 @@
1
1
  'use strict';
2
2
 
3
3
  var react = require('react');
4
- var ccstate = require('ccstate');
5
4
 
6
5
  var StoreContext = react.createContext(null);
7
6
  var StoreProvider = StoreContext.Provider;
8
7
  function useStore() {
9
8
  var store = react.useContext(StoreContext);
10
9
  if (!store) {
11
- return ccstate.getDefaultStore();
10
+ throw new Error('useStore must be used within a StoreProvider');
12
11
  }
13
12
  return store;
14
13
  }
15
14
 
16
15
  function useGet(atom) {
17
16
  var store = useStore();
18
- return react.useSyncExternalStore(function (fn) {
19
- return store.sub(atom, ccstate.command(fn));
20
- }, function () {
17
+ var onChange = react.useRef(function (fn) {
18
+ var controller = new AbortController();
19
+ store.watch(function (get) {
20
+ get(atom);
21
+ fn();
22
+ }, {
23
+ signal: controller.signal
24
+ });
25
+ return function () {
26
+ controller.abort();
27
+ };
28
+ });
29
+ return react.useSyncExternalStore(onChange.current, function () {
21
30
  return store.get(atom);
22
31
  });
23
32
  }
@@ -34,132 +43,54 @@ function useSet(signal) {
34
43
  }, [store, signal]);
35
44
  }
36
45
 
37
- function _arrayLikeToArray(r, a) {
38
- (null == a || a > r.length) && (a = r.length);
39
- for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
40
- return n;
41
- }
42
- function _arrayWithHoles(r) {
43
- if (Array.isArray(r)) return r;
44
- }
45
- function _iterableToArrayLimit(r, l) {
46
- var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
47
- if (null != t) {
48
- var e,
49
- n,
50
- i,
51
- u,
52
- a = [],
53
- f = !0,
54
- o = !1;
55
- try {
56
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
57
- } catch (r) {
58
- o = !0, n = r;
59
- } finally {
60
- try {
61
- if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
62
- } finally {
63
- if (o) throw n;
64
- }
65
- }
66
- return a;
67
- }
68
- }
69
- function _nonIterableRest() {
70
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
71
- }
72
- function _slicedToArray(r, e) {
73
- return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
74
- }
75
- function _unsupportedIterableToArray(r, a) {
76
- if (r) {
77
- if ("string" == typeof r) return _arrayLikeToArray(r, a);
78
- var t = {}.toString.call(r).slice(8, -1);
79
- return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
80
- }
81
- }
82
-
83
- /**
84
- * Handles a specific behavior of useSyncExternalStore. In React, there are situations where the getSnapshot function of
85
- * useSyncExternalStore executes, but the Render function doesn't execute.
86
- *
87
- * This can cause the promise generated in that round to not be caught, and userspace has no opportunity to handle this
88
- * promise. Therefore, this issue needs to be handled in useGetPromise.
89
- *
90
- * @param atom
91
- * @returns
92
- */
93
- function useGetPromise(atom) {
94
- var store = useStore();
95
- var lastPromise = react.useRef(undefined);
96
- var promiseProcessed = react.useRef(false);
97
- var promise = react.useSyncExternalStore(function (fn) {
98
- return store.sub(atom, ccstate.command(fn));
99
- }, function () {
100
- var val = store.get(atom);
101
-
102
- // If the last promise is not processed and the current value is a promise,
103
- // we need to silence the last promise to avoid unhandled rejections.
104
- if (lastPromise.current !== undefined && lastPromise.current !== val && !promiseProcessed.current) {
105
- lastPromise.current["catch"](function () {
106
- return void 0;
107
- });
108
- }
109
- if (lastPromise.current !== val) {
110
- promiseProcessed.current = false;
111
- lastPromise.current = val instanceof Promise ? val : undefined;
112
- }
113
- return val;
46
+ function useLoadableInternal(promise$, keepLastResolved) {
47
+ var promiseResult = react.useRef({
48
+ state: 'loading'
114
49
  });
115
- return [promise, function () {
116
- promiseProcessed.current = true;
117
- }];
118
- }
119
- function useLoadableInternal(atom, keepLastResolved) {
120
- var _useGetPromise = useGetPromise(atom),
121
- _useGetPromise2 = _slicedToArray(_useGetPromise, 2),
122
- promise = _useGetPromise2[0],
123
- setPromiseProcessed = _useGetPromise2[1];
124
- var _useState = react.useState({
125
- state: 'loading'
126
- }),
127
- _useState2 = _slicedToArray(_useState, 2),
128
- promiseResult = _useState2[0],
129
- setPromiseResult = _useState2[1];
130
- react.useEffect(function () {
131
- if (!(promise instanceof Promise)) {
132
- setPromiseResult({
133
- state: 'hasData',
134
- data: promise
135
- });
136
- return;
137
- }
138
- var cancelled = false;
139
- if (!keepLastResolved) {
140
- setPromiseResult({
141
- state: 'loading'
142
- });
50
+ var store = useStore();
51
+ var subStore = react.useCallback(function (fn) {
52
+ function updateResult(result, signal) {
53
+ if (signal.aborted) return;
54
+ promiseResult.current = result;
55
+ fn();
143
56
  }
144
- setPromiseProcessed();
145
- promise.then(function (ret) {
146
- if (cancelled) return;
147
- setPromiseResult({
148
- state: 'hasData',
149
- data: ret
150
- });
151
- }, function (error) {
152
- if (cancelled) return;
153
- setPromiseResult({
154
- state: 'hasError',
155
- error: error
57
+ var controller = new AbortController();
58
+ store.watch(function (get, _ref) {
59
+ var signal = _ref.signal;
60
+ var promise = get(promise$);
61
+ if (!(promise instanceof Promise)) {
62
+ updateResult({
63
+ state: 'hasData',
64
+ data: promise
65
+ }, signal);
66
+ return;
67
+ }
68
+ if (!keepLastResolved) {
69
+ updateResult({
70
+ state: 'loading'
71
+ }, signal);
72
+ }
73
+ promise.then(function (ret) {
74
+ updateResult({
75
+ state: 'hasData',
76
+ data: ret
77
+ }, signal);
78
+ }, function (error) {
79
+ updateResult({
80
+ state: 'hasError',
81
+ error: error
82
+ }, signal);
156
83
  });
84
+ }, {
85
+ signal: controller.signal
157
86
  });
158
87
  return function () {
159
- cancelled = true;
88
+ controller.abort();
160
89
  };
161
- }, [promise]);
162
- return promiseResult;
90
+ }, [store, promise$]);
91
+ return react.useSyncExternalStore(subStore, function () {
92
+ return promiseResult.current;
93
+ });
163
94
  }
164
95
  function useLoadable(atom) {
165
96
  return useLoadableInternal(atom, false);
package/dist/index.d.cts CHANGED
@@ -15,13 +15,13 @@ type Loadable<T> = {
15
15
  state: 'loading';
16
16
  } | {
17
17
  state: 'hasData';
18
- data: T;
18
+ data: Awaited<T>;
19
19
  } | {
20
20
  state: 'hasError';
21
21
  error: unknown;
22
22
  };
23
- declare function useLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<Awaited<T>>;
24
- declare function useLastLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<Awaited<T>>;
23
+ declare function useLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<T>;
24
+ declare function useLastLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<T>;
25
25
 
26
26
  declare const StoreProvider: react.Provider<Store | null>;
27
27
 
package/dist/index.d.ts CHANGED
@@ -15,13 +15,13 @@ type Loadable<T> = {
15
15
  state: 'loading';
16
16
  } | {
17
17
  state: 'hasData';
18
- data: T;
18
+ data: Awaited<T>;
19
19
  } | {
20
20
  state: 'hasError';
21
21
  error: unknown;
22
22
  };
23
- declare function useLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<Awaited<T>>;
24
- declare function useLastLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<Awaited<T>>;
23
+ declare function useLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<T>;
24
+ declare function useLastLoadable<T>(atom: State<Promise<Awaited<T>> | Awaited<T>> | Computed<Promise<Awaited<T>> | Awaited<T>>): Loadable<T>;
25
25
 
26
26
  declare const StoreProvider: react.Provider<Store | null>;
27
27