@preact/signals-react 1.3.0 → 1.3.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @preact/signals-react
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#358](https://github.com/preactjs/signals/pull/358) [`08ed3a0`](https://github.com/preactjs/signals/commit/08ed3a02a2291ad1e18389674d8ac20678064723) Thanks [@andrewiggins](https://github.com/andrewiggins)! - Add note to Readme about tradeoffs in current React integration
8
+
9
+ * [#355](https://github.com/preactjs/signals/pull/355) [`21c8ee9`](https://github.com/preactjs/signals/commit/21c8ee98070a8bda05095dc91b64d2fe54042fb3) Thanks [@andrewiggins](https://github.com/andrewiggins)! - Fix React adapter in SSR and when rerendering
10
+
11
+ - [#352](https://github.com/preactjs/signals/pull/352) [`a2b7320`](https://github.com/preactjs/signals/commit/a2b7320ee5829f58efaee5f7b20d993f35f09d2a) Thanks [@rschristian](https://github.com/rschristian)! - Uses full file path on useSyncExternalStore import, fixing a possible resolution issue in some build tools.
12
+
13
+ ## 1.3.1
14
+
15
+ ### Patch Changes
16
+
17
+ - [#344](https://github.com/preactjs/signals/pull/344) [`acdead6`](https://github.com/preactjs/signals/commit/acdead6a8631d7198d8a55d6cbde7713b5776d6b) Thanks [@andrewiggins](https://github.com/andrewiggins)! - Allow React ^16.14.0 as a peer dependency
18
+
3
19
  ## 1.3.0
4
20
 
5
21
  ### Minor Changes
package/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Signals
3
2
 
4
3
  Signals is a performant state management library with two primary goals:
@@ -15,17 +14,19 @@ npm install @preact/signals-react
15
14
  ```
16
15
 
17
16
  - [Guide / API](../../README.md#guide--api)
18
- - [`signal(initialValue)`](../../README.md#signalinitialvalue)
19
- - [`signal.peek()`](../../README.md#signalpeek)
20
- - [`computed(fn)`](../../README.md#computedfn)
21
- - [`effect(fn)`](../../README.md#effectfn)
22
- - [`batch(fn)`](../../README.md#batchfn)
17
+ - [`signal(initialValue)`](../../README.md#signalinitialvalue)
18
+ - [`signal.peek()`](../../README.md#signalpeek)
19
+ - [`computed(fn)`](../../README.md#computedfn)
20
+ - [`effect(fn)`](../../README.md#effectfn)
21
+ - [`batch(fn)`](../../README.md#batchfn)
23
22
  - [React Integration](#react-integration)
24
- - [Hooks](#hooks)
23
+ - [Hooks](#hooks)
25
24
  - [License](#license)
26
25
 
27
26
  ## React Integration
28
27
 
28
+ > Note: The React integration plugs into some React internals and may break unexpectedly in future versions of React. If you are using Signals with React and encounter errors such as "Rendered more hooks than during previous render", "Should have a queue. This is likely a bug in React." or "Cannot redefine property: createElement" please open an issue here.
29
+
29
30
  The React integration can be installed via:
30
31
 
31
32
  ```sh
@@ -68,4 +69,3 @@ function Counter() {
68
69
  ## License
69
70
 
70
71
  `MIT`, see the [LICENSE](../../LICENSE) file.
71
-
package/dist/signals.js CHANGED
@@ -1 +1 @@
1
- var r=require("react"),n=require("react/jsx-runtime"),e=require("react/jsx-dev-runtime"),t=require("@preact/signals-core"),u=require("use-sync-external-store/shim/index");function i(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var o,f=/*#__PURE__*/i(r),c=/*#__PURE__*/i(n),a=/*#__PURE__*/i(e),s=[],l=Symbol.for("react.element");function v(r){if(o)o();o=r&&r.S()}var p=!1,x=null;Object.defineProperty(r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return x},set:function(r){if(!p){var n=y(x),e=y(r),i=n===b&&e===d;x=r;if(n===d&&e===b){p=!0;var o=function(r){var n=r.useRef();if(null==n.current)n.current=function(){var r,n,e=0,u=t.effect(function(){r=this});r.c=function(){e=e+1|0;if(n)n()};return{updater:r,subscribe:function(r){n=r;return function(){e=e+1|0;n=void 0;u()}},getSnapshot:function(){return e}}}();var e=n.current;u.useSyncExternalStore(e.subscribe,e.getSnapshot,e.getSnapshot);return e}(r);p=!1;v(o.updater)}else if(i)v()}else x=r}});var b=0,d=1,g=new Map;function y(r){if(!r)return d;var n,e=g.get(r);if(void 0!==e)return e;if(r.useCallback.length<2)n=d;else if(/Invalid/.test(r.useCallback))n=2;else n=b;g.set(r,n);return n}function h(r){if("function"!=typeof r)return r;else return function(n,e){if("string"==typeof n&&e)for(var u in e){var i=e[u];if("children"!==u&&i instanceof t.Signal)e[u]=i.value}return r.call.apply(r,[r,n,e].concat([].slice.call(arguments,2)))}}var j=c,m=a;f.createElement=h(f.createElement);m.jsx&&(m.jsx=h(m.jsx));j.jsx&&(j.jsx=h(j.jsx));m.jsxs&&(m.jsxs=h(m.jsxs));j.jsxs&&(j.jsxs=h(j.jsxs));m.jsxDEV&&(m.jsxDEV=h(m.jsxDEV));j.jsxDEV&&(j.jsxDEV=h(j.jsxDEV));Object.defineProperties(t.Signal.prototype,{$$typeof:{configurable:!0,value:l},type:{configurable:!0,value:function(r){return r.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});exports.Signal=t.Signal;exports.batch=t.batch;exports.computed=t.computed;exports.effect=t.effect;exports.signal=t.signal;exports.useComputed=function(n){var e=r.useRef(n);e.current=n;return r.useMemo(function(){return t.computed(function(){return e.current()})},s)};exports.useSignal=function(n){return r.useMemo(function(){return t.signal(n)},s)};exports.useSignalEffect=function(n){var e=r.useRef(n);e.current=n;r.useEffect(function(){return t.effect(function(){return e.current()})},s)};//# sourceMappingURL=signals.js.map
1
+ var e=require("react"),r=require("react/jsx-runtime"),n=require("react/jsx-dev-runtime"),t=require("@preact/signals-core"),u=require("use-sync-external-store/shim/index.js");function i(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var f,o=/*#__PURE__*/i(e),c=/*#__PURE__*/i(r),a=/*#__PURE__*/i(n),s=[],l=Symbol.for("react.element");function v(e){if(f)f();f=e&&e.S()}var p=!1,d=null;Object.defineProperty(e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return d},set:function(e){if(!p){var r=b(d),n=b(e);d=e;if(function(e,r){if(1&e&&28&r)return!0;else if(2&e||2&r)return!1;else if(16&r)return!0;else return!1}(r,n)){p=!0;var i=function(e){var r=e.useRef();if(null==r.current)r.current=function(){var e,r,n=0,u=t.effect(function(){e=this});e.c=function(){n=n+1|0;if(r)r()};return{updater:e,subscribe:function(e){r=e;return function(){n=n+1|0;r=void 0;u()}},getSnapshot:function(){return n}}}();var n=r.current;u.useSyncExternalStore(n.subscribe,n.getSnapshot,n.getSnapshot);return n}(e);p=!1;v(i.updater)}else if(function(e,r){return Boolean(28&e&&1&r)}(r,n))v()}else d=e}});var x=new Map;function b(e){if(!e)return 1;var r,n=x.get(e);if(void 0!==n)return n;var t=e.useCallback.toString();if(e.useReducer===e.useEffect)r=1;else if(e.useEffect===e.useImperativeHandle)r=32;else if(/Invalid/.test(t))r=2;else if(/updateCallback/.test(t)||/\[0\]/.test(t)&&/\[1\]/.test(t)){var u=e.useReducer.toString();if(/rerenderReducer/.test(u)||/return\s*\[\w+,/.test(u))r=16;else r=8}else r=4;x.set(e,r);return r}function g(e){if("function"!=typeof e)return e;else return function(r,n){if("string"==typeof r&&n)for(var u in n){var i=n[u];if("children"!==u&&i instanceof t.Signal)n[u]=i.value}return e.call.apply(e,[e,r,n].concat([].slice.call(arguments,2)))}}var y=c,j=a;o.createElement=g(o.createElement);j.jsx&&(j.jsx=g(j.jsx));y.jsx&&(y.jsx=g(y.jsx));j.jsxs&&(j.jsxs=g(j.jsxs));y.jsxs&&(y.jsxs=g(y.jsxs));j.jsxDEV&&(j.jsxDEV=g(j.jsxDEV));y.jsxDEV&&(y.jsxDEV=g(y.jsxDEV));Object.defineProperties(t.Signal.prototype,{$$typeof:{configurable:!0,value:l},type:{configurable:!0,value:function(e){return e.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});exports.Signal=t.Signal;exports.batch=t.batch;exports.computed=t.computed;exports.effect=t.effect;exports.signal=t.signal;exports.useComputed=function(r){var n=e.useRef(r);n.current=r;return e.useMemo(function(){return t.computed(function(){return n.current()})},s)};exports.useSignal=function(r){return e.useMemo(function(){return t.signal(r)},s)};exports.useSignalEffect=function(r){var n=e.useRef(r);n.current=r;e.useEffect(function(){return t.effect(function(){return n.current()})},s)};//# sourceMappingURL=signals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n\ttype useCallback,\n\ttype useReducer,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof useRef;\n\tuseCallback: typeof useCallback;\n\tuseReducer: typeof useReducer;\n\tuseSyncExternalStore: typeof useSyncExternalStore;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to a valid one. Right after React finishes\n// rendering a component, the dispatcher is set to an erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a valid dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an effect and manually starting the effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some edge cases to be aware of:\n// - In development, useReducer, useState, and useMemo changes the dispatcher to\n// a different erroring dispatcher before invoking the reducer and resets it\n// right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are exiting a component\n// render. We ignore this change by detecting these dispatchers as different\n// from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// We are entering a component render if the current dispatcher is the\n\t\t// ContextOnlyDispatcher and the next dispatcher is a valid dispatcher.\n\t\tconst isEnteringComponentRender =\n\t\t\tcurrentDispatcherType === ContextOnlyDispatcherType &&\n\t\t\tnextDispatcherType === ValidDispatcherType;\n\n\t\t// We are exiting a component render if the current dispatcher is a valid\n\t\t// dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n\t\tconst isExitingComponentRender =\n\t\t\tcurrentDispatcherType === ValidDispatcherType &&\n\t\t\tnextDispatcherType === ContextOnlyDispatcherType;\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (isExitingComponentRender) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\nconst ValidDispatcherType = 0;\nconst ContextOnlyDispatcherType = 1;\nconst ErroringDispatcherType = 2;\n\n// We inject a useSyncExternalStore into every function component via\n// CurrentDispatcher. This prevents injecting into anything other than a\n// function component render.\nconst dispatcherTypeCache = new Map<ReactDispatcher, number>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): number {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. Check the number of arguments\n\t// for this dispatcher's useCallback implementation to determine if it is a\n\t// ContextOnlyDispatcher. All other dispatchers, erroring or not, define\n\t// functions with arguments and so fail this check.\n\tlet type: number;\n\tif (dispatcher.useCallback.length < 2) {\n\t\ttype = ContextOnlyDispatcherType;\n\t} else if (/Invalid/.test(dispatcher.useCallback as any)) {\n\t\ttype = ErroringDispatcherType;\n\t} else {\n\t\ttype = ValidDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["finishUpdate","Empty","ReactElemType","Symbol","setCurrentUpdater","updater","_start","lock","Object","defineProperty","ReactInternals","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","currentDispatcher","nextDispatcherType","ValidDispatcherType","ContextOnlyDispatcherType","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","dispatcher","cached","dispatcherTypeCache","useCallback","length","type","test","WrapJsx","jsx","props","v","i","Signal","value","call","apply","concat","slice","arguments","JsxPro","jsxRuntime","jsxRuntimeDev","React","createElement","JsxDev","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useMemo","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"qPAqCIA,8DAVOC,EAAG,GACRC,EAAgBC,OAAM,IAAK,iBAWjC,SAAAC,EAA2BC,GAE1B,GAAIL,EAAcA,IAElBA,EAAeK,GAAWA,EAAQC,GAClC,CAwHD,IAAIC,GAAO,IACqC,KAChDC,OAAOC,eAAeC,EAAAA,mDAAeC,uBAAwB,UAAW,CACvEC,eACC,QACA,EACDC,IAJuE,SAInEC,GACH,IAAIP,EAAJ,CAKA,IAAMQ,EAAwBC,EAAkBC,GACxBC,EAAGF,EAAkBF,KAW5CC,IAA0BI,GAC1BD,IAAuBE,EAIxBH,EAAoBH,EACpB,GAZCC,IAA0BK,GAC1BF,IAAuBC,EAWO,CAC9BZ,GAAO,EACP,IAAMc,EAvFT,SAA8BP,GAC7B,IAAMQ,EAAWR,EAAeS,SAChC,GAAwB,MAApBD,EAASE,QACZF,EAASE,QA/CX,WACC,IAAAnB,EAEAoB,EADIC,EAAU,EAGCC,EAAGC,EAAMA,OAAC,WACxBvB,EAAUwB,IACV,GACDxB,EAAQyB,EAAY,WACnBJ,EAAWA,EAAU,EAAK,EAC1B,GAAID,EAAqBA,GACzB,EAED,MAAO,CACNpB,QAAAA,EACA0B,UAFM,SAEIC,GACTP,EAAsBO,EAEtB,OAAO,WAWNN,EAAWA,EAAU,EAAK,EAC1BD,OAAsBQ,EACtBN,GACA,CACD,EACDO,YAAW,WACV,OACAR,CAAA,EAEF,CASoBS,GAGpB,IAAWd,EAAGC,EAASE,QACvBY,uBAAqBf,EAAMU,UAAWV,EAAMa,YAAab,EAAMa,aAE/D,OAAOb,CACP,CA6EgBgB,CAAqBvB,GACnCP,GAAO,EAEPH,EAAkBiB,EAAMhB,QACxB,SAAUiC,EACVlC,GA3BA,MAFAa,EAAoBH,CA+BrB,IAGF,IAAyBK,EAAG,IACM,IAMN,QAC5B,SAAAH,EAA2BuB,GAE1B,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E2D,KAAM1C,KACf,GAEF2C,IAAK,CAAEH,cAAc,EAAMjB,MAAO,QAoBlCqB,QAAAtB,OAAAuB,EAAAvB,OAAAsB,QAAAE,MAAAD,EAAAC,MAAAF,QAAAG,SAAAF,EAAAE,SAAAH,QAAA7C,OAAA8C,EAAA9C,OAAA6C,QAAAI,OAAAH,EAAAG,OAAAJ,QAAAK,YAbeA,SAAeC,GAC9B,IAAMC,EAAWzD,EAAAA,OAAOwD,GACxBC,EAASxD,QAAUuD,EACnB,OAAcE,EAAAA,QAAC,WAAML,OAAAA,EAAQA,SAAI,WAAMI,OAAAA,EAASxD,SAAf,EAAlB,EAA6CvB,EAC5D,EASAwE,QAAAS,UAjBeA,SAAa9B,GAC5B,OAAc6B,EAAAA,QAAC,kBAAYJ,SAAIzB,EAAhB,EAAwBnD,EACvC,EAeAwE,QAAAU,gBAPeA,SAAgBC,GAC/B,IAAMC,EAAW9D,EAAAA,OAAO6D,GACxBC,EAAS7D,QAAU4D,EAEnBE,YAAU,WACT,SAAa1D,OAAC,WAAA,OAAcyD,EAAC7D,SAAf,EACd,EAAEvB,EACH"}
1
+ {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n id: \"ReactCurrentDispatcher_PROD\",\n initial: \"null\",\n states: {\n null: {\n on: {\n pushDispatcher: \"ContextOnlyDispatcher\",\n },\n },\n ContextOnlyDispatcher: {\n on: {\n renderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n renderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n pushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n popDispatcher_NOOP: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnMount: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnUpdate: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n use_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n },\n },\n HooksDispatcherOnRerender: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n },\n});\n```\n*/\n\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender(currentDispatcherType, nextDispatcherType)) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (\n\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["finishUpdate","Empty","ReactElemType","Symbol","setCurrentUpdater","updater","_start","lock","currentDispatcher","Object","defineProperty","ReactInternals","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","Boolean","dispatcherTypeCache","Map","dispatcher","type","cached","useCallbackImpl","useCallback","toString","useReducer","useEffect","useImperativeHandle","test","useReducerImpl","WrapJsx","jsx","props","i","v","Signal","value","call","apply","concat","slice","arguments","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","use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gE,OAAAA,EAASpE,SAAf,EACd,EAAExB,EACH"}
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("react/jsx-runtime"),require("react/jsx-dev-runtime"),require("@preact/signals-core"),require("use-sync-external-store/shim/index")):"function"==typeof define&&define.amd?define(["exports","react","react/jsx-runtime","react/jsx-dev-runtime","@preact/signals-core","use-sync-external-store/shim/index"],n):n((e||self).reactSignals={},e.react,e.jsxRuntime,e.jsxRuntimeDev,e.signalsCore,e.index)}(this,function(e,n,r,t,i,u){function f(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o,c=/*#__PURE__*/f(n),a=/*#__PURE__*/f(r),s=/*#__PURE__*/f(t),l=[],v=Symbol.for("react.element");function d(e){if(o)o();o=e&&e.S()}var p=!1,b=null;Object.defineProperty(n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return b},set:function(e){if(!p){var n=h(b),r=h(e),t=n===g&&r===y;b=e;if(n===y&&r===g){p=!0;var f=function(e){var n=e.useRef();if(null==n.current)n.current=function(){var e,n,r=0,t=i.effect(function(){e=this});e.c=function(){r=r+1|0;if(n)n()};return{updater:e,subscribe:function(e){n=e;return function(){r=r+1|0;n=void 0;t()}},getSnapshot:function(){return r}}}();var r=n.current;u.useSyncExternalStore(r.subscribe,r.getSnapshot,r.getSnapshot);return r}(e);p=!1;d(f.updater)}else if(t)d()}else b=e}});var g=0,y=1,x=new Map;function h(e){if(!e)return y;var n,r=x.get(e);if(void 0!==r)return r;if(e.useCallback.length<2)n=y;else if(/Invalid/.test(e.useCallback))n=2;else n=g;x.set(e,n);return n}function m(e){if("function"!=typeof e)return e;else return function(n,r){if("string"==typeof n&&r)for(var t in r){var u=r[t];if("children"!==t&&u instanceof i.Signal)r[t]=u.value}return e.call.apply(e,[e,n,r].concat([].slice.call(arguments,2)))}}var j=a,q=s;c.createElement=m(c.createElement);q.jsx&&(q.jsx=m(q.jsx));j.jsx&&(j.jsx=m(j.jsx));q.jsxs&&(q.jsxs=m(q.jsxs));j.jsxs&&(j.jsxs=m(j.jsxs));q.jsxDEV&&(q.jsxDEV=m(q.jsxDEV));j.jsxDEV&&(j.jsxDEV=m(j.jsxDEV));Object.defineProperties(i.Signal.prototype,{$$typeof:{configurable:!0,value:v},type:{configurable:!0,value:function(e){return e.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});e.Signal=i.Signal;e.batch=i.batch;e.computed=i.computed;e.effect=i.effect;e.signal=i.signal;e.useComputed=function(e){var r=n.useRef(e);r.current=e;return n.useMemo(function(){return i.computed(function(){return r.current()})},l)};e.useSignal=function(e){return n.useMemo(function(){return i.signal(e)},l)};e.useSignalEffect=function(e){var r=n.useRef(e);r.current=e;n.useEffect(function(){return i.effect(function(){return r.current()})},l)}});//# sourceMappingURL=signals.min.js.map
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react"),require("react/jsx-runtime"),require("react/jsx-dev-runtime"),require("@preact/signals-core"),require("use-sync-external-store/shim/index.js")):"function"==typeof define&&define.amd?define(["exports","react","react/jsx-runtime","react/jsx-dev-runtime","@preact/signals-core","use-sync-external-store/shim/index.js"],n):n((e||self).reactSignals={},e.react,e.jsxRuntime,e.jsxRuntimeDev,e.signalsCore,e.index_js)}(this,function(e,n,r,t,i,u){function f(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var o,c=/*#__PURE__*/f(n),a=/*#__PURE__*/f(r),s=/*#__PURE__*/f(t),l=[],v=Symbol.for("react.element");function d(e){if(o)o();o=e&&e.S()}var p=!1,b=null;Object.defineProperty(n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return b},set:function(e){if(!p){var n=y(b),r=y(e);b=e;if(function(e,n){if(1&e&&28&n)return!0;else if(2&e||2&n)return!1;else if(16&n)return!0;else return!1}(n,r)){p=!0;var t=function(e){var n=e.useRef();if(null==n.current)n.current=function(){var e,n,r=0,t=i.effect(function(){e=this});e.c=function(){r=r+1|0;if(n)n()};return{updater:e,subscribe:function(e){n=e;return function(){r=r+1|0;n=void 0;t()}},getSnapshot:function(){return r}}}();var r=n.current;u.useSyncExternalStore(r.subscribe,r.getSnapshot,r.getSnapshot);return r}(e);p=!1;d(t.updater)}else if(function(e,n){return Boolean(28&e&&1&n)}(n,r))d()}else b=e}});var g=new Map;function y(e){if(!e)return 1;var n,r=g.get(e);if(void 0!==r)return r;var t=e.useCallback.toString();if(e.useReducer===e.useEffect)n=1;else if(e.useEffect===e.useImperativeHandle)n=32;else if(/Invalid/.test(t))n=2;else if(/updateCallback/.test(t)||/\[0\]/.test(t)&&/\[1\]/.test(t)){var i=e.useReducer.toString();if(/rerenderReducer/.test(i)||/return\s*\[\w+,/.test(i))n=16;else n=8}else n=4;g.set(e,n);return n}function x(e){if("function"!=typeof e)return e;else return function(n,r){if("string"==typeof n&&r)for(var t in r){var u=r[t];if("children"!==t&&u instanceof i.Signal)r[t]=u.value}return e.call.apply(e,[e,n,r].concat([].slice.call(arguments,2)))}}var j=a,h=s;c.createElement=x(c.createElement);h.jsx&&(h.jsx=x(h.jsx));j.jsx&&(j.jsx=x(j.jsx));h.jsxs&&(h.jsxs=x(h.jsxs));j.jsxs&&(j.jsxs=x(j.jsxs));h.jsxDEV&&(h.jsxDEV=x(h.jsxDEV));j.jsxDEV&&(j.jsxDEV=x(j.jsxDEV));Object.defineProperties(i.Signal.prototype,{$$typeof:{configurable:!0,value:v},type:{configurable:!0,value:function(e){return e.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});e.Signal=i.Signal;e.batch=i.batch;e.computed=i.computed;e.effect=i.effect;e.signal=i.signal;e.useComputed=function(e){var r=n.useRef(e);r.current=e;return n.useMemo(function(){return i.computed(function(){return r.current()})},l)};e.useSignal=function(e){return n.useMemo(function(){return i.signal(e)},l)};e.useSignalEffect=function(e){var r=n.useRef(e);r.current=e;n.useEffect(function(){return i.effect(function(){return r.current()})},l)}});//# sourceMappingURL=signals.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.min.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n\ttype useCallback,\n\ttype useReducer,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof useRef;\n\tuseCallback: typeof useCallback;\n\tuseReducer: typeof useReducer;\n\tuseSyncExternalStore: typeof useSyncExternalStore;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to a valid one. Right after React finishes\n// rendering a component, the dispatcher is set to an erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a valid dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an effect and manually starting the effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some edge cases to be aware of:\n// - In development, useReducer, useState, and useMemo changes the dispatcher to\n// a different erroring dispatcher before invoking the reducer and resets it\n// right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are exiting a component\n// render. We ignore this change by detecting these dispatchers as different\n// from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// We are entering a component render if the current dispatcher is the\n\t\t// ContextOnlyDispatcher and the next dispatcher is a valid dispatcher.\n\t\tconst isEnteringComponentRender =\n\t\t\tcurrentDispatcherType === ContextOnlyDispatcherType &&\n\t\t\tnextDispatcherType === ValidDispatcherType;\n\n\t\t// We are exiting a component render if the current dispatcher is a valid\n\t\t// dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n\t\tconst isExitingComponentRender =\n\t\t\tcurrentDispatcherType === ValidDispatcherType &&\n\t\t\tnextDispatcherType === ContextOnlyDispatcherType;\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (isExitingComponentRender) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\nconst ValidDispatcherType = 0;\nconst ContextOnlyDispatcherType = 1;\nconst ErroringDispatcherType = 2;\n\n// We inject a useSyncExternalStore into every function component via\n// CurrentDispatcher. This prevents injecting into anything other than a\n// function component render.\nconst dispatcherTypeCache = new Map<ReactDispatcher, number>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): number {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. Check the number of arguments\n\t// for this dispatcher's useCallback implementation to determine if it is a\n\t// ContextOnlyDispatcher. All other dispatchers, erroring or not, define\n\t// functions with arguments and so fail this check.\n\tlet type: number;\n\tif (dispatcher.useCallback.length < 2) {\n\t\ttype = ContextOnlyDispatcherType;\n\t} else if (/Invalid/.test(dispatcher.useCallback as any)) {\n\t\ttype = ErroringDispatcherType;\n\t} else {\n\t\ttype = ValidDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["finishUpdate","Empty","ReactElemType","Symbol","setCurrentUpdater","updater","_start","lock","Object","defineProperty","ReactInternals","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","currentDispatcher","nextDispatcherType","ValidDispatcherType","ContextOnlyDispatcherType","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","dispatcher","cached","dispatcherTypeCache","useCallback","length","type","test","WrapJsx","jsx","props","v","i","Signal","value","call","apply","concat","slice","arguments","JsxPro","jsxRuntime","jsxRuntimeDev","React","createElement","JsxDev","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useMemo","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"koBAqCIA,8DAVOC,EAAG,GACRC,EAAgBC,OAAM,IAAK,iBAWjC,SAAAC,EAA2BC,GAE1B,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,OAAA8C,EAAA9C,OAAA6C,EAAAI,OAAAH,EAAAG,OAAAJ,EAAAK,YAbeA,SAAeC,GAC9B,IAAMC,EAAWzD,EAAAA,OAAOwD,GACxBC,EAASxD,QAAUuD,EACnB,OAAcE,EAAAA,QAAC,WAAML,OAAAA,EAAQA,SAAI,WAAMI,OAAAA,EAASxD,SAAf,EAAlB,EAA6CvB,EAC5D,EASAwE,EAAAS,UAjBeA,SAAa9B,GAC5B,OAAc6B,EAAAA,QAAC,kBAAYJ,SAAIzB,EAAhB,EAAwBnD,EACvC,EAeAwE,EAAAU,gBAPeA,SAAgBC,GAC/B,IAAMC,EAAW9D,EAAAA,OAAO6D,GACxBC,EAAS7D,QAAU4D,EAEnBE,YAAU,WACT,SAAa1D,OAAC,WAAA,OAAcyD,EAAC7D,SAAf,EACd,EAAEvB,EACH,CAAA"}
1
+ {"version":3,"file":"signals.min.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n id: \"ReactCurrentDispatcher_PROD\",\n initial: \"null\",\n states: {\n null: {\n on: {\n pushDispatcher: \"ContextOnlyDispatcher\",\n },\n },\n ContextOnlyDispatcher: {\n on: {\n renderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n renderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n pushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n popDispatcher_NOOP: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnMount: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnUpdate: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n use_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n },\n },\n HooksDispatcherOnRerender: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n },\n});\n```\n*/\n\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender(currentDispatcherType, nextDispatcherType)) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (\n\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["finishUpdate","Empty","ReactElemType","Symbol","setCurrentUpdater","updater","_start","lock","currentDispatcher","Object","defineProperty","ReactInternals","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","Boolean","dispatcherTypeCache","Map","dispatcher","type","cached","useCallbackImpl","useCallback","toString","useReducer","useEffect","useImperativeHandle","test","useReducerImpl","WrapJsx","jsx","props","i","v","Signal","value","call","apply","concat","slice","arguments","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","_ref","data","ref","exports","signalsCore","batch","computed","signal","useComputed","compute","$compute","useMemo","useSignal","useSignalEffect","cb","callback"],"mappings":"2oBAqCAA,8DAZMC,EAAQ,GACRC,EAAgBC,OAAA,IAAW,iBAajC,SAASC,EAAkBC,GAE1B,GAAIL,EAAcA,IAElBA,EAAeK,GAAWA,EAAQC,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,useEffect as o}from"react";import i from"react/jsx-runtime";import c from"react/jsx-dev-runtime";import{Signal as f,signal as u,computed as s,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";import{useSyncExternalStore as a}from"use-sync-external-store/shim/index";const p=[],m=Symbol.for("react.element");let g;function b(t){if(g)g();g=t&&t.S()}let d=!1,v=null;Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:()=>v,set(t){if(d){v=t;return}const n=j(v),e=j(t),r=n===h&&e===x;v=t;if(n===x&&e===h){d=!0;const n=function(t){const n=t.useRef();if(null==n.current)n.current=function(){let t,n,e=0,r=l(function(){t=this});t.c=function(){e=e+1|0;if(n)n()};return{updater:t,subscribe(t){n=t;return function(){e=e+1|0;n=void 0;r()}},getSnapshot:()=>e}}();const e=n.current;a(e.subscribe,e.getSnapshot,e.getSnapshot);return e}(t);d=!1;b(n.updater)}else if(r)b()}});const h=0,x=1,y=new Map;function j(t){if(!t)return x;const n=y.get(t);if(void 0!==n)return n;let e;if(t.useCallback.length<2)e=x;else if(/Invalid/.test(t.useCallback))e=2;else e=h;y.set(t,e);return e}function S(t){if("function"!=typeof t)return t;else return function(n,e,...r){if("string"==typeof n&&e)for(let t in e){let n=e[t];if("children"!==t&&n instanceof f)e[t]=n.value}return t.call(t,n,e,...r)}}const O=i,$=c;t.createElement=S(t.createElement);$.jsx&&($.jsx=S($.jsx));O.jsx&&(O.jsx=S(O.jsx));$.jsxs&&($.jsxs=S($.jsxs));O.jsxs&&(O.jsxs=S(O.jsxs));$.jsxDEV&&($.jsxDEV=S($.jsxDEV));O.jsxDEV&&(O.jsxDEV=S(O.jsxDEV));Object.defineProperties(f.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:function({data:t}){return t.value}},props:{configurable:!0,get(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(t){return e(()=>u(t),p)}function useComputed(t){const n=r(t);n.current=t;return e(()=>s(()=>n.current()),p)}function useSignalEffect(t){const n=r(t);n.current=t;o(()=>l(()=>n.current()),p)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.mjs.map
1
+ import e,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as t,useMemo as n,useRef as r,useEffect as i}from"react";import o from"react/jsx-runtime";import u from"react/jsx-dev-runtime";import{Signal as f,signal as c,computed as s,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";import{useSyncExternalStore as a}from"use-sync-external-store/shim/index.js";const p=[],m=Symbol.for("react.element");let d;function g(e){if(d)d();d=e&&e.S()}let b=!1,v=null;Object.defineProperty(t.ReactCurrentDispatcher,"current",{get:()=>v,set(e){if(b){v=e;return}const t=x(v),n=x(e);v=e;if(function(e,t){if(1&e&&28&t)return!0;else if(2&e||2&t)return!1;else if(16&t)return!0;else return!1}(t,n)){b=!0;const t=function(e){const t=e.useRef();if(null==t.current)t.current=function(){let e,t,n=0,r=l(function(){e=this});e.c=function(){n=n+1|0;if(t)t()};return{updater:e,subscribe(e){t=e;return function(){n=n+1|0;t=void 0;r()}},getSnapshot:()=>n}}();const n=t.current;a(n.subscribe,n.getSnapshot,n.getSnapshot);return n}(e);b=!1;g(t.updater)}else if(function(e,t){return Boolean(28&e&&1&t)}(t,n))g()}});const h=new Map;function x(e){if(!e)return 1;const t=h.get(e);if(void 0!==t)return t;let n;const r=e.useCallback.toString();if(e.useReducer===e.useEffect)n=1;else if(e.useEffect===e.useImperativeHandle)n=32;else if(/Invalid/.test(r))n=2;else if(/updateCallback/.test(r)||/\[0\]/.test(r)&&/\[1\]/.test(r)){let t=e.useReducer.toString();if(/rerenderReducer/.test(t)||/return\s*\[\w+,/.test(t))n=16;else n=8}else n=4;h.set(e,n);return n}function y(e){if("function"!=typeof e)return e;else return function(t,n,...r){if("string"==typeof t&&n)for(let e in n){let t=n[e];if("children"!==e&&t instanceof f)n[e]=t.value}return e.call(e,t,n,...r)}}const j=o,S=u;e.createElement=y(e.createElement);S.jsx&&(S.jsx=y(S.jsx));j.jsx&&(j.jsx=y(j.jsx));S.jsxs&&(S.jsxs=y(S.jsxs));j.jsxs&&(j.jsxs=y(j.jsxs));S.jsxDEV&&(S.jsxDEV=y(S.jsxDEV));j.jsxDEV&&(j.jsxDEV=y(j.jsxDEV));Object.defineProperties(f.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:function({data:e}){return e.value}},props:{configurable:!0,get(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(e){return n(()=>c(e),p)}function useComputed(e){const t=r(e);t.current=e;return n(()=>s(()=>t.current()),p)}function useSignalEffect(e){const t=r(e);t.current=e;i(()=>l(()=>t.current()),p)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n\ttype useCallback,\n\ttype useReducer,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof useRef;\n\tuseCallback: typeof useCallback;\n\tuseReducer: typeof useReducer;\n\tuseSyncExternalStore: typeof useSyncExternalStore;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to a valid one. Right after React finishes\n// rendering a component, the dispatcher is set to an erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a valid dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an effect and manually starting the effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some edge cases to be aware of:\n// - In development, useReducer, useState, and useMemo changes the dispatcher to\n// a different erroring dispatcher before invoking the reducer and resets it\n// right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are exiting a component\n// render. We ignore this change by detecting these dispatchers as different\n// from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// We are entering a component render if the current dispatcher is the\n\t\t// ContextOnlyDispatcher and the next dispatcher is a valid dispatcher.\n\t\tconst isEnteringComponentRender =\n\t\t\tcurrentDispatcherType === ContextOnlyDispatcherType &&\n\t\t\tnextDispatcherType === ValidDispatcherType;\n\n\t\t// We are exiting a component render if the current dispatcher is a valid\n\t\t// dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n\t\tconst isExitingComponentRender =\n\t\t\tcurrentDispatcherType === ValidDispatcherType &&\n\t\t\tnextDispatcherType === ContextOnlyDispatcherType;\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (isExitingComponentRender) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\nconst ValidDispatcherType = 0;\nconst ContextOnlyDispatcherType = 1;\nconst ErroringDispatcherType = 2;\n\n// We inject a useSyncExternalStore into every function component via\n// CurrentDispatcher. This prevents injecting into anything other than a\n// function component render.\nconst dispatcherTypeCache = new Map<ReactDispatcher, number>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): number {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. Check the number of arguments\n\t// for this dispatcher's useCallback implementation to determine if it is a\n\t// ContextOnlyDispatcher. All other dispatchers, erroring or not, define\n\t// functions with arguments and so fail this check.\n\tlet type: number;\n\tif (dispatcher.useCallback.length < 2) {\n\t\ttype = ContextOnlyDispatcherType;\n\t} else if (/Invalid/.test(dispatcher.useCallback as any)) {\n\t\ttype = ErroringDispatcherType;\n\t} else {\n\t\ttype = ValidDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["Empty","ReactElemType","Symbol","for","finishUpdate","setCurrentUpdater","updater","_start","lock","currentDispatcher","Object","defineProperty","ReactInternals","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","isExitingComponentRender","ValidDispatcherType","nextDispatcherType","ContextOnlyDispatcherType","store","storeRef","useRef","current","onChangeNotifyReact","unsubscribe","effect","this","_callback","version","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","dispatcherTypeCache","Map","dispatcher","cached","type","useCallback","length","test","WrapJsx","jsx","props","rest","i","v","Signal","value","call","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","data","ref","useSignal","useMemo","signal","useComputed","compute","$compute","computed","cb","callback","useEffect","useSignalEffect"],"mappings":"gaA2BA,MAAWA,EAAG,GACRC,EAAgBC,OAAOC,IAAI,iBASjC,IAAAC,EAEA,SAASC,EAAkBC,GAE1B,GAAIF,EAAcA,IAElBA,EAAeE,GAAWA,EAAQC,GAClC,CAwHD,IAAQC,GAAG,EACPC,EAA4C,KAChDC,OAAOC,eAAeC,EAAeC,uBAAwB,UAAW,CACvEC,IAAG,IACKL,EAERM,IAAIC,GACH,GAAIR,EAAM,CACTC,EAAoBO,EACpB,MACA,CAED,MAA2BC,EAAGC,EAAkBT,KACrBS,EAAkBF,GAUvCG,EACLF,IAA0BG,GAC1BC,IAAuBC,EAIxBb,EAAoBO,EACpB,GAZCC,IAA0BK,GAC1BD,IAAuBD,EAWO,CAC9BZ,GAAO,EACP,MAAWe,EAvFd,SAA8BP,GAC7B,MAAcQ,EAAGR,EAAeS,SAChC,GAAwB,MAApBD,EAASE,QACZF,EAASE,QA/CX,WACC,IAAIpB,EAEAqB,IADU,EAGVC,EAAcC,EAAO,WACxBvB,EAAUwB,IACV,GACDxB,EAAQyB,EAAY,WACnBC,EAAWA,EAAU,EAAK,EAC1B,GAAIL,EAAqBA,GACzB,EAED,MAAO,CACNrB,UACA2B,UAAUC,GACTP,EAAsBO,EAEtB,kBAWCF,EAAWA,EAAU,EAAK,EAC1BL,OAAsBQ,EACtBP,GACA,CACD,EACDQ,YAAW,MAIZ,CASoBC,GAGpB,MAAMd,EAAQC,EAASE,QACvBY,EAAqBf,EAAMU,UAAWV,EAAMa,YAAab,EAAMa,aAE/D,OACAb,CAAA,CA6E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,cAAc,EAAMb,MAP7B,UAAcc,KAAEA,IACf,SAAYd,KACZ,GAMAL,MAAO,CACNkB,cAAc,EACdtD,MACC,MAAO,CAAEuD,KAAMvC,KACf,GAEFwC,IAAK,CAAEF,cAAc,EAAMb,MAAO,QAGnBgB,SAAAA,UAAahB,GAC5B,OAAOiB,EAAQ,IAAMC,EAAUlB,GAAQvD,EACvC,CAEe0E,SAAAA,YAAeC,GAC9B,MAAcC,EAAGnD,EAAOkD,GACxBC,EAASlD,QAAUiD,EACnB,OAAOH,EAAQ,IAAMK,EAAY,IAAMD,EAASlD,WAAY1B,EAC5D,CAEK,yBAA0B8E,GAC/B,MAAcC,EAAGtD,EAAOqD,GACxBC,EAASrD,QAAUoD,EAEnBE,EAAU,IACInD,EAAC,IAAMkD,EAASrD,WAC3B1B,EACH,QAAA0E,YAAAH,UAAAU"}
1
+ {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n id: \"ReactCurrentDispatcher_PROD\",\n initial: \"null\",\n states: {\n null: {\n on: {\n pushDispatcher: \"ContextOnlyDispatcher\",\n },\n },\n ContextOnlyDispatcher: {\n on: {\n renderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n renderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n pushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n popDispatcher_NOOP: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnMount: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnUpdate: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n use_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n },\n },\n HooksDispatcherOnRerender: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n },\n});\n```\n*/\n\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender(currentDispatcherType, nextDispatcherType)) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (\n\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["Empty","ReactElemType","Symbol","for","finishUpdate","setCurrentUpdater","updater","_start","lock","currentDispatcher","Object","defineProperty","ReactInternals","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","Boolean","dispatcherTypeCache","Map","dispatcher","cached","type","useCallbackImpl","useCallback","toString","useReducer","useEffect","useImperativeHandle","test","useReducerImpl","WrapJsx","jsx","props","rest","i","v","Signal","value","call","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","data","ref","useSignal","useMemo","signal","useComputed","compute","$compute","computed","useSignalEffect","cb","callback"],"mappings":"maAyBA,MAAMA,EAAQ,GACRC,EAAgBC,OAAOC,IAAI,iBAWjC,IAAIC,EAEJ,SAAAC,EAA2BC,GAE1B,GAAIF,EAAcA,IAElBA,EAAeE,GAAWA,EAAQC,GAClC,CA8MD,IAAQC,GAAG,EACPC,EAA4C,KAChDC,OAAOC,eAAeC,EA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AAOY,UAAW,CACzCC,SAAU,CAAEC,cAAc,EAAMb,MAAO5D,GACvC4C,KAAM,CAAE6B,cAAc,EAAMb,MAP7B,UAAcc,KAAEA,IACf,OAAOA,EAAKd,KACZ,GAMAL,MAAO,CACNkB,cAAc,EACd5D,MACC,MAAO,CAAE6D,KAAM7C,KACf,GAEF8C,IAAK,CAAEF,cAAc,EAAMb,MAAO,iBAG7BgB,UAAuBhB,GAC5B,OAAciB,EAAC,IAAMC,EAAUlB,GAAQ7D,EACvC,CAEegF,SAAAA,YAAeC,GAC9B,MAAMC,EAAW1D,EAAOyD,GACxBC,EAASzD,QAAUwD,EACnB,OAAcH,EAAC,IAAMK,EAAY,IAAMD,EAASzD,WAAYzB,EAC5D,CAEeoF,SAAAA,gBAAgBC,GAC/B,MAAMC,EAAW9D,EAAO6D,GACxBC,EAAS7D,QAAU4D,EAEnBnC,EAAU,IACFrB,EAAO,IAAMyD,EAAS7D,WAC3BzB,EACH,QAAAgF,YAAAH,UAAAO"}
@@ -1 +1 @@
1
- import n,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as r,useMemo as t,useRef as e,useEffect as i}from"react";import u from"react/jsx-runtime";import f from"react/jsx-dev-runtime";import{Signal as o,signal as c,computed as a,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";import{useSyncExternalStore as s}from"use-sync-external-store/shim/index";var v,p=[],m=Symbol.for("react.element");function g(n){if(v)v();v=n&&n.S()}var b=!1,d=null;Object.defineProperty(r.ReactCurrentDispatcher,"current",{get:function(){return d},set:function(n){if(!b){var r=j(d),t=j(n),e=r===h&&t===x;d=n;if(r===x&&t===h){b=!0;var i=function(n){var r=n.useRef();if(null==r.current)r.current=function(){var n,r,t=0,e=l(function(){n=this});n.c=function(){t=t+1|0;if(r)r()};return{updater:n,subscribe:function(n){r=n;return function(){t=t+1|0;r=void 0;e()}},getSnapshot:function(){return t}}}();var t=r.current;s(t.subscribe,t.getSnapshot,t.getSnapshot);return t}(n);b=!1;g(i.updater)}else if(e)g()}else d=n}});var h=0,x=1,y=new Map;function j(n){if(!n)return x;var r,t=y.get(n);if(void 0!==t)return t;if(n.useCallback.length<2)r=x;else if(/Invalid/.test(n.useCallback))r=2;else r=h;y.set(n,r);return r}function S(n){if("function"!=typeof n)return n;else return function(r,t){if("string"==typeof r&&t)for(var e in t){var i=t[e];if("children"!==e&&i instanceof o)t[e]=i.value}return n.call.apply(n,[n,r,t].concat([].slice.call(arguments,2)))}}var O=u,$=f;n.createElement=S(n.createElement);$.jsx&&($.jsx=S($.jsx));O.jsx&&(O.jsx=S(O.jsx));$.jsxs&&($.jsxs=S($.jsxs));O.jsxs&&(O.jsxs=S(O.jsxs));$.jsxDEV&&($.jsxDEV=S($.jsxDEV));O.jsxDEV&&(O.jsxDEV=S(O.jsxDEV));Object.defineProperties(o.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:function(n){return n.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(n){return t(function(){return c(n)},p)}function useComputed(n){var r=e(n);r.current=n;return t(function(){return a(function(){return r.current()})},p)}function useSignalEffect(n){var r=e(n);r.current=n;i(function(){return l(function(){return r.current()})},p)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
1
+ import r,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as n,useMemo as e,useRef as t,useEffect as i}from"react";import u from"react/jsx-runtime";import f from"react/jsx-dev-runtime";import{Signal as o,signal as c,computed as a,effect as l}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";import{useSyncExternalStore as s}from"use-sync-external-store/shim/index.js";var v,p=[],m=Symbol.for("react.element");function d(r){if(v)v();v=r&&r.S()}var g=!1,b=null;Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:function(){return b},set:function(r){if(!g){var n=x(b),e=x(r);b=r;if(function(r,n){if(1&r&&28&n)return!0;else if(2&r||2&n)return!1;else if(16&n)return!0;else return!1}(n,e)){g=!0;var t=function(r){var n=r.useRef();if(null==n.current)n.current=function(){var r,n,e=0,t=l(function(){r=this});r.c=function(){e=e+1|0;if(n)n()};return{updater:r,subscribe:function(r){n=r;return function(){e=e+1|0;n=void 0;t()}},getSnapshot:function(){return e}}}();var e=n.current;s(e.subscribe,e.getSnapshot,e.getSnapshot);return e}(r);g=!1;d(t.updater)}else if(function(r,n){return Boolean(28&r&&1&n)}(n,e))d()}else b=r}});var h=new Map;function x(r){if(!r)return 1;var n,e=h.get(r);if(void 0!==e)return e;var t=r.useCallback.toString();if(r.useReducer===r.useEffect)n=1;else if(r.useEffect===r.useImperativeHandle)n=32;else if(/Invalid/.test(t))n=2;else if(/updateCallback/.test(t)||/\[0\]/.test(t)&&/\[1\]/.test(t)){var i=r.useReducer.toString();if(/rerenderReducer/.test(i)||/return\s*\[\w+,/.test(i))n=16;else n=8}else n=4;h.set(r,n);return n}function y(r){if("function"!=typeof r)return r;else return function(n,e){if("string"==typeof n&&e)for(var t in e){var i=e[t];if("children"!==t&&i instanceof o)e[t]=i.value}return r.call.apply(r,[r,n,e].concat([].slice.call(arguments,2)))}}var j=u,S=f;r.createElement=y(r.createElement);S.jsx&&(S.jsx=y(S.jsx));j.jsx&&(j.jsx=y(j.jsx));S.jsxs&&(S.jsxs=y(S.jsxs));j.jsxs&&(j.jsxs=y(j.jsxs));S.jsxDEV&&(S.jsxDEV=y(S.jsxDEV));j.jsxDEV&&(j.jsxDEV=y(j.jsxDEV));Object.defineProperties(o.prototype,{$$typeof:{configurable:!0,value:m},type:{configurable:!0,value:function(r){return r.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});function useSignal(r){return e(function(){return c(r)},p)}function useComputed(r){var n=t(r);n.current=r;return e(function(){return a(function(){return n.current()})},p)}function useSignalEffect(r){var n=t(r);n.current=r;i(function(){return l(function(){return n.current()})},p)}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.module.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n\ttype useCallback,\n\ttype useReducer,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof useRef;\n\tuseCallback: typeof useCallback;\n\tuseReducer: typeof useReducer;\n\tuseSyncExternalStore: typeof useSyncExternalStore;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://reactjs.org/docs/hooks-reference.html#usesyncexternalstore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to a valid one. Right after React finishes\n// rendering a component, the dispatcher is set to an erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a valid dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an effect and manually starting the effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some edge cases to be aware of:\n// - In development, useReducer, useState, and useMemo changes the dispatcher to\n// a different erroring dispatcher before invoking the reducer and resets it\n// right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are exiting a component\n// render. We ignore this change by detecting these dispatchers as different\n// from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// We are entering a component render if the current dispatcher is the\n\t\t// ContextOnlyDispatcher and the next dispatcher is a valid dispatcher.\n\t\tconst isEnteringComponentRender =\n\t\t\tcurrentDispatcherType === ContextOnlyDispatcherType &&\n\t\t\tnextDispatcherType === ValidDispatcherType;\n\n\t\t// We are exiting a component render if the current dispatcher is a valid\n\t\t// dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n\t\tconst isExitingComponentRender =\n\t\t\tcurrentDispatcherType === ValidDispatcherType &&\n\t\t\tnextDispatcherType === ContextOnlyDispatcherType;\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (isExitingComponentRender) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\nconst ValidDispatcherType = 0;\nconst ContextOnlyDispatcherType = 1;\nconst ErroringDispatcherType = 2;\n\n// We inject a useSyncExternalStore into every function component via\n// CurrentDispatcher. This prevents injecting into anything other than a\n// function component render.\nconst dispatcherTypeCache = new Map<ReactDispatcher, number>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): number {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. Check the number of arguments\n\t// for this dispatcher's useCallback implementation to determine if it is a\n\t// ContextOnlyDispatcher. All other dispatchers, erroring or not, define\n\t// functions with arguments and so fail this check.\n\tlet type: number;\n\tif (dispatcher.useCallback.length < 2) {\n\t\ttype = ContextOnlyDispatcherType;\n\t} else if (/Invalid/.test(dispatcher.useCallback as any)) {\n\t\ttype = ErroringDispatcherType;\n\t} else {\n\t\ttype = ValidDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["finishUpdate","Empty","ReactElemType","Symbol","setCurrentUpdater","updater","_start","lock","Object","defineProperty","ReactInternals","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","currentDispatcher","nextDispatcherType","ValidDispatcherType","ContextOnlyDispatcherType","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","dispatcher","cached","dispatcherTypeCache","useCallback","length","type","test","WrapJsx","jsx","props","v","i","Signal","value","call","apply","concat","slice","arguments","JsxPro","jsxRuntime","jsxRuntimeDev","React","createElement","JsxDev","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","_ref","data","ref","useSignal","useMemo","signal","useComputed","compute","$compute","computed","useSignalEffect","cb","callback","useEffect"],"mappings":"gaA2BA,IAUIA,EAVOC,EAAG,GACRC,EAAgBC,OAAM,IAAK,iBAWjC,SAAAC,EAA2BC,GAE1B,GAAIL,EAAcA,IAElBA,EAAeK,GAAWA,EAAQC,GAClC,CAwHD,IAAIC,GAAO,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OAAAA,EAAStD,SAAf,EAAlB,EAA6CvB,EAC5D,CAEe+E,SAAAA,gBAAgBC,GAC/B,IAAMC,EAAW3D,EAAO0D,GACxBC,EAAS1D,QAAUyD,EAEnBE,EAAU,WACT,SAAc,WAAA,OAAcD,EAAC1D,SAAf,EACd,EAAEvB,EACH,QAAA2E,YAAAH,UAAAO"}
1
+ {"version":3,"file":"signals.module.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\n\tuseEffect,\n\t// @ts-ignore-next-line\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as ReactInternals,\n\ttype ReactElement,\n} from \"react\";\nimport React from \"react\";\nimport jsxRuntime from \"react/jsx-runtime\";\nimport jsxRuntimeDev from \"react/jsx-dev-runtime\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { useSyncExternalStore } from \"use-sync-external-store/shim/index.js\";\nimport type { Effect, JsxRuntimeModule } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\nconst Empty = [] as const;\nconst ReactElemType = Symbol.for(\"react.element\"); // https://github.com/facebook/react/blob/346c7d4c43a0717302d446da9e7423a8e28d8996/packages/shared/ReactSymbols.js#L15\n\ninterface ReactDispatcher {\n\tuseRef: typeof React.useRef;\n\tuseCallback: typeof React.useCallback;\n\tuseReducer: typeof React.useReducer;\n\tuseSyncExternalStore: typeof React.useSyncExternalStore;\n\tuseEffect: typeof React.useEffect;\n\tuseImperativeHandle: typeof React.useImperativeHandle;\n}\n\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\ninterface EffectStore {\n\tupdater: Effect;\n\tsubscribe(onStoreChange: () => void): () => void;\n\tgetSnapshot(): number;\n}\n\n/**\n * A redux-like store whose store value is a positive 32bit integer (a 'version').\n *\n * React subscribes to this store and gets a snapshot of the current 'version',\n * whenever the 'version' changes, we tell React it's time to update the component (call 'onStoreChange').\n *\n * How we achieve this is by creating a binding with an 'effect', when the `effect._callback' is called,\n * we update our store version and tell React to re-render the component ([1] We don't really care when/how React does it).\n *\n * [1]\n * @see https://react.dev/reference/react/useSyncExternalStore\n * @see https://github.com/reactjs/rfcs/blob/main/text/0214-use-sync-external-store.md\n */\nfunction createEffectStore(): EffectStore {\n\tlet updater!: Effect;\n\tlet version = 0;\n\tlet onChangeNotifyReact: (() => void) | undefined;\n\n\tlet unsubscribe = effect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = function () {\n\t\tversion = (version + 1) | 0;\n\t\tif (onChangeNotifyReact) onChangeNotifyReact();\n\t};\n\n\treturn {\n\t\tupdater,\n\t\tsubscribe(onStoreChange) {\n\t\t\tonChangeNotifyReact = onStoreChange;\n\n\t\t\treturn function () {\n\t\t\t\t/**\n\t\t\t\t * Rotate to next version when unsubscribing to ensure that components are re-run\n\t\t\t\t * when subscribing again.\n\t\t\t\t *\n\t\t\t\t * In StrictMode, 'memo'-ed components seem to keep a stale snapshot version, so\n\t\t\t\t * don't re-run after subscribing again if the version is the same as last time.\n\t\t\t\t *\n\t\t\t\t * Because we unsubscribe from the effect, the version may not change. We simply\n\t\t\t\t * set a new initial version in case of stale snapshots here.\n\t\t\t\t */\n\t\t\t\tversion = (version + 1) | 0;\n\t\t\t\tonChangeNotifyReact = undefined;\n\t\t\t\tunsubscribe();\n\t\t\t};\n\t\t},\n\t\tgetSnapshot() {\n\t\t\treturn version;\n\t\t},\n\t};\n}\n\n/**\n * Custom hook to create the effect to track signals used during render and\n * subscribe to changes to rerender the component when the signals change\n */\nfunction usePreactSignalStore(nextDispatcher: ReactDispatcher): EffectStore {\n\tconst storeRef = nextDispatcher.useRef<EffectStore>();\n\tif (storeRef.current == null) {\n\t\tstoreRef.current = createEffectStore();\n\t}\n\n\tconst store = storeRef.current;\n\tuseSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n\n\treturn store;\n}\n\n// In order for signals to work in React, we need to observe what signals a\n// component uses while rendering. To do this, we need to know when a component\n// is rendering. To do this, we watch the transition of the\n// ReactCurrentDispatcher to know when a component is rerendering.\n//\n// To track when we are entering and exiting a component render (i.e. before and\n// after React renders a component), we track how the dispatcher changes.\n// Outside of a component rendering, the dispatcher is set to an instance that\n// errors or warns when any hooks are called. This behavior is prevents hooks\n// from being used outside of components. Right before React renders a\n// component, the dispatcher is set to an instance that doesn't warn or error\n// and contains the implementations of all hooks. Right after React finishes\n// rendering a component, the dispatcher is set to the erroring one again. This\n// erroring dispatcher is called the `ContextOnlyDispatcher` in React's source.\n//\n// So, we watch the getter and setter on `ReactCurrentDispatcher.current` to\n// monitor the changes to the current ReactDispatcher. When the dispatcher\n// changes from the ContextOnlyDispatcher to a \"valid\" dispatcher, we assume we\n// are entering a component render. At this point, we setup our\n// auto-subscriptions for any signals used in the component. We do this by\n// creating an Signal effect and manually starting the Signal effect. We use\n// `useSyncExternalStore` to trigger rerenders on the component when any signals\n// it uses changes.\n//\n// When the dispatcher changes from a valid dispatcher back to the\n// ContextOnlyDispatcher, we assume we are exiting a component render. At this\n// point we stop the effect.\n//\n// Some additional complexities to be aware of:\n// - If a component calls `setState` while rendering, React will re-render the\n// component immediately. Before triggering the re-render, React will change\n// the dispatcher to the HooksDispatcherOnRerender. When we transition to this\n// rerendering adapter, we need to re-trigger our hooks to keep the order of\n// hooks the same for every render of a component.\n//\n// - In development, useReducer, useState, and useMemo change the dispatcher to\n// a different warning dispatcher (not ContextOnlyDispatcher) before invoking\n// the reducer and resets it right after.\n//\n// The useSyncExternalStore shim will use some of these hooks when we invoke\n// it while entering a component render. We need to prevent this dispatcher\n// change caused by these hooks from re-triggering our entering logic (it\n// would cause an infinite loop if we did not). We do this by using a lock to\n// prevent the setter from running while we are in the setter.\n//\n// When a Component's function body invokes useReducer, useState, or useMemo,\n// this change in dispatcher should not signal that we are entering or exiting\n// a component render. We ignore this change by detecting these dispatchers as\n// different from ContextOnlyDispatcher and other valid dispatchers.\n//\n// - The `use` hook will change the dispatcher to from a valid update dispatcher\n// to a valid mount dispatcher in some cases. Similarly to useReducer\n// mentioned above, we should not signal that we are exiting a component\n// during this change. Because these other valid dispatchers do not pass the\n// ContextOnlyDispatcher check, they do not affect our logic.\n//\n// - When server rendering, React does not change the dispatcher before and\n// after each component render. It sets it once for before the first render\n// and once for after the last render. This means that we will not be able to\n// detect when we are entering or exiting a component render. This is fine\n// because we don't need to detect this for server rendering. A component\n// can't trigger async rerenders in SSR so we don't need to track signals.\n//\n// If a component updates a signal value while rendering during SSR, we will\n// not rerender the component because the signal value will synchronously\n// change so all reads of the signal further down the tree will see the new\n// value.\n\n/*\nBelow is a state machine definition for transitions between the various\ndispatchers in React's prod build. (It does not include dev time warning\ndispatchers which are just always ignored).\n\nENTER and EXIT suffixes indicates whether this ReactCurrentDispatcher transition\nsignals we are entering or exiting a component render, or if it doesn't signal a\nchange in the component rendering lifecyle (NOOP).\n\n```js\n// Paste this into https://stately.ai/viz to visualize the state machine.\nimport { createMachine } from \"xstate\";\n\n// ENTER, EXIT, NOOP suffixes indicates whether this ReactCurrentDispatcher\n// transition signals we are entering or exiting a component render, or\n// if it doesn't signal a change in the component rendering lifecyle (NOOP).\n\nconst dispatcherMachinePROD = createMachine({\n id: \"ReactCurrentDispatcher_PROD\",\n initial: \"null\",\n states: {\n null: {\n on: {\n pushDispatcher: \"ContextOnlyDispatcher\",\n },\n },\n ContextOnlyDispatcher: {\n on: {\n renderWithHooks_Mount_ENTER: \"HooksDispatcherOnMount\",\n renderWithHooks_Update_ENTER: \"HooksDispatcherOnUpdate\",\n pushDispatcher_NOOP: \"ContextOnlyDispatcher\",\n popDispatcher_NOOP: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnMount: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n HooksDispatcherOnUpdate: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n use_ResumeSuspensedMount_NOOP: \"HooksDispatcherOnMount\",\n },\n },\n HooksDispatcherOnRerender: {\n on: {\n renderWithHooksAgain_ENTER: \"HooksDispatcherOnRerender\",\n resetHooksAfterThrow_EXIT: \"ContextOnlyDispatcher\",\n finishRenderingHooks_EXIT: \"ContextOnlyDispatcher\",\n },\n },\n },\n});\n```\n*/\n\nlet lock = false;\nlet currentDispatcher: ReactDispatcher | null = null;\nObject.defineProperty(ReactInternals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(nextDispatcher: ReactDispatcher) {\n\t\tif (lock) {\n\t\t\tcurrentDispatcher = nextDispatcher;\n\t\t\treturn;\n\t\t}\n\n\t\tconst currentDispatcherType = getDispatcherType(currentDispatcher);\n\t\tconst nextDispatcherType = getDispatcherType(nextDispatcher);\n\n\t\t// Update the current dispatcher now so the hooks inside of the\n\t\t// useSyncExternalStore shim get the right dispatcher.\n\t\tcurrentDispatcher = nextDispatcher;\n\t\tif (isEnteringComponentRender(currentDispatcherType, nextDispatcherType)) {\n\t\t\tlock = true;\n\t\t\tconst store = usePreactSignalStore(nextDispatcher);\n\t\t\tlock = false;\n\n\t\t\tsetCurrentUpdater(store.updater);\n\t\t} else if (\n\t\t\tisExitingComponentRender(currentDispatcherType, nextDispatcherType)\n\t\t) {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\ntype DispatcherType = number;\nconst ContextOnlyDispatcherType = 1 << 0;\nconst WarningDispatcherType = 1 << 1;\nconst MountDispatcherType = 1 << 2;\nconst UpdateDispatcherType = 1 << 3;\nconst RerenderDispatcherType = 1 << 4;\nconst ServerDispatcherType = 1 << 5;\nconst BrowserClientDispatcherType =\n\tMountDispatcherType | UpdateDispatcherType | RerenderDispatcherType;\n\nconst dispatcherTypeCache = new Map<ReactDispatcher, DispatcherType>();\nfunction getDispatcherType(dispatcher: ReactDispatcher | null): DispatcherType {\n\t// Treat null the same as the ContextOnlyDispatcher.\n\tif (!dispatcher) return ContextOnlyDispatcherType;\n\n\tconst cached = dispatcherTypeCache.get(dispatcher);\n\tif (cached !== undefined) return cached;\n\n\t// The ContextOnlyDispatcher sets all the hook implementations to a function\n\t// that takes no arguments and throws and error. This dispatcher is the only\n\t// dispatcher where useReducer and useEffect will have the same\n\t// implementation.\n\tlet type: DispatcherType;\n\tconst useCallbackImpl = dispatcher.useCallback.toString();\n\tif (dispatcher.useReducer === dispatcher.useEffect) {\n\t\ttype = ContextOnlyDispatcherType;\n\n\t\t// @ts-expect-error When server rendering, useEffect and useImperativeHandle\n\t\t// are both set to noop functions and so have the same implementation.\n\t} else if (dispatcher.useEffect === dispatcher.useImperativeHandle) {\n\t\ttype = ServerDispatcherType;\n\t} else if (/Invalid/.test(useCallbackImpl)) {\n\t\t// We first check for warning dispatchers because they would also pass some\n\t\t// of the checks below.\n\t\ttype = WarningDispatcherType;\n\t} else if (\n\t\t// The development mount dispatcher invokes a function called\n\t\t// `mountCallback` whereas the development update/re-render dispatcher\n\t\t// invokes a function called `updateCallback`. Use that difference to\n\t\t// determine if we are in a mount or update-like dispatcher in development.\n\t\t// The production mount dispatcher defines an array of the form [callback,\n\t\t// deps] whereas update/re-render dispatchers read the array using array\n\t\t// indices (e.g. `[0]` and `[1]`). Use those differences to determine if we\n\t\t// are in a mount or update-like dispatcher in production.\n\t\t/updateCallback/.test(useCallbackImpl) ||\n\t\t(/\\[0\\]/.test(useCallbackImpl) && /\\[1\\]/.test(useCallbackImpl))\n\t) {\n\t\t// The update and rerender dispatchers have different implementations for\n\t\t// useReducer. We'll check it's implementation to determine if this is the\n\t\t// rerender or update dispatcher.\n\t\tlet useReducerImpl = dispatcher.useReducer.toString();\n\t\tif (\n\t\t\t// The development rerender dispatcher invokes a function called\n\t\t\t// `rerenderReducer` whereas the update dispatcher invokes a function\n\t\t\t// called `updateReducer`. The production rerender dispatcher returns an\n\t\t\t// array of the form `[state, dispatch]` whereas the update dispatcher\n\t\t\t// returns an array of `[fiber.memoizedState, dispatch]` so we check the\n\t\t\t// return statement in the implementation of useReducer to differentiate\n\t\t\t// between the two.\n\t\t\t/rerenderReducer/.test(useReducerImpl) ||\n\t\t\t/return\\s*\\[\\w+,/.test(useReducerImpl)\n\t\t) {\n\t\t\ttype = RerenderDispatcherType;\n\t\t} else {\n\t\t\ttype = UpdateDispatcherType;\n\t\t}\n\t} else {\n\t\ttype = MountDispatcherType;\n\t}\n\n\tdispatcherTypeCache.set(dispatcher, type);\n\treturn type;\n}\n\nfunction isEnteringComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\tif (\n\t\tcurrentDispatcherType & ContextOnlyDispatcherType &&\n\t\tnextDispatcherType & BrowserClientDispatcherType\n\t) {\n\t\t// ## Mount or update (ContextOnlyDispatcher -> ValidDispatcher (Mount or Update))\n\t\t//\n\t\t// If the current dispatcher is the ContextOnlyDispatcher and the next\n\t\t// dispatcher is a valid dispatcher, we are entering a component render.\n\t\treturn true;\n\t} else if (\n\t\tcurrentDispatcherType & WarningDispatcherType ||\n\t\tnextDispatcherType & WarningDispatcherType\n\t) {\n\t\t// ## Warning dispatcher\n\t\t//\n\t\t// If the current dispatcher or next dispatcher is an warning dispatcher,\n\t\t// we are not entering a component render. The current warning dispatchers\n\t\t// are used to warn when hooks are nested improperly and do not indicate\n\t\t// entering a new component render.\n\t\treturn false;\n\t} else if (nextDispatcherType & RerenderDispatcherType) {\n\t\t// Any transition into the rerender dispatcher is the beginning of a\n\t\t// component render, so we should invoke our hooks. Details below.\n\t\t//\n\t\t// ## In-place rerendering (e.g. Mount -> Rerender)\n\t\t//\n\t\t// If we are transitioning from the mount, update, or rerender dispatcher to\n\t\t// the rerender dispatcher (e.g. HooksDispatcherOnMount to\n\t\t// HooksDispatcherOnRerender), then this component is rerendering due to\n\t\t// calling setState inside of its function body. We are re-entering a\n\t\t// component's render method and so we should re-invoke our hooks.\n\t\treturn true;\n\t} else {\n\t\t// ## Resuming suspended mount edge case (Update -> Mount)\n\t\t//\n\t\t// If we are transitioning from the update dispatcher to the mount\n\t\t// dispatcher, then this component is using the `use` hook and is resuming\n\t\t// from a mount. We should not re-invoke our hooks in this situation since\n\t\t// we are not entering a new component render, but instead continuing a\n\t\t// previous render.\n\t\t//\n\t\t// ## Other transitions\n\t\t//\n\t\t// For example, Mount -> Mount, Update -> Update, Mount -> Update, any\n\t\t// transition in and out of invalid dispatchers.\n\t\t//\n\t\t// There is no known transition for the following transitions so we default\n\t\t// to not triggering a re-enter of the component.\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnMount\n\t\t// - HooksDispatcherOnMount -> HooksDispatcherOnUpdate\n\t\t// - HooksDispatcherOnUpdate -> HooksDispatcherOnUpdate\n\t\treturn false;\n\t}\n}\n\n/**\n * We are exiting a component render if the current dispatcher is a valid\n * dispatcher and the next dispatcher is the ContextOnlyDispatcher.\n */\nfunction isExitingComponentRender(\n\tcurrentDispatcherType: DispatcherType,\n\tnextDispatcherType: DispatcherType\n): boolean {\n\treturn Boolean(\n\t\tcurrentDispatcherType & BrowserClientDispatcherType &&\n\t\t\tnextDispatcherType & ContextOnlyDispatcherType\n\t);\n}\n\nfunction WrapJsx<T>(jsx: T): T {\n\tif (typeof jsx !== \"function\") return jsx;\n\n\treturn function (type: any, props: any, ...rest: any[]) {\n\t\tif (typeof type === \"string\" && props) {\n\t\t\tfor (let i in props) {\n\t\t\t\tlet v = props[i];\n\t\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t\tprops[i] = v.value;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn jsx.call(jsx, type, props, ...rest);\n\t} as any as T;\n}\n\nconst JsxPro: JsxRuntimeModule = jsxRuntime;\nconst JsxDev: JsxRuntimeModule = jsxRuntimeDev;\n\n/**\n * createElement _may_ be called by jsx runtime as a fallback in certain cases,\n * so we need to wrap it regardless.\n *\n * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't\n * include both, so one of them will be set with `undefined` values.\n */\nReact.createElement = WrapJsx(React.createElement);\nJsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));\nJsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));\nJsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));\nJsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));\nJsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));\nJsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));\n\ndeclare module \"@preact/signals-core\" {\n\t// @ts-ignore internal Signal is viewed as function\n\t// eslint-disable-next-line @typescript-eslint/no-empty-interface\n\tinterface Signal extends ReactElement {}\n}\n\n/**\n * A wrapper component that renders a Signal's value directly as a Text node.\n */\nfunction Text({ data }: { data: Signal }) {\n\treturn data.value;\n}\n\n// Decorate Signals so React renders them as <Text> components.\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: ReactElemType },\n\ttype: { configurable: true, value: Text },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { configurable: true, value: null },\n});\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), Empty);\n}\n\nexport function useComputed<T>(compute: () => T) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\treturn useMemo(() => computed<T>(() => $compute.current()), Empty);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => callback.current());\n\t}, Empty);\n}\n"],"names":["finishUpdate","Empty","ReactElemType","Symbol","setCurrentUpdater","updater","_start","lock","currentDispatcher","Object","defineProperty","ReactInternals","ReactCurrentDispatcher","get","set","nextDispatcher","currentDispatcherType","getDispatcherType","nextDispatcherType","MountDispatcherType","isEnteringComponentRender","store","storeRef","useRef","current","onChangeNotifyReact","version","unsubscribe","effect","this","_callback","subscribe","onStoreChange","undefined","getSnapshot","createEffectStore","useSyncExternalStore","usePreactSignalStore","isExitingComponentRender","Boolean","dispatcherTypeCache","Map","dispatcher","type","cached","useCallbackImpl","useCallback","toString","useReducer","useEffect","useImperativeHandle","test","useReducerImpl","WrapJsx","jsx","props","i","v","Signal","value","call","apply","concat","slice","arguments","JsxPro","jsxRuntime","JsxDev","jsxRuntimeDev","React","createElement","jsxs","jsxDEV","defineProperties","prototype","$$typeof","configurable","_ref","data","ref","useSignal","useMemo","signal","useComputed","compute","$compute","computed","useSignalEffect","cb","callback"],"mappings":"maAyBA,IAYAA,EAZMC,EAAQ,GACRC,EAAgBC,OAAA,IAAW,iBAajC,SAASC,EAAkBC,GAE1B,GAAIL,EAAcA,IAElBA,EAAeK,GAAWA,EAAQC,GAClC,CA8MD,IAAQC,GAAG,EACPC,EAA4C,KAChDC,OAAOC,eAAeC,EAAeC,uBAAwB,UAAW,CACvEC,IAAG,WACF,OAAOL,CACP,EACDM,IAJuE,SAInEC,GACH,IAAIR,EAAJ,CAKA,IAAMS,EAAwBC,EAAkBT,GAC1CU,EAAqBD,EAAkBF,GAI7CP,EAAoBO,EACpB,GAwFF,SACCC,EACAE,GAEA,GA7EiC,EA8EhCF,GAvEDG,GAwECD,EAMA,OAAO,OAEPF,GAtF4B,EAsF5BA,GAtF4B,EAuF5BE,EAQA,OAAO,OACGA,GA7FmB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