@preact/signals-react 1.0.2 → 1.1.1

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,38 @@
1
1
  # @preact/signals-react
2
2
 
3
+ ## 1.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#221](https://github.com/preactjs/signals/pull/221) [`7e8d4c2`](https://github.com/preactjs/signals/commit/7e8d4c25dfdc7fa9434b6c2af4aa0e495b9fae55) Thanks [@marvinhagemeister](https://github.com/marvinhagemeister)! - Fix signal not updated in React production build
8
+
9
+ - Updated dependencies [[`4b73164`](https://github.com/preactjs/signals/commit/4b7316497aee03413f91e9f714cdcf9f553e39d9), [`57fd2e7`](https://github.com/preactjs/signals/commit/57fd2e723528a36cc5d4ebf09ba34178aa84c879), [`49756ae`](https://github.com/preactjs/signals/commit/49756aef28fe12c6ae6b801224bf5ae608ddf562)]:
10
+ - @preact/signals-core@1.2.1
11
+
12
+ ## 1.1.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#91](https://github.com/preactjs/signals/pull/91) [`fb74bb9`](https://github.com/preactjs/signals/commit/fb74bb9ce4e44192e1ee7d3d041274cc985db767) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - add the `useSignalEffect` hook
17
+
18
+ * [#183](https://github.com/preactjs/signals/pull/183) [`79ff1e7`](https://github.com/preactjs/signals/commit/79ff1e794dde9952db2d6d43b22cebfb2accc770) Thanks [@jviide](https://github.com/jviide)! - Add ability to run custom cleanup logic when an effect is disposed.
19
+
20
+ ```js
21
+ effect(() => {
22
+ console.log("This runs whenever a dependency changes");
23
+ return () => {
24
+ console.log("This runs when the effect is disposed");
25
+ });
26
+ });
27
+ ```
28
+
29
+ ### Patch Changes
30
+
31
+ - [#161](https://github.com/preactjs/signals/pull/161) [`6ac6923`](https://github.com/preactjs/signals/commit/6ac6923e5294f8a31ee1a009550b9891c3996cb4) Thanks [@jviide](https://github.com/jviide)! - Remove all usages of `Set`, `Map` and other allocation heavy objects in signals-core. This substaintially increases performance across all measurements.
32
+
33
+ - Updated dependencies [[`b4611cc`](https://github.com/preactjs/signals/commit/b4611cc9dee0ae09f4b378ba293c3203edc32be4), [`9802da5`](https://github.com/preactjs/signals/commit/9802da5274bb45c3cc28dda961b9b2d18535729a), [`6ac6923`](https://github.com/preactjs/signals/commit/6ac6923e5294f8a31ee1a009550b9891c3996cb4), [`79ff1e7`](https://github.com/preactjs/signals/commit/79ff1e794dde9952db2d6d43b22cebfb2accc770), [`3e31aab`](https://github.com/preactjs/signals/commit/3e31aabb812ddb0f7451deba38267f8384eff9d1)]:
34
+ - @preact/signals-core@1.2.0
35
+
3
36
  ## 1.0.2
4
37
 
5
38
  ### Patch Changes
package/dist/signals.d.ts CHANGED
@@ -2,3 +2,4 @@ import { signal, computed, batch, effect, Signal, type ReadonlySignal } from "@p
2
2
  export { signal, computed, batch, effect, Signal, type ReadonlySignal };
3
3
  export declare function useSignal<T>(value: T): Signal<T>;
4
4
  export declare function useComputed<T>(compute: () => T): ReadonlySignal<T>;
5
+ export declare function useSignalEffect(cb: () => void | (() => void)): void;
package/dist/signals.js CHANGED
@@ -1 +1 @@
1
- var r=require("react"),n=require("@preact/signals-core");function t(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var e,u=/*#__PURE__*/t(r),o=u.createElement;u.createElement=function(r,t){if("string"==typeof r&&t)for(var e in t){var u=t[e];"children"!==e&&u instanceof n.Signal&&(t[e]=u.value)}return o.apply(this,arguments)};var i=new WeakMap;function a(r){e&&e(!0,!0),e=r&&r._()}function c(r){var t=n.signal(void 0);return t._u=r,t}var f,v=o("a").$$typeof;Object.defineProperties(n.Signal.prototype,{$$typeof:{configurable:!0,value:v},type:{configurable:!0,value:function(r){return r.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});var s=null;Object.defineProperty(r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,"current",{get:function(){return s},set:function(r){(s=r)&&(f=s)}});var l,p=!1,g=function(){return{}};Object.defineProperty(r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return l},set:function(r){if(l=r,!p)if(f&&r&&!x(r)){p=!0;var n=r.useReducer(g,{})[1];p=!1;var t=i.get(f);t?t._u=n:(t=c(n),i.set(f,t)),a(t)}else a()}});var b=new Map;function x(r){var n=b.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/warnInvalidHookAccess/.test(r.useCallback);return b.set(r,t),t}exports.Signal=n.Signal,exports.batch=n.batch,exports.computed=n.computed,exports.effect=n.effect,exports.signal=n.signal,exports.useComputed=function(t){var e=r.useRef(t);return e.current=t,r.useMemo(function(){return n.computed(function(){return e.current()})},[])},exports.useSignal=function(t){return r.useMemo(function(){return n.signal(t)},[])};//# sourceMappingURL=signals.js.map
1
+ var r=require("react"),n=require("@preact/signals-core");function t(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var e,u=/*#__PURE__*/t(r),i=u.createElement;u.createElement=function(r,t){if("string"==typeof r&&t)for(var e in t){var u=t[e];if("children"!==e&&u instanceof n.Signal)t[e]=u.value}return i.apply(this,arguments)};var o=new WeakMap;function f(r){if(e)e();e=r&&r.S()}var a=i("a").$$typeof;Object.defineProperties(n.Signal.prototype,{$$typeof:{configurable:!0,value:a},type:{configurable:!0,value:function(r){return r.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});var c,v=!1,s=function(){return{}};Object.defineProperty(r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return c},set:function(r){c=r;if(!v)if(r&&!function(r){var n=p.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/Invalid/.test(r.useCallback);p.set(r,t);return t}(r)){v=!0;var t=r.useReducer(s,{})[1];v=!1;var e=o.get(t);if(!e){e=function(r){var t;n.effect(function(){t=this});t.c=r;return t}(t);o.set(t,e)}else e.c=t;f(e)}else f()}});var p=new Map;exports.Signal=n.Signal;exports.batch=n.batch;exports.computed=n.computed;exports.effect=n.effect;exports.signal=n.signal;exports.useComputed=function(t){var e=r.useRef(t);e.current=t;return r.useMemo(function(){return n.computed(function(){return e.current()})},[])};exports.useSignal=function(t){return r.useMemo(function(){return n.signal(t)},[])};exports.useSignalEffect=function(t){var e=r.useRef(t);e.current=t;r.useEffect(function(){return n.effect(function(){return e.current()})},[])};//# sourceMappingURL=signals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Updater, ReactOwner, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: ReturnType<Updater[\"_setCurrent\"]> | undefined;\nconst updaterForComponent = new WeakMap<ReactOwner, Updater>();\n\nfunction setCurrentUpdater(updater?: Updater) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate(true, true);\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._setCurrent();\n}\n\nfunction createUpdater(updater: () => void) {\n\tconst s = signal(undefined) as Updater;\n\ts._updater = updater;\n\treturn s;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current owner (roughly equiv to current vnode)\nlet lastOwner: ReactOwner | undefined;\nlet currentOwner: ReactOwner | null = null;\nObject.defineProperty(internals.ReactCurrentOwner, \"current\", {\n\tget() {\n\t\treturn currentOwner;\n\t},\n\tset(owner) {\n\t\tcurrentOwner = owner;\n\t\tif (currentOwner) lastOwner = currentOwner;\n\t},\n});\n\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (lastOwner && api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(lastOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(lastOwner, updater);\n\t\t\t} else {\n\t\t\t\tupdater._updater = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 ||\n\t\t/warnInvalidHookAccess/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n"],"names":["React","require","signalsCore","_interopDefaultLegacy","e","default","finishUpdate","React__default","createElement","type","props","i","v","Signal","value","apply","this","arguments","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_updater","lastOwner","$$typeof","Object","defineProperties","prototype","configurable","_ref","data","get","ref","currentOwner","defineProperty","internals","ReactCurrentOwner","set","owner","currentDispatcher","lock","ReactCurrentDispatcher","api","isInvalidHookAccessor","rerender","useReducer","UPDATE","updaterForComponent","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","exports","batch","computed","effect","useComputed","compute","$compute","useRef","current","useMemo","useSignal"],"mappings":"AAwBA,IAAAA,EAAAC,QAAA,SAAAC,EA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,EACDM,IAJkE,SAI9DK,GAEH,GADAH,EAAoBG,GAChBF,EACJ,GAAIjB,GAAamB,IAAQC,EAAsBD,GAAM,CAGpDF,GAAO,EACP,IAAcI,EAAGF,EAAIG,WAAWC,EAAQ,CAAA,GAAI,GAC5CN,GAAO,EAEP,IAAWxB,EAAG+B,EAAoBhB,IAAIR,GACjCP,EAIJA,EAAQM,GAAWsB,GAHnB5B,EAAUE,EAAc0B,GACxBG,EAAoBV,IAAId,EAAWP,IAIpCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAA0BiC,EAAG,IAAIC,IACjC,SAAAN,EAA+BD,GAC9B,IAAMQ,EAASF,EAAqBjB,IAAIW,GACxC,QAAerB,IAAX6B,EAAsB,SAE1B,IAAaC,EACZT,EAAIU,YAAYC,OAAS,GACzB,wBAAwBC,KAAKZ,EAAIU,aAElC,OADAJ,EAAqBX,IAAIK,EAAKS,GACvBA,CACP,CAUAI,QAAA9C,OAAAX,EAAAW,OAAA8C,QAAAC,MAAA1D,EAAA0D,MAAAD,QAAAE,SAAA3D,EAAA2D,SAAAF,QAAAG,OAAA5D,EAAA4D,OAAAH,QAAAnC,OAAAtB,EAAAsB,OAAAmC,QAAAI,qBAJ8BC,GAC9B,IAAcC,EAAGC,EAAMA,OAACF,GAExB,OADAC,EAASE,QAAUH,EACZI,UAAQ,WAAA,OAAcP,EAAAA,SAAI,kBAAcI,EAACE,SAAf,EAAlB,EAA6C,GAC5D,EAAAR,QAAAU,UAReA,SAAavD,GAC5B,OAAcsD,EAAAA,QAAC,WAAM5C,OAAAA,EAAAA,OAAUV,EAAhB,EAAwB,GACvC"}
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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Effect, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: (() => void) | undefined;\nconst updaterForComponent = new WeakMap<() => void, Effect>();\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\nfunction createUpdater(update: () => void) {\n\tlet updater!: Effect;\n\teffect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = update;\n\treturn updater;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(rerender);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(rerender, updater);\n\t\t\t} else {\n\t\t\t\tupdater._callback = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 || /Invalid/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, []);\n}\n"],"names":["React","require","signalsCore","_interopDefaultLegacy","e","default","React__default","createElement","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","updater","finishUpdate","_start","$$typeof","Object","defineProperties","prototype","configurable","_ref","data","get","ref","currentDispatcher","lock","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","cached","invalidHookAccessors","undefined","invalid","useCallback","length","test","isInvalidHookAccessor","rerender","useReducer","update","effect","_callback","createUpdater","setCurrentUpdater","Map","exports","batch","computed","signal","useComputed","compute","useRef","$compute","current","useMemo","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"AAyBA,IAAAA,EAAAC,QAAA,SAAAC,EAAAD,QAAA,wBAAA,SAAAE,EAAAC,GAAA,OAAAA,GAAA,iBAAAA,GAAA,YAAAA,EAAAA,EAAAC,QAAAD,CAAA,CAAA,MAAAE,eAAAH,EAAAH,GAAmBO,EAAGP,EAAMO,cAE5BP,EAAMO,cAAgB,SAAUC,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACd,GAAU,aAANA,GAAoBC,aAAaC,EAAAA,OAEpCH,EAAMC,GAAKC,EAAEE,KAEd,CAGF,OAAON,EAAcO,MAAMC,KAAMC,UACjC,EAkBD,IAAyBC,EAAG,IAAIC,QAEhC,WAA2BC,GAE1B,GAAIC,EAAcA,IAElBA,EAAeD,GAAWA,EAAQE,GAClC,CAoBD,IAAcC,EAAGf,EAAc,KAAKe,SACpCC,OAAOC,iBAAiBZ,SAAOa,UAAW,CACzCH,SAAU,CAAEI,cAAc,EAAMb,MAAOS,GACvCd,KAAM,CAAEkB,cAAc,EAAMb,MAT7B,SAAAc,GACC,OADeC,EAAAA,KACHf,KACZ,GAQAJ,MAAO,CACN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6C,GAC5D,EAWAR,QAAAU,UAnBK,SAAuBpD,GAC5B,OAAcmD,EAAAA,QAAC,kBAAYN,EAAAA,OAAI7C,EAAhB,EAAwB,GACvC,EAiBA0C,QAAAW,gBATK,SAA0BC,GAC/B,IAAMC,EAAWP,EAAMA,OAACM,GACxBC,EAASL,QAAUI,EAEnBE,EAAAA,UAAU,WACT,OAAanB,EAAAA,OAAC,WACb,OAAekB,EAACL,SAChB,EACD,EAAE,GACH"}
@@ -1 +1 @@
1
- !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","react","@preact/signals-core"],e):e((n||self).reactSignals={},n.react,n.signalsCore)}(this,function(n,e,r){function t(n){return n&&"object"==typeof n&&"default"in n?n.default:n}var u,i=/*#__PURE__*/t(e),o=i.createElement;i.createElement=function(n,e){if("string"==typeof n&&e)for(var t in e){var u=e[t];"children"!==t&&u instanceof r.Signal&&(e[t]=u.value)}return o.apply(this,arguments)};var f=new WeakMap;function c(n){u&&u(!0,!0),u=n&&n._()}function a(n){var e=r.signal(void 0);return e._u=n,e}var l,s=o("a").$$typeof;Object.defineProperties(r.Signal.prototype,{$$typeof:{configurable:!0,value:s},type:{configurable:!0,value:function(n){return n.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});var v=null;Object.defineProperty(e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,"current",{get:function(){return v},set:function(n){(v=n)&&(l=v)}});var p,d=!1,g=function(){return{}};Object.defineProperty(e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return p},set:function(n){if(p=n,!d)if(l&&n&&!y(n)){d=!0;var e=n.useReducer(g,{})[1];d=!1;var r=f.get(l);r?r._u=e:(r=a(e),f.set(l,r)),c(r)}else c()}});var b=new Map;function y(n){var e=b.get(n);if(void 0!==e)return e;var r=n.useCallback.length<2||/warnInvalidHookAccess/.test(n.useCallback);return b.set(n,r),r}n.Signal=r.Signal,n.batch=r.batch,n.computed=r.computed,n.effect=r.effect,n.signal=r.signal,n.useComputed=function(n){var t=e.useRef(n);return t.current=n,e.useMemo(function(){return r.computed(function(){return t.current()})},[])},n.useSignal=function(n){return e.useMemo(function(){return r.signal(n)},[])}});//# sourceMappingURL=signals.min.js.map
1
+ !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","react","@preact/signals-core"],e):e((n||self).reactSignals={},n.react,n.signalsCore)}(this,function(n,e,r){function t(n){return n&&"object"==typeof n&&"default"in n?n.default:n}var i,u=/*#__PURE__*/t(e),f=u.createElement;u.createElement=function(n,e){if("string"==typeof n&&e)for(var t in e){var i=e[t];if("children"!==t&&i instanceof r.Signal)e[t]=i.value}return f.apply(this,arguments)};var o=new WeakMap;function c(n){if(i)i();i=n&&n.S()}var a=f("a").$$typeof;Object.defineProperties(r.Signal.prototype,{$$typeof:{configurable:!0,value:a},type:{configurable:!0,value:function(n){return n.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});var l,s=!1,v=function(){return{}};Object.defineProperty(e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return l},set:function(n){l=n;if(!s)if(n&&!function(n){var e=p.get(n);if(void 0!==e)return e;var r=n.useCallback.length<2||/Invalid/.test(n.useCallback);p.set(n,r);return r}(n)){s=!0;var e=n.useReducer(v,{})[1];s=!1;var t=o.get(e);if(!t){t=function(n){var e;r.effect(function(){e=this});e.c=n;return e}(e);o.set(e,t)}else t.c=e;c(t)}else c()}});var p=new Map;n.Signal=r.Signal;n.batch=r.batch;n.computed=r.computed;n.effect=r.effect;n.signal=r.signal;n.useComputed=function(n){var t=e.useRef(n);t.current=n;return e.useMemo(function(){return r.computed(function(){return t.current()})},[])};n.useSignal=function(n){return e.useMemo(function(){return r.signal(n)},[])};n.useSignalEffect=function(n){var t=e.useRef(n);t.current=n;e.useEffect(function(){return r.effect(function(){return t.current()})},[])}});//# 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\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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Updater, ReactOwner, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: ReturnType<Updater[\"_setCurrent\"]> | undefined;\nconst updaterForComponent = new WeakMap<ReactOwner, Updater>();\n\nfunction setCurrentUpdater(updater?: Updater) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate(true, true);\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._setCurrent();\n}\n\nfunction createUpdater(updater: () => void) {\n\tconst s = signal(undefined) as Updater;\n\ts._updater = updater;\n\treturn s;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current owner (roughly equiv to current vnode)\nlet lastOwner: ReactOwner | undefined;\nlet currentOwner: ReactOwner | null = null;\nObject.defineProperty(internals.ReactCurrentOwner, \"current\", {\n\tget() {\n\t\treturn currentOwner;\n\t},\n\tset(owner) {\n\t\tcurrentOwner = owner;\n\t\tif (currentOwner) lastOwner = currentOwner;\n\t},\n});\n\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (lastOwner && api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(lastOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(lastOwner, updater);\n\t\t\t} else {\n\t\t\t\tupdater._updater = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 ||\n\t\t/warnInvalidHookAccess/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n"],"names":["g","f","exports","module","require","define","amd","globalThis","self","reactSignals","react","signalsCore","this","React","_interopDefaultLegacy","e","default","finishUpdate","React__default","createElement","type","props","i","v","Signal","value","apply","arguments","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_updater","lastOwner","$$typeof","Object","defineProperties","prototype","configurable","_ref","data","get","ref","currentOwner","defineProperty","internals","ReactCurrentOwner","set","owner","currentDispatcher","lock","ReactCurrentDispatcher","api","isInvalidHookAccessor","rerender","useReducer","UPDATE","updaterForComponent","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","batch","computed","effect","useComputed","compute","$compute","useRef","current","useMemo","useSignal"],"mappings":"CAwBA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,QAAAE,QAAA,SAAAA,QAAA,yBAAA,mBAAAC,QAAAA,OAAAC,IAAAD,OAAA,CAAA,UAAA,QAAA,wBAAAJ,GAAAA,GAAAD,EAAA,oBAAAO,WAAAA,WAAAP,GAAAQ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AAP,EAEff,OAAOS,eAAeC,EAAAA,mDAAUM,uBAAwB,UAAW,CAClEV,IADkE,WAEjE,QACA,EACDM,IAJkE,SAI9DK,GAEH,GADAH,EAAoBG,GAChBF,EACJ,GAAIjB,GAAamB,IAAQC,EAAsBD,GAAM,CAGpDF,GAAO,EACP,IAAcI,EAAGF,EAAIG,WAAWC,EAAQ,CAAA,GAAI,GAC5CN,GAAO,EAEP,IAAWxB,EAAG+B,EAAoBhB,IAAIR,GACjCP,EAIJA,EAAQM,GAAWsB,GAHnB5B,EAAUE,EAAc0B,GACxBG,EAAoBV,IAAId,EAAWP,IAIpCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAA0BiC,EAAG,IAAIC,IACjC,SAAAN,EAA+BD,GAC9B,IAAMQ,EAASF,EAAqBjB,IAAIW,GACxC,QAAerB,IAAX6B,EAAsB,SAE1B,IAAaC,EACZT,EAAIU,YAAYC,OAAS,GACzB,wBAAwBC,KAAKZ,EAAIU,aAElC,OADAJ,EAAqBX,IAAIK,EAAKS,GACvBA,CACP,CAUA/D,EAAAsB,OAAAb,EAAAa,OAAAtB,EAAAmE,MAAA1D,EAAA0D,MAAAnE,EAAAoE,SAAA3D,EAAA2D,SAAApE,EAAAqE,OAAA5D,EAAA4D,OAAArE,EAAAgC,OAAAvB,EAAAuB,OAAAhC,EAAAsE,qBAJ8BC,GAC9B,IAAcC,EAAGC,EAAMA,OAACF,GAExB,OADAC,EAASE,QAAUH,EACZI,UAAQ,WAAA,OAAcP,EAAAA,SAAI,kBAAcI,EAACE,SAAf,EAAlB,EAA6C,GAC5D,EAAA1E,EAAA4E,UAReA,SAAarD,GAC5B,OAAcoD,EAAAA,QAAC,WAAM3C,OAAAA,EAAAA,OAAUT,EAAhB,EAAwB,GACvC,CAMA"}
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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Effect, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: (() => void) | undefined;\nconst updaterForComponent = new WeakMap<() => void, Effect>();\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\nfunction createUpdater(update: () => void) {\n\tlet updater!: Effect;\n\teffect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = update;\n\treturn updater;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(rerender);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(rerender, updater);\n\t\t\t} else {\n\t\t\t\tupdater._callback = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 || /Invalid/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, []);\n}\n"],"names":["g","f","exports","module","require","define","amd","globalThis","self","reactSignals","react","signalsCore","this","React","_interopDefaultLegacy","e","default","React__default","createElement","type","props","i","v","Signal","value","apply","arguments","updaterForComponent","WeakMap","updater","finishUpdate","_start","$$typeof","Object","defineProperties","prototype","configurable","_ref","data","get","ref","currentDispatcher","lock","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","cached","invalidHookAccessors","undefined","invalid","useCallback","length","test","isInvalidHookAccessor","rerender","useReducer","update","effect","_callback","createUpdater","setCurrentUpdater","Map","batch","computed","signal","useComputed","compute","useRef","$compute","current","useMemo","useSignal","useSignalEffect","cb","callback","useEffect"],"mappings":"CAyBA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,QAAAE,QAAA,SAAAA,QAAA,yBAAA,mBAAAC,QAAAA,OAAAC,IAAAD,OAAA,CAAA,UAAA,QAAA,wBAAAJ,GAAAA,GAAAD,EAAA,oBAAAO,WAAAA,WAAAP,GAAAQ,MAAAC,aAAA,CAAA,EAAAT,EAAAU,MAAAV,EAAAW,YAAA,CAAA,CAAAC,KAAA,SAAAV,EAAAW,EAAAF,GAAA,SAAAG,EAAAC,GAAA,OAAAA,GAAA,iBAAAA,GAAA,YAAAA,EAAAA,EAAAC,QAAAD,CAAA,CAAA,MAAAE,eAAAH,EAAAD,GAAmBK,EAAGL,EAAMK,cAE5BL,EAAMK,cAAgB,SAAUC,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACd,GAAU,aAANA,GAAoBC,aAAaC,EAAAA,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C,MACAA,EAAQgC,EAAYJ,EAErBM,EAAkBlC,EAClB,MACAkC,GAED,IAKF,MAA6B,IAA7BC,IA8BC9D,EAAAqB,OAAAZ,EAAAY,OAAArB,EAAA+D,MAAAtD,EAAAsD,MAAA/D,EAAAgE,SAAAvD,EAAAuD,SAAAhE,EAAA0D,OAAAjD,EAAAiD,OAAA1D,EAAAiE,OAAAxD,EAAAwD,OAAAjE,EAAAkE,YAfK,SAAyBC,GAC9B,MAAiBC,EAAAA,OAAOD,GACxBE,EAASC,QAAUH,EACnB,OAAOI,EAAOA,QAAC,WAAA,kBAAkB,WAAA,OAAcF,EAACC,SAAf,EAAlB,EAA6C,GAC5D,EAWAtE,EAAAwE,UAnBK,SAAuBlD,GAC5B,OAAciD,EAAAA,QAAC,kBAAYN,EAAAA,OAAI3C,EAAhB,EAAwB,GACvC,EAiBAtB,EAAAyE,gBATK,SAA0BC,GAC/B,IAAMC,EAAWP,EAAMA,OAACM,GACxBC,EAASL,QAAUI,EAEnBE,EAAAA,UAAU,WACT,OAAalB,EAAAA,OAAC,WACb,OAAeiB,EAACL,SAChB,EACD,EAAE,GACH,CAAA"}
package/dist/signals.mjs CHANGED
@@ -1 +1 @@
1
- import t,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as e,useMemo as n,useRef as r}from"react";import{Signal as o,signal as c,computed as i}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";const u=t.createElement;let a;t.createElement=function(t,e){if("string"==typeof t&&e)for(let t in e){let n=e[t];"children"!==t&&n instanceof o&&(e[t]=n.value)}return u.apply(this,arguments)};const l=new WeakMap;function f(t){a&&a(!0,!0),a=t&&t._()}function s(t){const e=c(void 0);return e._u=t,e}const p=u("a").$$typeof;let g;Object.defineProperties(o.prototype,{$$typeof:{configurable:!0,value:p},type:{configurable:!0,value:function({data:t}){return t.value}},props:{configurable:!0,get(){return{data:this}}},ref:{configurable:!0,value:null}});let b=null;Object.defineProperty(e.ReactCurrentOwner,"current",{get:()=>b,set(t){b=t,b&&(g=b)}});let d=!1;const m=()=>({});let v;Object.defineProperty(e.ReactCurrentDispatcher,"current",{get:()=>v,set(t){if(v=t,!d)if(g&&t&&!j(t)){d=!0;const e=t.useReducer(m,{})[1];d=!1;let n=l.get(g);n?n._u=e:(n=s(e),l.set(g,n)),f(n)}else f()}});const h=new Map;function j(t){const e=h.get(t);if(void 0!==e)return e;const n=t.useCallback.length<2||/warnInvalidHookAccess/.test(t.useCallback);return h.set(t,n),n}function w(t){return n(()=>c(t),[])}function y(t){const e=r(t);return e.current=t,n(()=>i(()=>e.current()),[])}export{y as useComputed,w as useSignal};//# sourceMappingURL=signals.mjs.map
1
+ import t,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as n,useMemo as e,useRef as o,useEffect as r}from"react";import{Signal as c,effect as i,signal as f,computed as u}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";const a=t.createElement;t.createElement=function(t,n){if("string"==typeof t&&n)for(let t in n){let e=n[t];if("children"!==t&&e instanceof c)n[t]=e.value}return a.apply(this,arguments)};let l;const s=new WeakMap;function p(t){if(l)l();l=t&&t.S()}const g=a("a").$$typeof;Object.defineProperties(c.prototype,{$$typeof:{configurable:!0,value:g},type:{configurable:!0,value:function({data:t}){return t.value}},props:{configurable:!0,get(){return{data:this}}},ref:{configurable:!0,value:null}});let b=!1;const d=()=>({});let m;Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:()=>m,set(t){m=t;if(!b)if(t&&!function(t){const n=h.get(t);if(void 0!==n)return n;const e=t.useCallback.length<2||/Invalid/.test(t.useCallback);h.set(t,e);return e}(t)){b=!0;const n=t.useReducer(d,{})[1];b=!1;let e=s.get(n);if(!e){e=function(t){let n;i(function(){n=this});n.c=t;return n}(n);s.set(n,e)}else e.c=n;p(e)}else p()}});const h=new Map;function v(t){return e(()=>f(t),[])}function y(t){const n=o(t);n.current=t;return e(()=>u(()=>n.current()),[])}function j(t){const n=o(t);n.current=t;r(()=>i(()=>n.current()),[])}export{y as useComputed,v as useSignal,j as useSignalEffect};//# sourceMappingURL=signals.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import {\n\tuseRef,\n\tuseMemo,\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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Updater, ReactOwner, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: ReturnType<Updater[\"_setCurrent\"]> | undefined;\nconst updaterForComponent = new WeakMap<ReactOwner, Updater>();\n\nfunction setCurrentUpdater(updater?: Updater) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate(true, true);\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._setCurrent();\n}\n\nfunction createUpdater(updater: () => void) {\n\tconst s = signal(undefined) as Updater;\n\ts._updater = updater;\n\treturn s;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current owner (roughly equiv to current vnode)\nlet lastOwner: ReactOwner | undefined;\nlet currentOwner: ReactOwner | null = null;\nObject.defineProperty(internals.ReactCurrentOwner, \"current\", {\n\tget() {\n\t\treturn currentOwner;\n\t},\n\tset(owner) {\n\t\tcurrentOwner = owner;\n\t\tif (currentOwner) lastOwner = currentOwner;\n\t},\n});\n\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (lastOwner && api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(lastOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(lastOwner, updater);\n\t\t\t} else {\n\t\t\t\tupdater._updater = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 ||\n\t\t/warnInvalidHookAccess/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n"],"names":["React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","useMemo","useRef","Signal","signal","computed","batch","effect","createElement","finishUpdate","type","props","i","v","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","undefined","_updater","$$typeof","lastOwner","Object","defineProperties","prototype","configurable","data","get","ref","defineProperty","internals","ReactCurrentOwner","currentOwner","set","owner","lock","UPDATE","currentDispatcher","ReactCurrentDispatcher","api","isInvalidHookAccessor","rerender","useReducer","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","useSignal","useComputed","compute","$compute","current"],"mappings":"OAwBAA,yDAAAC,aAAAC,YAAAC,MAAA,yBAAAC,YAAAC,cAAAC,MAAA,8BAAAF,OAAAG,MAAAD,SAAAE,OAAAH,WAAA,uBAAA,MAAmBI,EAAGT,EAAMS,cA+B5B,IAAIC,EA7BJV,EAAMS,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAATD,GAAqBC,EAC/B,IAAK,IAAIC,KAAKD,EAAO,CACpB,IAAIE,EAAIF,EAAMC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,EAAG,IAAIC,IACjC,SAAAJ,EAA+BD,GAC9B,MAAMM,EAASF,EAAqBhB,IAAIY,GACxC,QAAerB,IAAX2B,EAAsB,OAAOA,EAEjC,MAAaC,EACZP,EAAIQ,YAAYC,OAAS,GACzB,wBAAwBC,KAAKV,EAAIQ,aAElC,OADAJ,EAAqBV,IAAIM,EAAKO,GACvBA,CACP,UAEKI,EAAuB3C,GAC5B,OAAcb,EAAC,IAAMG,EAAUU,GAAQ,GACvC,CAEK,SAAA4C,EAAyBC,GAC9B,MAAcC,EAAG1D,EAAOyD,GAExB,OADAC,EAASC,QAAUF,EACZ1D,EAAQ,IAAMI,EAAY,IAAMuD,EAASC,WAAY,GAC5D,QAAAH,iBAAAD"}
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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Effect, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: (() => void) | undefined;\nconst updaterForComponent = new WeakMap<() => void, Effect>();\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\nfunction createUpdater(update: () => void) {\n\tlet updater!: Effect;\n\teffect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = update;\n\treturn updater;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(rerender);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(rerender, updater);\n\t\t\t} else {\n\t\t\t\tupdater._callback = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 || /Invalid/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, []);\n}\n"],"names":["createElement","React","type","props","i","v","Signal","value","apply","this","arguments","finishUpdate","updaterForComponent","WeakMap","setCurrentUpdater","updater","_start","$$typeof","Object","defineProperties","prototype","configurable","data","get","ref","UPDATE","currentDispatcher","defineProperty","internals","ReactCurrentDispatcher","set","api","lock","cached","invalidHookAccessors","undefined","invalid","useCallback","length","test","isInvalidHookAccessor","useReducer","rerender","update","effect","_callback","createUpdater","Map","useSignal","signal","useComputed","compute","$compute","useRef","current","useMemo","computed","useSignalEffect","cb","callback","useEffect"],"mappings":"gRAyBA,MAAmBA,EAAGC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAATD,GAAqBC,EAC/B,IAAK,IAA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ca+B,CAAcJ,GACxB9B,EAAoBkB,IAAIY,EAAU3B,EAClC,MACAA,EAAQ8B,EAAYH,EAErB5B,EAAkBC,EAClB,MACAD,GAED,IAKF,MAAMoB,EAAuB,IAA7Ba,IAWM,SAAAC,EAAuBzC,GAC5B,SAAe,IAAM0C,EAAU1C,GAAQ,GACvC,CAEe2C,SAAAA,EAAeC,GAC9B,MAAcC,EAAGC,EAAOF,GACxBC,EAASE,QAAUH,EACnB,OAAcI,EAAC,IAAMC,EAAY,IAAMJ,EAASE,WAAY,GAC5D,CAEK,SAAAG,EAA0BC,GAC/B,MAAMC,EAAWN,EAAOK,GACxBC,EAASL,QAAUI,EAEnBE,EAAU,IACIhB,EAAC,IACEe,EAACL,WAEf,GACH,QAAAJ,iBAAAF,eAAAS"}
@@ -1 +1 @@
1
- import r,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as n,useMemo as t,useRef as e}from"react";import{Signal as u,signal as i,computed as o}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";var a,c=r.createElement;r.createElement=function(r,n){if("string"==typeof r&&n)for(var t in n){var e=n[t];"children"!==t&&e instanceof u&&(n[t]=e.value)}return c.apply(this,arguments)};var f=new WeakMap;function v(r){a&&a(!0,!0),a=r&&r._()}function l(r){var n=i(void 0);return n._u=r,n}var s,p=c("a").$$typeof;Object.defineProperties(u.prototype,{$$typeof:{configurable:!0,value:p},type:{configurable:!0,value:function(r){return r.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});var g=null;Object.defineProperty(n.ReactCurrentOwner,"current",{get:function(){return g},set:function(r){(g=r)&&(s=g)}});var b,d=!1,m=function(){return{}};Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:function(){return b},set:function(r){if(b=r,!d)if(s&&r&&!j(r)){d=!0;var n=r.useReducer(m,{})[1];d=!1;var t=f.get(s);t?t._u=n:(t=l(n),f.set(s,t)),v(t)}else v()}});var h=new Map;function j(r){var n=h.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/warnInvalidHookAccess/.test(r.useCallback);return h.set(r,t),t}function w(r){return t(function(){return i(r)},[])}function y(r){var n=e(r);return n.current=r,t(function(){return o(function(){return n.current()})},[])}export{y as useComputed,w as useSignal};//# sourceMappingURL=signals.module.js.map
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{Signal as u,effect as f,signal as o,computed as a}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";var c,v=n.createElement;n.createElement=function(n,r){if("string"==typeof n&&r)for(var t in r){var e=r[t];if("children"!==t&&e instanceof u)r[t]=e.value}return v.apply(this,arguments)};var l=new WeakMap;function p(n){if(c)c();c=n&&n.S()}var s=v("a").$$typeof;Object.defineProperties(u.prototype,{$$typeof:{configurable:!0,value:s},type:{configurable:!0,value:function(n){return n.data.value}},props:{configurable:!0,get:function(){return{data:this}}},ref:{configurable:!0,value:null}});var g,b=!1,m=function(){return{}};Object.defineProperty(r.ReactCurrentDispatcher,"current",{get:function(){return g},set:function(n){g=n;if(!b)if(n&&!function(n){var r=d.get(n);if(void 0!==r)return r;var t=n.useCallback.length<2||/Invalid/.test(n.useCallback);d.set(n,t);return t}(n)){b=!0;var r=n.useReducer(m,{})[1];b=!1;var t=l.get(r);if(!t){t=function(n){var r;f(function(){r=this});r.c=n;return r}(r);l.set(r,t)}else t.c=r;p(t)}else p()}});var d=new Map;function h(n){return t(function(){return o(n)},[])}function y(n){var r=e(n);r.current=n;return t(function(){return a(function(){return r.current()})},[])}function j(n){var r=e(n);r.current=n;i(function(){return f(function(){return r.current()})},[])}export{y as useComputed,h as useSignal,j as 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\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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Updater, ReactOwner, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: ReturnType<Updater[\"_setCurrent\"]> | undefined;\nconst updaterForComponent = new WeakMap<ReactOwner, Updater>();\n\nfunction setCurrentUpdater(updater?: Updater) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate(true, true);\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._setCurrent();\n}\n\nfunction createUpdater(updater: () => void) {\n\tconst s = signal(undefined) as Updater;\n\ts._updater = updater;\n\treturn s;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current owner (roughly equiv to current vnode)\nlet lastOwner: ReactOwner | undefined;\nlet currentOwner: ReactOwner | null = null;\nObject.defineProperty(internals.ReactCurrentOwner, \"current\", {\n\tget() {\n\t\treturn currentOwner;\n\t},\n\tset(owner) {\n\t\tcurrentOwner = owner;\n\t\tif (currentOwner) lastOwner = currentOwner;\n\t},\n});\n\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (lastOwner && api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(lastOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(lastOwner, updater);\n\t\t\t} else {\n\t\t\t\tupdater._updater = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 ||\n\t\t/warnInvalidHookAccess/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n"],"names":["React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","useMemo","useRef","Signal","signal","computed","batch","effect","finishUpdate","createElement","type","props","i","v","value","apply","this","arguments","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","undefined","_updater","lastOwner","$$typeof","Object","defineProperties","prototype","configurable","_ref","data","get","ref","currentOwner","defineProperty","internals","ReactCurrentOwner","set","owner","currentDispatcher","lock","ReactCurrentDispatcher","api","isInvalidHookAccessor","rerender","useReducer","UPDATE","updaterForComponent","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","useSignal","useComputed","compute","$compute","current"],"mappings":"OAwBAA,yDAAAC,aAAAC,YAAAC,MAAA,yBAAAC,YAAAC,cAAAC,MAAA,8BAAAF,OAAAG,MAAAD,SAAAE,OAAAH,WAAA,uBAAA,IA+BII,EA/BeC,EAAGV,EAAMU,cAE5BV,EAAMU,cAAgB,SAAUC,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACJ,aAANA,GAAoBC,aAAaV,IAEpCQ,EAAMC,GAAKC,EAAEC,MAEd,CAGF,OAAoBL,EAACM,MAAMC,KAAMC,UACjC,EAkBD,MAA4B,IAA5BC,QAEA,SAASC,EAAkBC,GAEtBZ,GAAcA,GAAa,GAAM,GAErCA,EAAeY,GAAWA,EAAQC,GAClC,CAED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,IAAIK,EAAKS,GACvBA,CACP,CAEeI,SAAAA,EAAa5C,GAC5B,OAAcb,EAAC,WAAMG,OAAAA,EAAUU,EAAhB,EAAwB,GACvC,UAEK6C,EAAyBC,GAC9B,IAAcC,EAAG3D,EAAO0D,GAExB,OADAC,EAASC,QAAUF,EACZ3D,EAAQ,WAAA,OAAcI,EAAI,kBAAcwD,EAACC,SAAf,EAAlB,EAA6C,GAC5D,QAAAH,iBAAAD"}
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 internals,\n} from \"react\";\nimport React from \"react\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n} from \"@preact/signals-core\";\nimport { Effect, ReactDispatcher } from \"./internal\";\n\nexport { signal, computed, batch, effect, Signal, type ReadonlySignal };\n\n/**\n * Install a middleware into React.createElement to replace any Signals in props with their value.\n * @todo this likely needs to be duplicated for jsx()...\n */\nconst createElement = React.createElement;\n// @ts-ignore-next-line\nReact.createElement = function (type, props) {\n\tif (typeof type === \"string\" && props) {\n\t\tfor (let i in props) {\n\t\t\tlet v = props[i];\n\t\t\tif (i !== \"children\" && v instanceof Signal) {\n\t\t\t\t// createPropUpdater(props, i, v);\n\t\t\t\tprops[i] = v.value;\n\t\t\t}\n\t\t}\n\t}\n\t// @ts-ignore-next-line\n\treturn createElement.apply(this, arguments);\n};\n\n/*\n// This breaks React's controlled components implementation\nfunction createPropUpdater(props: any, prop: string, signal: Signal) {\n\tlet ref = props.ref;\n\tif (!ref) ref = props.ref = React.createRef();\n\teffect(() => {\n\t\tif (props) props[prop] = signal.value;\n\t\tlet el = ref.current;\n\t\tif (!el) return; // unsubscribe\n\t\t(el as any)[prop] = signal.value;\n\t});\n\tprops = null;\n}\n*/\n\nlet finishUpdate: (() => void) | undefined;\nconst updaterForComponent = new WeakMap<() => void, Effect>();\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\nfunction createUpdater(update: () => void) {\n\tlet updater!: Effect;\n\teffect(function (this: Effect) {\n\t\tupdater = this;\n\t});\n\tupdater._callback = update;\n\treturn updater;\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.\n//@ts-ignore-next-line\nconst $$typeof = createElement(\"a\").$$typeof;\nObject.defineProperties(Signal.prototype, {\n\t$$typeof: { configurable: true, value: $$typeof },\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\n// Track the current dispatcher (roughly equiv to current component impl)\nlet lock = false;\nconst UPDATE = () => ({});\nlet currentDispatcher: ReactDispatcher;\nObject.defineProperty(internals.ReactCurrentDispatcher, \"current\", {\n\tget() {\n\t\treturn currentDispatcher;\n\t},\n\tset(api) {\n\t\tcurrentDispatcher = api;\n\t\tif (lock) return;\n\t\tif (api && !isInvalidHookAccessor(api)) {\n\t\t\t// prevent re-injecting useReducer when the Dispatcher\n\t\t\t// context changes to run the reducer callback:\n\t\t\tlock = true;\n\t\t\tconst rerender = api.useReducer(UPDATE, {})[1];\n\t\t\tlock = false;\n\n\t\t\tlet updater = updaterForComponent.get(rerender);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(rerender, updater);\n\t\t\t} else {\n\t\t\t\tupdater._callback = rerender;\n\t\t\t}\n\t\t\tsetCurrentUpdater(updater);\n\t\t} else {\n\t\t\tsetCurrentUpdater();\n\t\t}\n\t},\n});\n\n// We inject a useReducer into every function component via CurrentDispatcher.\n// This prevents injecting into anything other than a function component render.\nconst invalidHookAccessors = new Map();\nfunction isInvalidHookAccessor(api: ReactDispatcher) {\n\tconst cached = invalidHookAccessors.get(api);\n\tif (cached !== undefined) return cached;\n\t// we only want the real implementation, not the warning ones\n\tconst invalid =\n\t\tapi.useCallback.length < 2 || /Invalid/.test(api.useCallback as any);\n\tinvalidHookAccessors.set(api, invalid);\n\treturn invalid;\n}\n\nexport function useSignal<T>(value: T) {\n\treturn useMemo(() => signal<T>(value), []);\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()), []);\n}\n\nexport function useSignalEffect(cb: () => void | (() => void)) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(() => {\n\t\t\treturn callback.current();\n\t\t});\n\t}, []);\n}\n"],"names":["React","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","useMemo","useRef","useEffect","Signal","effect","signal","computed","batch","createElement","type","props","i","v","value","apply","this","arguments","updaterForComponent","WeakMap","updater","finishUpdate","_start","$$typeof","Object","defineProperties","prototype","configurable","_ref","data","get","ref","currentDispatcher","lock","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","cached","invalidHookAccessors","undefined","invalid","useCallback","length","test","isInvalidHookAccessor","rerender","useReducer","update","_callback","createUpdater","setCurrentUpdater","Map","useSignal","useComputed","compute","$compute","current","useSignalEffect","cb","callback"],"mappings":"OAyBAA,yDAAAC,aAAAC,YAAAC,eAAAC,MAAA,yBAAAC,YAAAC,YAAAC,cAAAC,MAAA,8BAAAH,OAAAI,MAAAD,SAAAF,OAAAC,WAAA,uBAAA,MAAmBG,EAAGV,EAAMU,cAE5BV,EAAMU,cAAgB,SAAUC,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,E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ACpB,OAAO9B,CACP,CA4CagC,CAAcJ,GACxB9B,EAAoBoB,IAAIU,EAAU5B,EAClC,MACAA,EAAQ+B,EAAYH,EAErBK,EAAkBjC,EAClB,MACAiC,GAED,IAKF,MAA6B,IAA7BC,IAWM,SAAAC,EAAuBzC,GAC5B,OAAcb,EAAC,kBAAYK,EAAIQ,EAAhB,EAAwB,GACvC,CAEK,SAAA0C,EAAyBC,GAC9B,MAAiBvD,EAAOuD,GACxBC,EAASC,QAAUF,EACnB,OAAOxD,EAAQ,WAAA,SAAkB,WAAA,OAAcyD,EAACC,SAAf,EAAlB,EAA6C,GAC5D,CAEK,SAAAC,EAA0BC,GAC/B,IAAMC,EAAW5D,EAAO2D,GACxBC,EAASH,QAAUE,EAEnB1D,EAAU,WACT,OAAaE,EAAC,WACb,OAAeyD,EAACH,SAChB,EACD,EAAE,GACH,QAAAH,iBAAAD,eAAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preact/signals-react",
3
- "version": "1.0.2",
3
+ "version": "1.1.1",
4
4
  "license": "MIT",
