@depup/jotai 2.18.0-depup.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 (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/babel/plugin-debug-label.d.ts +5 -0
  4. package/babel/plugin-debug-label.js +54 -0
  5. package/babel/plugin-react-refresh.d.ts +5 -0
  6. package/babel/plugin-react-refresh.js +72 -0
  7. package/babel/preset.d.ts +6 -0
  8. package/babel/preset.js +110 -0
  9. package/babel/utils.d.ts +5 -0
  10. package/benchmarks/simple-read.d.ts +2 -0
  11. package/benchmarks/simple-write.d.ts +2 -0
  12. package/benchmarks/subscribe-write.d.ts +2 -0
  13. package/changes.json +5 -0
  14. package/esm/babel/plugin-debug-label.d.mts +5 -0
  15. package/esm/babel/plugin-debug-label.mjs +103 -0
  16. package/esm/babel/plugin-react-refresh.d.mts +5 -0
  17. package/esm/babel/plugin-react-refresh.mjs +121 -0
  18. package/esm/babel/preset.d.mts +6 -0
  19. package/esm/babel/preset.mjs +179 -0
  20. package/esm/babel/utils.d.mts +5 -0
  21. package/esm/index.d.mts +2 -0
  22. package/esm/index.mjs +2 -0
  23. package/esm/react/Provider.d.mts +16 -0
  24. package/esm/react/useAtom.d.mts +13 -0
  25. package/esm/react/useAtomValue.d.mts +9 -0
  26. package/esm/react/useSetAtom.d.mts +7 -0
  27. package/esm/react/utils/useAtomCallback.d.mts +5 -0
  28. package/esm/react/utils/useHydrateAtoms.d.mts +14 -0
  29. package/esm/react/utils/useReducerAtom.d.mts +14 -0
  30. package/esm/react/utils/useResetAtom.d.mts +6 -0
  31. package/esm/react/utils.d.mts +4 -0
  32. package/esm/react/utils.mjs +57 -0
  33. package/esm/react.d.mts +4 -0
  34. package/esm/react.mjs +182 -0
  35. package/esm/utils.d.mts +2 -0
  36. package/esm/utils.mjs +2 -0
  37. package/esm/vanilla/atom.d.mts +47 -0
  38. package/esm/vanilla/internals.d.mts +164 -0
  39. package/esm/vanilla/internals.mjs +715 -0
  40. package/esm/vanilla/store.d.mts +5 -0
  41. package/esm/vanilla/typeUtils.d.mts +7 -0
  42. package/esm/vanilla/utils/atomFamily.d.mts +55 -0
  43. package/esm/vanilla/utils/atomWithDefault.d.mts +6 -0
  44. package/esm/vanilla/utils/atomWithLazy.d.mts +2 -0
  45. package/esm/vanilla/utils/atomWithObservable.d.mts +32 -0
  46. package/esm/vanilla/utils/atomWithReducer.d.mts +3 -0
  47. package/esm/vanilla/utils/atomWithRefresh.d.mts +6 -0
  48. package/esm/vanilla/utils/atomWithReset.d.mts +8 -0
  49. package/esm/vanilla/utils/atomWithStorage.d.mts +50 -0
  50. package/esm/vanilla/utils/constants.d.mts +1 -0
  51. package/esm/vanilla/utils/freezeAtom.d.mts +6 -0
  52. package/esm/vanilla/utils/loadable.d.mts +33 -0
  53. package/esm/vanilla/utils/selectAtom.d.mts +2 -0
  54. package/esm/vanilla/utils/splitAtom.d.mts +16 -0
  55. package/esm/vanilla/utils/unwrap.d.mts +5 -0
  56. package/esm/vanilla/utils.d.mts +14 -0
  57. package/esm/vanilla/utils.mjs +736 -0
  58. package/esm/vanilla.d.mts +4 -0
  59. package/esm/vanilla.mjs +59 -0
  60. package/index.d.ts +2 -0
  61. package/index.js +19 -0
  62. package/package.json +125 -0
  63. package/react/Provider.d.ts +16 -0
  64. package/react/useAtom.d.ts +13 -0
  65. package/react/useAtomValue.d.ts +9 -0
  66. package/react/useSetAtom.d.ts +7 -0
  67. package/react/utils/useAtomCallback.d.ts +5 -0
  68. package/react/utils/useHydrateAtoms.d.ts +14 -0
  69. package/react/utils/useReducerAtom.d.ts +14 -0
  70. package/react/utils/useResetAtom.d.ts +6 -0
  71. package/react/utils.d.ts +4 -0
  72. package/react/utils.js +100 -0
  73. package/react.d.ts +4 -0
  74. package/react.js +182 -0
  75. package/system/babel/plugin-debug-label.development.js +113 -0
  76. package/system/babel/plugin-debug-label.production.js +4 -0
  77. package/system/babel/plugin-react-refresh.development.js +131 -0
  78. package/system/babel/plugin-react-refresh.production.js +11 -0
  79. package/system/babel/preset.development.js +189 -0
  80. package/system/babel/preset.production.js +14 -0
  81. package/system/index.development.js +27 -0
  82. package/system/index.production.js +1 -0
  83. package/system/react/utils.development.js +79 -0
  84. package/system/react/utils.production.js +2 -0
  85. package/system/react.development.js +210 -0
  86. package/system/react.production.js +2 -0
  87. package/system/utils.development.js +27 -0
  88. package/system/utils.production.js +1 -0
  89. package/system/vanilla/internals.development.js +735 -0
  90. package/system/vanilla/internals.production.js +1 -0
  91. package/system/vanilla/utils.development.js +764 -0
  92. package/system/vanilla/utils.production.js +1 -0
  93. package/system/vanilla.development.js +75 -0
  94. package/system/vanilla.production.js +1 -0
  95. package/ts3.8/babel/plugin-debug-label.d.ts +6 -0
  96. package/ts3.8/babel/plugin-react-refresh.d.ts +6 -0
  97. package/ts3.8/babel/preset.d.ts +7 -0
  98. package/ts3.8/babel/utils.d.ts +6 -0
  99. package/ts3.8/benchmarks/simple-read.d.ts +3 -0
  100. package/ts3.8/benchmarks/simple-write.d.ts +3 -0
  101. package/ts3.8/benchmarks/subscribe-write.d.ts +3 -0
  102. package/ts3.8/esm/babel/plugin-debug-label.d.ts +6 -0
  103. package/ts3.8/esm/babel/plugin-react-refresh.d.ts +6 -0
  104. package/ts3.8/esm/babel/preset.d.ts +7 -0
  105. package/ts3.8/esm/babel/utils.d.ts +6 -0
  106. package/ts3.8/esm/index.d.ts +3 -0
  107. package/ts3.8/esm/react/Provider.d.ts +17 -0
  108. package/ts3.8/esm/react/useAtom.d.ts +28 -0
  109. package/ts3.8/esm/react/useAtomValue.d.ts +10 -0
  110. package/ts3.8/esm/react/useSetAtom.d.ts +8 -0
  111. package/ts3.8/esm/react/utils/useAtomCallback.d.ts +6 -0
  112. package/ts3.8/esm/react/utils/useHydrateAtoms.d.ts +27 -0
  113. package/ts3.8/esm/react/utils/useReducerAtom.d.ts +21 -0
  114. package/ts3.8/esm/react/utils/useResetAtom.d.ts +9 -0
  115. package/ts3.8/esm/react/utils.d.ts +5 -0
  116. package/ts3.8/esm/react.d.ts +5 -0
  117. package/ts3.8/esm/utils.d.ts +3 -0
  118. package/ts3.8/esm/vanilla/atom.d.ts +48 -0
  119. package/ts3.8/esm/vanilla/internals.d.ts +165 -0
  120. package/ts3.8/esm/vanilla/store.d.ts +6 -0
  121. package/ts3.8/esm/vanilla/typeUtils.d.ts +8 -0
  122. package/ts3.8/esm/vanilla/utils/atomFamily.d.ts +56 -0
  123. package/ts3.8/esm/vanilla/utils/atomWithDefault.d.ts +11 -0
  124. package/ts3.8/esm/vanilla/utils/atomWithLazy.d.ts +3 -0
  125. package/ts3.8/esm/vanilla/utils/atomWithObservable.d.ts +37 -0
  126. package/ts3.8/esm/vanilla/utils/atomWithReducer.d.ts +8 -0
  127. package/ts3.8/esm/vanilla/utils/atomWithRefresh.d.ts +10 -0
  128. package/ts3.8/esm/vanilla/utils/atomWithReset.d.ts +11 -0
  129. package/ts3.8/esm/vanilla/utils/atomWithStorage.d.ts +53 -0
  130. package/ts3.8/esm/vanilla/utils/constants.d.ts +2 -0
  131. package/ts3.8/esm/vanilla/utils/freezeAtom.d.ts +7 -0
  132. package/ts3.8/esm/vanilla/utils/loadable.d.ts +34 -0
  133. package/ts3.8/esm/vanilla/utils/selectAtom.d.ts +3 -0
  134. package/ts3.8/esm/vanilla/utils/splitAtom.d.ts +21 -0
  135. package/ts3.8/esm/vanilla/utils/unwrap.d.ts +6 -0
  136. package/ts3.8/esm/vanilla/utils.d.ts +15 -0
  137. package/ts3.8/esm/vanilla.d.ts +5 -0
  138. package/ts3.8/index.d.ts +3 -0
  139. package/ts3.8/react/Provider.d.ts +17 -0
  140. package/ts3.8/react/useAtom.d.ts +28 -0
  141. package/ts3.8/react/useAtomValue.d.ts +10 -0
  142. package/ts3.8/react/useSetAtom.d.ts +8 -0
  143. package/ts3.8/react/utils/useAtomCallback.d.ts +6 -0
  144. package/ts3.8/react/utils/useHydrateAtoms.d.ts +27 -0
  145. package/ts3.8/react/utils/useReducerAtom.d.ts +21 -0
  146. package/ts3.8/react/utils/useResetAtom.d.ts +9 -0
  147. package/ts3.8/react/utils.d.ts +5 -0
  148. package/ts3.8/react.d.ts +5 -0
  149. package/ts3.8/utils.d.ts +3 -0
  150. package/ts3.8/vanilla/atom.d.ts +48 -0
  151. package/ts3.8/vanilla/internals.d.ts +165 -0
  152. package/ts3.8/vanilla/store.d.ts +6 -0
  153. package/ts3.8/vanilla/typeUtils.d.ts +8 -0
  154. package/ts3.8/vanilla/utils/atomFamily.d.ts +56 -0
  155. package/ts3.8/vanilla/utils/atomWithDefault.d.ts +11 -0
  156. package/ts3.8/vanilla/utils/atomWithLazy.d.ts +3 -0
  157. package/ts3.8/vanilla/utils/atomWithObservable.d.ts +37 -0
  158. package/ts3.8/vanilla/utils/atomWithReducer.d.ts +8 -0
  159. package/ts3.8/vanilla/utils/atomWithRefresh.d.ts +10 -0
  160. package/ts3.8/vanilla/utils/atomWithReset.d.ts +11 -0
  161. package/ts3.8/vanilla/utils/atomWithStorage.d.ts +53 -0
  162. package/ts3.8/vanilla/utils/constants.d.ts +2 -0
  163. package/ts3.8/vanilla/utils/freezeAtom.d.ts +7 -0
  164. package/ts3.8/vanilla/utils/loadable.d.ts +34 -0
  165. package/ts3.8/vanilla/utils/selectAtom.d.ts +3 -0
  166. package/ts3.8/vanilla/utils/splitAtom.d.ts +21 -0
  167. package/ts3.8/vanilla/utils/unwrap.d.ts +6 -0
  168. package/ts3.8/vanilla/utils.d.ts +15 -0
  169. package/ts3.8/vanilla.d.ts +5 -0
  170. package/ts_version_3.8_and_above_is_required.d.ts +0 -0
  171. package/umd/babel/plugin-debug-label.development.js +58 -0
  172. package/umd/babel/plugin-debug-label.production.js +1 -0
  173. package/umd/babel/plugin-react-refresh.development.js +76 -0
  174. package/umd/babel/plugin-react-refresh.production.js +1 -0
  175. package/umd/babel/preset.development.js +114 -0
  176. package/umd/babel/preset.production.js +1 -0
  177. package/umd/index.development.js +20 -0
  178. package/umd/index.production.js +1 -0
  179. package/umd/react/utils.development.js +101 -0
  180. package/umd/react/utils.production.js +1 -0
  181. package/umd/react.development.js +184 -0
  182. package/umd/react.production.js +1 -0
  183. package/umd/utils.development.js +20 -0
  184. package/umd/utils.production.js +1 -0
  185. package/umd/vanilla/internals.development.js +785 -0
  186. package/umd/vanilla/internals.production.js +1 -0
  187. package/umd/vanilla/utils.development.js +858 -0
  188. package/umd/vanilla/utils.production.js +1 -0
  189. package/umd/vanilla.development.js +64 -0
  190. package/umd/vanilla.production.js +1 -0
  191. package/utils.d.ts +2 -0
  192. package/utils.js +19 -0
  193. package/vanilla/atom.d.ts +47 -0
  194. package/vanilla/internals.d.ts +164 -0
  195. package/vanilla/internals.js +779 -0
  196. package/vanilla/store.d.ts +5 -0
  197. package/vanilla/typeUtils.d.ts +7 -0
  198. package/vanilla/utils/atomFamily.d.ts +55 -0
  199. package/vanilla/utils/atomWithDefault.d.ts +6 -0
  200. package/vanilla/utils/atomWithLazy.d.ts +2 -0
  201. package/vanilla/utils/atomWithObservable.d.ts +32 -0
  202. package/vanilla/utils/atomWithReducer.d.ts +3 -0
  203. package/vanilla/utils/atomWithRefresh.d.ts +6 -0
  204. package/vanilla/utils/atomWithReset.d.ts +8 -0
  205. package/vanilla/utils/atomWithStorage.d.ts +50 -0
  206. package/vanilla/utils/constants.d.ts +1 -0
  207. package/vanilla/utils/freezeAtom.d.ts +6 -0
  208. package/vanilla/utils/loadable.d.ts +33 -0
  209. package/vanilla/utils/selectAtom.d.ts +2 -0
  210. package/vanilla/utils/splitAtom.d.ts +16 -0
  211. package/vanilla/utils/unwrap.d.ts +5 -0
  212. package/vanilla/utils.d.ts +14 -0
  213. package/vanilla/utils.js +854 -0
  214. package/vanilla.d.ts +4 -0
  215. package/vanilla.js +60 -0
@@ -0,0 +1,101 @@
1
+ 'use client';
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('jotai/react'), require('jotai/vanilla/utils'), require('jotai/vanilla')) :
4
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'jotai/react', 'jotai/vanilla/utils', 'jotai/vanilla'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jotaiReactUtils = {}, global.React, global.jotaiReact, global.jotaiVanillaUtils, global.jotaiVanilla));
6
+ })(this, (function (exports, react$1, react, utils, vanilla) { 'use strict';
7
+
8
+ function useResetAtom(anAtom, options) {
9
+ var setAtom = react.useSetAtom(anAtom, options);
10
+ var resetAtom = react$1.useCallback(function () {
11
+ return setAtom(utils.RESET);
12
+ }, [setAtom]);
13
+ return resetAtom;
14
+ }
15
+
16
+ function useReducerAtom(anAtom, reducer, options) {
17
+ {
18
+ console.warn('[DEPRECATED] useReducerAtom is deprecated and will be removed in the future. Please create your own version using the recipe. https://github.com/pmndrs/jotai/pull/2467');
19
+ }
20
+ var _useAtom = react.useAtom(anAtom, options),
21
+ state = _useAtom[0],
22
+ setState = _useAtom[1];
23
+ var dispatch = react$1.useCallback(function (action) {
24
+ setState(function (prev) {
25
+ return reducer(prev, action);
26
+ });
27
+ }, [setState, reducer]);
28
+ return [state, dispatch];
29
+ }
30
+
31
+ function useAtomCallback(callback, options) {
32
+ var anAtom = react$1.useMemo(function () {
33
+ return vanilla.atom(null, function (get, set) {
34
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
35
+ args[_key - 2] = arguments[_key];
36
+ }
37
+ return callback.apply(void 0, [get, set].concat(args));
38
+ });
39
+ }, [callback]);
40
+ return react.useSetAtom(anAtom, options);
41
+ }
42
+
43
+ function _arrayLikeToArray(r, a) {
44
+ (null == a || a > r.length) && (a = r.length);
45
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
46
+ return n;
47
+ }
48
+ function _createForOfIteratorHelperLoose(r, e) {
49
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
50
+ if (t) return (t = t.call(r)).next.bind(t);
51
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
52
+ t && (r = t);
53
+ var o = 0;
54
+ return function () {
55
+ return o >= r.length ? {
56
+ done: true
57
+ } : {
58
+ done: false,
59
+ value: r[o++]
60
+ };
61
+ };
62
+ }
63
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
+ }
65
+ function _unsupportedIterableToArray(r, a) {
66
+ if (r) {
67
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
68
+ var t = {}.toString.call(r).slice(8, -1);
69
+ 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;
70
+ }
71
+ }
72
+
73
+ var hydratedMap = new WeakMap();
74
+ function useHydrateAtoms(values, options) {
75
+ var store = react.useStore(options);
76
+ var hydratedSet = getHydratedSet(store);
77
+ for (var _iterator = _createForOfIteratorHelperLoose(values), _step; !(_step = _iterator()).done;) {
78
+ var _step$value = _step.value,
79
+ atom = _step$value[0],
80
+ args = _arrayLikeToArray(_step$value).slice(1);
81
+ if (!hydratedSet.has(atom) || options != null && options.dangerouslyForceHydrate) {
82
+ hydratedSet.add(atom);
83
+ store.set.apply(store, [atom].concat(args));
84
+ }
85
+ }
86
+ }
87
+ var getHydratedSet = function getHydratedSet(store) {
88
+ var hydratedSet = hydratedMap.get(store);
89
+ if (!hydratedSet) {
90
+ hydratedSet = new WeakSet();
91
+ hydratedMap.set(store, hydratedSet);
92
+ }
93
+ return hydratedSet;
94
+ };
95
+
96
+ exports.useAtomCallback = useAtomCallback;
97
+ exports.useHydrateAtoms = useHydrateAtoms;
98
+ exports.useReducerAtom = useReducerAtom;
99
+ exports.useResetAtom = useResetAtom;
100
+
101
+ }));
@@ -0,0 +1 @@
1
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("jotai/react"),require("jotai/vanilla/utils"),require("jotai/vanilla")):"function"==typeof define&&define.amd?define(["exports","react","jotai/react","jotai/vanilla/utils","jotai/vanilla"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jotaiReactUtils={},t.React,t.jotaiReact,t.jotaiVanillaUtils,t.jotaiVanilla)}(this,function(t,e,r,n,a){"use strict";function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return o(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(t,e):void 0}}(t))||e){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u=new WeakMap;var l=function(t){var e=u.get(t);return e||(e=new WeakSet,u.set(t,e)),e};t.useAtomCallback=function(t,n){var o=e.useMemo(function(){return a.atom(null,function(e,r){for(var n=arguments.length,a=new Array(n>2?n-2:0),o=2;o<n;o++)a[o-2]=arguments[o];return t.apply(void 0,[e,r].concat(a))})},[t]);return r.useSetAtom(o,n)},t.useHydrateAtoms=function(t,e){for(var n,a=r.useStore(e),u=l(a),c=i(t);!(n=c()).done;){var s=n.value,f=s[0],d=o(s).slice(1);(!u.has(f)||null!=e&&e.dangerouslyForceHydrate)&&(u.add(f),a.set.apply(a,[f].concat(d)))}},t.useReducerAtom=function(t,n,a){var o=r.useAtom(t,a),i=o[0],u=o[1];return[i,e.useCallback(function(t){u(function(e){return n(e,t)})},[u,n])]},t.useResetAtom=function(t,a){var o=r.useSetAtom(t,a);return e.useCallback(function(){return o(n.RESET)},[o])}});
@@ -0,0 +1,184 @@
1
+ 'use client';
2
+ (function (global, factory) {
3
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('jotai/vanilla'), require('jotai/vanilla/internals')) :
4
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'jotai/vanilla', 'jotai/vanilla/internals'], factory) :
5
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jotaiReact = {}, global.React, global.jotaiVanilla, global.jotaiVanillaInternals));
6
+ })(this, (function (exports, React, vanilla, internals) { 'use strict';
7
+
8
+ var StoreContext = React.createContext(undefined);
9
+ function useStore(options) {
10
+ var store = React.useContext(StoreContext);
11
+ return (options == null ? void 0 : options.store) || store || vanilla.getDefaultStore();
12
+ }
13
+ function Provider(_ref) {
14
+ var children = _ref.children,
15
+ store = _ref.store;
16
+ var storeRef = React.useRef(null);
17
+ if (store) {
18
+ return React.createElement(StoreContext.Provider, {
19
+ value: store
20
+ }, children);
21
+ }
22
+ if (storeRef.current === null) {
23
+ storeRef.current = vanilla.createStore();
24
+ }
25
+ return React.createElement(StoreContext.Provider, {
26
+ value: storeRef.current
27
+ }, children);
28
+ }
29
+
30
+ var isPromiseLike = function isPromiseLike(x) {
31
+ return typeof (x == null ? void 0 : x.then) === 'function';
32
+ };
33
+ var attachPromiseStatus = function attachPromiseStatus(promise) {
34
+ if (!promise.status) {
35
+ promise.status = 'pending';
36
+ promise.then(function (v) {
37
+ promise.status = 'fulfilled';
38
+ promise.value = v;
39
+ }, function (e) {
40
+ promise.status = 'rejected';
41
+ promise.reason = e;
42
+ });
43
+ }
44
+ };
45
+ var use = React.use || function (promise) {
46
+ if (promise.status === 'pending') {
47
+ throw promise;
48
+ } else if (promise.status === 'fulfilled') {
49
+ return promise.value;
50
+ } else if (promise.status === 'rejected') {
51
+ throw promise.reason;
52
+ } else {
53
+ attachPromiseStatus(promise);
54
+ throw promise;
55
+ }
56
+ };
57
+ var continuablePromiseMap = new WeakMap();
58
+ var createContinuablePromise = function createContinuablePromise(store, promise, getValue) {
59
+ var buildingBlocks = internals.INTERNAL_getBuildingBlocksRev2(store);
60
+ var registerAbortHandler = buildingBlocks[26];
61
+ var continuablePromise = continuablePromiseMap.get(promise);
62
+ if (!continuablePromise) {
63
+ continuablePromise = new Promise(function (resolve, reject) {
64
+ var curr = promise;
65
+ var onFulfilled = function onFulfilled(me) {
66
+ return function (v) {
67
+ if (curr === me) {
68
+ resolve(v);
69
+ }
70
+ };
71
+ };
72
+ var onRejected = function onRejected(me) {
73
+ return function (e) {
74
+ if (curr === me) {
75
+ reject(e);
76
+ }
77
+ };
78
+ };
79
+ var _onAbort = function onAbort() {
80
+ try {
81
+ var nextValue = getValue();
82
+ if (isPromiseLike(nextValue)) {
83
+ continuablePromiseMap.set(nextValue, continuablePromise);
84
+ curr = nextValue;
85
+ nextValue.then(onFulfilled(nextValue), onRejected(nextValue));
86
+ registerAbortHandler(store, nextValue, _onAbort);
87
+ } else {
88
+ resolve(nextValue);
89
+ }
90
+ } catch (e) {
91
+ reject(e);
92
+ }
93
+ };
94
+ promise.then(onFulfilled(promise), onRejected(promise));
95
+ registerAbortHandler(store, promise, _onAbort);
96
+ });
97
+ continuablePromiseMap.set(promise, continuablePromise);
98
+ }
99
+ return continuablePromise;
100
+ };
101
+ function useAtomValue(atom, options) {
102
+ var _ref = options || {},
103
+ delay = _ref.delay,
104
+ _ref$unstable_promise = _ref.unstable_promiseStatus,
105
+ promiseStatus = _ref$unstable_promise === void 0 ? !React.use : _ref$unstable_promise;
106
+ var store = useStore(options);
107
+ var _useReducer = React.useReducer(function (prev) {
108
+ var nextValue = store.get(atom);
109
+ if (Object.is(prev[0], nextValue) && prev[1] === store && prev[2] === atom) {
110
+ return prev;
111
+ }
112
+ return [nextValue, store, atom];
113
+ }, undefined, function () {
114
+ return [store.get(atom), store, atom];
115
+ }),
116
+ _useReducer$ = _useReducer[0],
117
+ valueFromReducer = _useReducer$[0],
118
+ storeFromReducer = _useReducer$[1],
119
+ atomFromReducer = _useReducer$[2],
120
+ rerender = _useReducer[1];
121
+ var value = valueFromReducer;
122
+ if (storeFromReducer !== store || atomFromReducer !== atom) {
123
+ rerender();
124
+ value = store.get(atom);
125
+ }
126
+ React.useEffect(function () {
127
+ var unsub = store.sub(atom, function () {
128
+ if (promiseStatus) {
129
+ try {
130
+ var _value = store.get(atom);
131
+ if (isPromiseLike(_value)) {
132
+ attachPromiseStatus(createContinuablePromise(store, _value, function () {
133
+ return store.get(atom);
134
+ }));
135
+ }
136
+ } catch (_unused) {}
137
+ }
138
+ if (typeof delay === 'number') {
139
+ setTimeout(rerender, delay);
140
+ return;
141
+ }
142
+ rerender();
143
+ });
144
+ rerender();
145
+ return unsub;
146
+ }, [store, atom, delay, promiseStatus]);
147
+ React.useDebugValue(value);
148
+ if (isPromiseLike(value)) {
149
+ var promise = createContinuablePromise(store, value, function () {
150
+ return store.get(atom);
151
+ });
152
+ if (promiseStatus) {
153
+ attachPromiseStatus(promise);
154
+ }
155
+ return use(promise);
156
+ }
157
+ return value;
158
+ }
159
+
160
+ function useSetAtom(atom, options) {
161
+ var store = useStore(options);
162
+ var setAtom = React.useCallback(function () {
163
+ if (!('write' in atom)) {
164
+ throw new Error('not writable atom');
165
+ }
166
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
167
+ args[_key] = arguments[_key];
168
+ }
169
+ return store.set.apply(store, [atom].concat(args));
170
+ }, [store, atom]);
171
+ return setAtom;
172
+ }
173
+
174
+ function useAtom(atom, options) {
175
+ return [useAtomValue(atom, options), useSetAtom(atom, options)];
176
+ }
177
+
178
+ exports.Provider = Provider;
179
+ exports.useAtom = useAtom;
180
+ exports.useAtomValue = useAtomValue;
181
+ exports.useSetAtom = useSetAtom;
182
+ exports.useStore = useStore;
183
+
184
+ }));
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("jotai/vanilla"),require("jotai/vanilla/internals")):"function"==typeof define&&define.amd?define(["exports","react","jotai/vanilla","jotai/vanilla/internals"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jotaiReact={},e.React,e.jotaiVanilla,e.jotaiVanillaInternals)}(this,function(e,t,n,r){"use strict";var u=t.createContext(void 0);function i(e){var r=t.useContext(u);return(null==e?void 0:e.store)||r||n.getDefaultStore()}var o=function(e){return"function"==typeof(null==e?void 0:e.then)},a=function(e){e.status||(e.status="pending",e.then(function(t){e.status="fulfilled",e.value=t},function(t){e.status="rejected",e.reason=t}))},c=t.use||function(e){if("pending"===e.status)throw e;if("fulfilled"===e.status)return e.value;throw"rejected"===e.status?e.reason:(a(e),e)},f=new WeakMap,l=function(e,t,n){var u=r.INTERNAL_getBuildingBlocksRev2(e)[26],i=f.get(t);return i||(i=new Promise(function(r,a){var c=t,l=function(e){return function(t){c===e&&r(t)}},s=function(e){return function(t){c===e&&a(t)}},v=function(){try{var t=n();o(t)?(f.set(t,i),c=t,t.then(l(t),s(t)),u(e,t,v)):r(t)}catch(e){a(e)}};t.then(l(t),s(t)),u(e,t,v)}),f.set(t,i)),i};function s(e,n){var r=n||{},u=r.delay,f=r.unstable_promiseStatus,s=void 0===f?!t.use:f,v=i(n),d=t.useReducer(function(t){var n=v.get(e);return Object.is(t[0],n)&&t[1]===v&&t[2]===e?t:[n,v,e]},void 0,function(){return[v.get(e),v,e]}),g=d[0],p=g[0],h=g[1],j=g[2],m=d[1],y=p;if(h===v&&j===e||(m(),y=v.get(e)),t.useEffect(function(){var t=v.sub(e,function(){if(s)try{var t=v.get(e);o(t)&&a(l(v,t,function(){return v.get(e)}))}catch(e){}"number"!=typeof u?m():setTimeout(m,u)});return m(),t},[v,e,u,s]),t.useDebugValue(y),o(y)){var b=l(v,y,function(){return v.get(e)});return s&&a(b),c(b)}return y}function v(e,n){var r=i(n),u=t.useCallback(function(){for(var t=arguments.length,n=new Array(t),u=0;u<t;u++)n[u]=arguments[u];return r.set.apply(r,[e].concat(n))},[r,e]);return u}e.Provider=function(e){var r=e.children,i=e.store,o=t.useRef(null);return i?t.createElement(u.Provider,{value:i},r):(null===o.current&&(o.current=n.createStore()),t.createElement(u.Provider,{value:o.current},r))},e.useAtom=function(e,t){return[s(e,t),v(e,t)]},e.useAtomValue=s,e.useSetAtom=v,e.useStore=i});
@@ -0,0 +1,20 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('jotai/vanilla/utils'), require('jotai/react/utils')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'jotai/vanilla/utils', 'jotai/react/utils'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.jotaiUtils = {}, global.jotaiVanillaUtils, global.jotaiReactUtils));
5
+ })(this, (function (exports, utils$1, utils) { 'use strict';
6
+
7
+ Object.keys(utils$1).forEach(function (k) {
8
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
9
+ enumerable: true,
10
+ get: function () { return utils$1[k]; }
11
+ });
12
+ });
13
+ Object.keys(utils).forEach(function (k) {
14
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
15
+ enumerable: true,
16
+ get: function () { return utils[k]; }
17
+ });
18
+ });
19
+
20
+ }));
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jotai/vanilla/utils"),require("jotai/react/utils")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla/utils","jotai/react/utils"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jotaiUtils={},e.jotaiVanillaUtils,e.jotaiReactUtils)}(this,function(e,t,i){"use strict";Object.keys(t).forEach(function(i){"default"===i||Object.prototype.hasOwnProperty.call(e,i)||Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[i]}})}),Object.keys(i).forEach(function(t){"default"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return i[t]}})})});