5
5
  "description": "",
6
6
  "keywords": [],
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "mangle": "../../mangle.json",
37
37
  "dependencies": {
38
- "@preact/signals-core": "^1.1.1"
38
+ "@preact/signals-core": "^1.2.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "react": "17.x || 18.x"
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  useRef,
3
3
  useMemo,
4
+ useEffect,
4
5
  // @ts-ignore-next-line
5
6
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
7
  __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as internals,
@@ -14,7 +15,7 @@ import {
14
15
  Signal,
15
16
  type ReadonlySignal,
16
17
  } from "@preact/signals-core";
17
- import { Updater, ReactOwner, ReactDispatcher } from "./internal";
18
+ import { Effect, ReactDispatcher } from "./internal";
18
19
 
19
20
  export { signal, computed, batch, effect, Signal, type ReadonlySignal };
20
21
 
@@ -53,20 +54,23 @@ function createPropUpdater(props: any, prop: string, signal: Signal) {
53
54
  }
54
55
  */
55
56
 
56
- let finishUpdate: ReturnType<Updater["_setCurrent"]> | undefined;
57
- const updaterForComponent = new WeakMap<ReactOwner, Updater>();
57
+ let finishUpdate: (() => void) | undefined;
58
+ const updaterForComponent = new WeakMap<() => void, Effect>();
58
59
 
59
- function setCurrentUpdater(updater?: Updater) {
60
+ function setCurrentUpdater(updater?: Effect) {
60
61
  // end tracking for the current update:
61
- if (finishUpdate) finishUpdate(true, true);
62
+ if (finishUpdate) finishUpdate();
62
63
  // start tracking the new update:
63
- finishUpdate = updater && updater._setCurrent();
64
+ finishUpdate = updater && updater._start();
64
65
  }
65
66
 
66
- function createUpdater(updater: () => void) {
67
- const s = signal(undefined) as Updater;
68
- s._updater = updater;
69
- return s;
67
+ function createUpdater(update: () => void) {
68
+ let updater!: Effect;
69
+ effect(function (this: Effect) {
70
+ updater = this;
71
+ });
72
+ updater._callback = update;
73
+ return updater;
70
74
  }
71
75
 
72
76
  /**
@@ -91,19 +95,6 @@ Object.defineProperties(Signal.prototype, {
91
95
  ref: { configurable: true, value: null },
92
96
  });
93
97
 
94
- // Track the current owner (roughly equiv to current vnode)
95
- let lastOwner: ReactOwner | undefined;
96
- let currentOwner: ReactOwner | null = null;
97
- Object.defineProperty(internals.ReactCurrentOwner, "current", {
98
- get() {
99
- return currentOwner;
100
- },
101
- set(owner) {
102
- currentOwner = owner;
103
- if (currentOwner) lastOwner = currentOwner;
104
- },
105
- });
106
-
107
98
  // Track the current dispatcher (roughly equiv to current component impl)
108
99
  let lock = false;
109
100
  const UPDATE = () => ({});
@@ -115,19 +106,19 @@ Object.defineProperty(internals.ReactCurrentDispatcher, "current", {
115
106
  set(api) {
116
107
  currentDispatcher = api;
117
108
  if (lock) return;
118
- if (lastOwner && api && !isInvalidHookAccessor(api)) {
109
+ if (api && !isInvalidHookAccessor(api)) {
119
110
  // prevent re-injecting useReducer when the Dispatcher
120
111
  // context changes to run the reducer callback:
121
112
  lock = true;
122
113
  const rerender = api.useReducer(UPDATE, {})[1];
123
114
  lock = false;
124
115
 
125
- let updater = updaterForComponent.get(lastOwner);
116
+ let updater = updaterForComponent.get(rerender);
126
117
  if (!updater) {
127
118
  updater = createUpdater(rerender);
128
- updaterForComponent.set(lastOwner, updater);
119
+ updaterForComponent.set(rerender, updater);
129
120
  } else {
130
- updater._updater = rerender;
121
+ updater._callback = rerender;
131
122
  }
132
123
  setCurrentUpdater(updater);
133
124
  } else {
@@ -144,8 +135,7 @@ function isInvalidHookAccessor(api: ReactDispatcher) {
144
135
  if (cached !== undefined) return cached;
145
136
  // we only want the real implementation, not the warning ones
146
137
  const invalid =
147
- api.useCallback.length < 2 ||
148
- /warnInvalidHookAccess/.test(api.useCallback as any);
138
+ api.useCallback.length < 2 || /Invalid/.test(api.useCallback as any);
149
139
  invalidHookAccessors.set(api, invalid);
150
140
  return invalid;
151
141
  }
@@ -159,3 +149,14 @@ export function useComputed<T>(compute: () => T) {
159
149
  $compute.current = compute;
160
150
  return useMemo(() => computed<T>(() => $compute.current()), []);
161
151
  }
152
+
153
+ export function useSignalEffect(cb: () => void | (() => void)) {
154
+ const callback = useRef(cb);
155
+ callback.current = cb;
156
+
157
+ useEffect(() => {
158
+ return effect(() => {
159
+ return callback.current();
160
+ });
161
+ }, []);
162
+ }
package/src/internal.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { Signal } from "@preact/signals-core";
2
2
 
3
- export interface ReactOwner {
4
- _: never;
3
+ export interface Effect {
4
+ _sources: object | undefined;
5
+ _start(): () => void;
6
+ _callback(): void;
7
+ _dispose(): void;
5
8
  }
6
9
 
7
10
  export interface ReactDispatcher {