@preact/signals-react 1.0.0 → 1.0.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,18 @@
1
1
  # @preact/signals-react
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 62439c9: Fixes invalid React peer dependency range for environments with strict peerDeps
8
+ - Updated dependencies [336bb34]
9
+ - Updated dependencies [bc0080c]
10
+ - Updated dependencies [7228418]
11
+ - Updated dependencies [32abe07]
12
+ - Updated dependencies [4782b41]
13
+ - Updated dependencies [bf6af3b]
14
+ - @preact/signals-core@1.1.0
15
+
3
16
  ## 1.0.0
4
17
 
5
18
  ### Major Changes
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+
2
+ # Signals
3
+
4
+ Signals is a performant state management library with two primary goals:
5
+
6
+ 1. Make it as easy as possible to write business logic for small up to complex apps. No matter how complex your logic is, your app updates should stay fast without you needing to think about it. Signals automatically optimize state updates behind the scenes to trigger the fewest updates necessary. They are lazy by default and automatically skip signals that no one listens to.
7
+ 2. Integrate into frameworks as if they were native built-in primitives. You don't need any selectors, wrapper functions, or anything else. Signals can be accessed directly and your component will automatically re-render when the signal's value changes.
8
+
9
+ Read the [announcement post](https://preactjs.com/blog/introducing-signals/) to learn more about which problems signals solves and how it came to be.
10
+
11
+ ## Installation:
12
+
13
+ ```sh
14
+ npm install @preact/signals-react
15
+ ```
16
+
17
+ - [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)
23
+ - [React Integration](#react-integration)
24
+ - [Hooks](#hooks)
25
+ - [License](#license)
26
+
27
+ ## React Integration
28
+
29
+ The React integration can be installed via:
30
+
31
+ ```sh
32
+ npm install @preact/signals-react
33
+ ```
34
+
35
+ Similar to the Preact integration, the React adapter allows you to access signals directly inside your components and will automatically subscribe to them.
36
+
37
+ ```js
38
+ import { signal } from "@preact/signals-react";
39
+
40
+ const count = signal(0);
41
+
42
+ function CounterValue() {
43
+ // Whenver the `count` signal is updated, we'll
44
+ // re-render this component automatically for you
45
+ return <p>Value: {count.value}</p>;
46
+ }
47
+ ```
48
+
49
+ ### Hooks
50
+
51
+ If you need to instantiate new signals inside your components, you can use the `useSignal` or `useComputed` hook.
52
+
53
+ ```js
54
+ import { useSignal, useComputed } from "@preact/signals-react";
55
+
56
+ function Counter() {
57
+ const count = useSignal(0);
58
+ const double = useComputed(() => count.value * 2);
59
+
60
+ return (
61
+ <button onClick={() => count.value++}>
62
+ Value: {count.value}, value x 2 = {double.value}
63
+ </button>
64
+ );
65
+ }
66
+ ```
67
+
68
+ ## License
69
+
70
+ `MIT`, see the [LICENSE](../../LICENSE) file.
71
+
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._c=!0,t._u=r,t}var f=o("a").$$typeof;Object.defineProperties(n.Signal.prototype,{$$typeof:{value:f},type:{value:function(r){return r.data.value}},props:{get:function(){return{data:this}}},ref:{value:null}});var v,s=!1,p=function(){return{}};Object.defineProperty(r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return v},set:function(n){if(v=n,!s)if(n&&!x(n)){s=!0;var t=n.useReducer(p,{})[1];s=!1;var e=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current,u=i.get(e);u||(u=c(t),i.set(e,u)),a(u)}else a()}});var l=new Map;function x(r){var n=l.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/warnInvalidHookAccess/.test(r.useCallback);return l.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),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=o("a").$$typeof;Object.defineProperties(n.Signal.prototype,{$$typeof:{value:f},type:{value:function(r){return r.data.value}},props:{get:function(){return{data:this}}},ref:{value:null}});var v,s=!1,p=function(){return{}};Object.defineProperty(r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return v},set:function(n){if(v=n,!s)if(n&&!x(n)){s=!0;var t=n.useReducer(p,{})[1];s=!1;var e=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current,u=i.get(e);u||(u=c(t),i.set(e,u)),a(u)}else a()}});var l=new Map;function x(r){var n=l.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/warnInvalidHookAccess/.test(r.useCallback);return l.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 +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._canActivate = true;\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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["finishUpdate","createElement","React","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_canActivate","_updater","$$typeof","Object","defineProperties","prototype","_ref","data","get","ref","currentDispatcher","UPDATE","defineProperty","internals","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","set","api","lock","isInvalidHookAccessor","useReducer","currentOwner","ReactCurrentOwner","current","rerender","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","exports","signalsCore","batch","computed","effect","useComputed","compute","$compute","useRef","useMemo","useSignal"],"mappings":"mIAuDAA,sBA/BmBC,EAAGC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACJ,aAANA,GAAoBC,aAAxBC,EAAAA,SAECH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAOP,EAAcQ,MAAMC,KAAMC,UACjC,EAkBD,IAAMC,EAAsB,IAA5BC,QAEA,SAASC,EAAkBC,GAEtBf,GAAcA,GAAa,GAAM,GAErCA,EAAee,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,IAAMG,EAAIC,EAAMA,YAACC,GAGjB,OAFAF,EAAEG,IAAe,EACjBH,EAAEI,GAAWP,EAEbG,CAAA,CAWD,IAAMK,EAAWtB,EAAc,KAAKsB,SACpCC,OAAOC,iBAAiBlB,EAAAA,OAAOmB,UAAW,CACzCH,SAAU,CAAEf,MAAOe,GACnBpB,KAAM,CAAEK,MATT,SAAwCmB,GACvC,OADuCA,EAAxBC,KACHpB,KACZ,GAQAJ,MAAO,CACNyB,IADM,WAEL,MAAO,CAAED,KAAMlB,KACf,GAEFoB,IAAK,CAAEtB,MAAO,QAWf,IAEIuB,KAFO,EACCC,EAAG,WAAO,MAAA,CAAP,CAAA,EAEfR,OAAOS,eAAeC,EAASC,mDAACC,uBAAwB,UAAW,CAClEP,IADkE,WAEjE,QACA,EACDQ,IAJkE,SAI9DC,GAEH,GADAP,EAAoBO,GAChBC,EACJ,GAAID,IAAQE,EAAsBF,GAAM,CAGvCC,GAAO,EACP,MAAiBD,EAAIG,WAAWT,EAAQ,CAAvB,GAA2B,GAC5CO,GAAO,EACP,IAAMG,EAAeR,EAASC,mDAACQ,kBAAkBC,QACtC7B,EAAGH,EAAoBiB,IAAIa,GACjC3B,IACJA,EAAUE,EAAc4B,GACxBjC,EAAoByB,IAAIK,EAAc3B,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAAMgC,EAAuB,IAA7BC,IACA,SAASP,EAAsBF,GAC9B,IAAMU,EAASF,EAAqBjB,IAAIS,GACxC,QAAelB,IAAX4B,EAAsB,OAAAA,EAE1B,IAAMC,EACLX,EAAIY,YAAYC,OAAS,GACzB,wBAAwBC,KAAKd,EAAIY,aAElC,OADAJ,EAAqBT,IAAIC,EAAKW,GACvBA,CACP,CAUAI,QAAA9C,OAAA+C,EAAA/C,OAAA8C,QAAAE,MAAAD,EAAAC,MAAAF,QAAAG,SAAAF,EAAAE,SAAAH,QAAAI,OAAAH,EAAAG,OAAAJ,QAAAlC,OAAAmC,EAAAnC,OAAAkC,QAAAK,YAJeA,SAAeC,GAC9B,IAAMC,EAAWC,EAAMA,OAACF,GAExB,OADAC,EAAShB,QAAUe,EACZG,EAAAA,QAAQ,WAAA,OAAcN,EAAAA,SAAI,WAAMI,OAAAA,EAAShB,SAAf,EAAlB,EAA6C,GAC5D,EAAAS,QAAAU,UAReA,SAAavD,GAC5B,OAAOsD,EAAOA,QAAC,WAAA,OAAY3C,EAAAA,OAAIX,EAAhB,EAAwB,GACvC"}
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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["finishUpdate","createElement","React","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_updater","$$typeof","Object","defineProperties","prototype","_ref","data","get","ref","currentDispatcher","lock","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","isInvalidHookAccessor","rerender","useReducer","currentOwner","ReactCurrentOwner","current","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","exports","signalsCore","batch","computed","effect","useComputed","compute","useRef","$compute","useMemo","useSignal"],"mappings":"mIAuDAA,sBA/BMC,EAAgBC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAATD,GAAqBC,EAC/B,IAAK,IAAIC,KAAKD,EAAO,CACpB,IAAIE,EAAIF,EAAMC,GACJ,aAANA,GAAoBC,aAAaC,EAAAA,SAEpCH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAOP,EAAcQ,MAAMC,KAAMC,UACjC,EAkBD,IAAMC,EAAsB,IAA5BC,QAEA,SAAAC,EAA2BC,GAEtBf,GAAcA,GAAa,GAAM,GAErCA,EAAee,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,IAAOG,EAAGC,EAAAA,YAAOC,GAEjB,OADAF,EAAEG,GAAWN,EAEbG,CAAA,CAWD,MAAiBjB,EAAc,KAAKqB,SACpCC,OAAOC,iBAAiBjB,EAAMA,OAACkB,UAAW,CACzCH,SAAU,CAAEd,MAAOc,GACnBnB,KAAM,CAAEK,MATT,SAAwCkB,GACvC,OADuCA,EAAxBC,KACHnB,KACZ,GAQAJ,MAAO,CACNwB,IAAG,WACF,MAAO,CAAED,KAAMjB,KACf,GAEFmB,IAAK,CAAErB,MAAO,QAWf,IAEAsB,EAFIC,GAAO,EACLC,EAAS,WAAA,MAAO,EAAP,EAEfT,OAAOU,eAAeC,EAAAA,mDAAUC,uBAAwB,UAAW,CAClEP,IAAG,WACF,OAAOE,CACP,EACDM,IAAIC,SAAAA,GAEH,GADAP,EAAoBO,GAChBN,EACJ,GAAIM,IAAQC,EAAsBD,GAAM,CAGvCN,GAAO,EACP,IAAMQ,EAAWF,EAAIG,WAAWR,EAAQ,CAAA,GAAI,GAC5CD,GAAO,EACP,IAAkBU,EAAGP,EAAAA,mDAAUQ,kBAAkBC,QAC7C5B,EAAUH,EAAoBgB,IAAIa,GACjC1B,IACJA,EAAUE,EAAcsB,GACxB3B,EAAoBwB,IAAIK,EAAc1B,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAAM8B,EAAuB,IAA7BC,IACA,SAASP,EAAsBD,GAC9B,IAAMS,EAASF,EAAqBhB,IAAIS,GACxC,QAAejB,IAAX0B,EAAsB,OAAOA,EAEjC,IAAaC,EACZV,EAAIW,YAAYC,OAAS,GACzB,wBAAwBC,KAAKb,EAAIW,aAElC,OADAJ,EAAqBR,IAAIC,EAAKU,GAE9BA,CAAA,CAUAI,QAAA5C,OAAA6C,EAAA7C,OAAA4C,QAAAE,MAAAD,EAAAC,MAAAF,QAAAG,SAAAF,EAAAE,SAAAH,QAAAI,OAAAH,EAAAG,OAAAJ,QAAAhC,OAAAiC,EAAAjC,OAAAgC,QAAAK,YAJK,SAAyBC,GAC9B,MAAiBC,EAAAA,OAAOD,GAExB,OADAE,EAAShB,QAAUc,EACZG,EAAOA,QAAC,WAAA,OAAcN,EAAAA,SAAI,WAAMK,OAAAA,EAAShB,SAAf,EAAlB,EAA6C,GAC5D,EAAAQ,QAAAU,UARK,SAAuBrD,GAC5B,OAAcoD,EAAAA,QAAC,WAAMzC,OAAAA,EAAMA,OAAIX,EAAhB,EAAwB,GACvC"}
@@ -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 i,u=/*#__PURE__*/t(e),o=u.createElement;u.createElement=function(n,e){if("string"==typeof n&&e)for(var t in e){var i=e[t];"children"!==t&&i instanceof r.Signal&&(e[t]=i.value)}return o.apply(this,arguments)};var f=new WeakMap;function a(n){i&&i(!0,!0),i=n&&n._()}function c(n){var e=r.signal(void 0);return e._c=!0,e._u=n,e}var s=o("a").$$typeof;Object.defineProperties(r.Signal.prototype,{$$typeof:{value:s},type:{value:function(n){return n.data.value}},props:{get:function(){return{data:this}}},ref:{value:null}});var v,l=!1,p=function(){return{}};Object.defineProperty(e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return v},set:function(n){if(v=n,!l)if(n&&!y(n)){l=!0;var r=n.useReducer(p,{})[1];l=!1;var t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current,i=f.get(t);i||(i=c(r),f.set(t,i)),a(i)}else a()}});var d=new Map;function y(n){var e=d.get(n);if(void 0!==e)return e;var r=n.useCallback.length<2||/warnInvalidHookAccess/.test(n.useCallback);return d.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),o=u.createElement;u.createElement=function(n,e){if("string"==typeof n&&e)for(var t in e){var i=e[t];"children"!==t&&i instanceof r.Signal&&(e[t]=i.value)}return o.apply(this,arguments)};var f=new WeakMap;function a(n){i&&i(!0,!0),i=n&&n._()}function c(n){var e=r.signal(void 0);return e._u=n,e}var s=o("a").$$typeof;Object.defineProperties(r.Signal.prototype,{$$typeof:{value:s},type:{value:function(n){return n.data.value}},props:{get:function(){return{data:this}}},ref:{value:null}});var v,l=!1,p=function(){return{}};Object.defineProperty(e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,"current",{get:function(){return v},set:function(n){if(v=n,!l)if(n&&!y(n)){l=!0;var r=n.useReducer(p,{})[1];l=!1;var t=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner.current,i=f.get(t);i||(i=c(r),f.set(t,i)),a(i)}else a()}});var d=new Map;function y(n){var e=d.get(n);if(void 0!==e)return e;var r=n.useCallback.length<2||/warnInvalidHookAccess/.test(n.useCallback);return d.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 +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._canActivate = true;\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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["finishUpdate","createElement","React","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_canActivate","_updater","$$typeof","Object","defineProperties","prototype","_ref","data","get","ref","currentDispatcher","UPDATE","defineProperty","internals","__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED","ReactCurrentDispatcher","set","api","lock","isInvalidHookAccessor","useReducer","currentOwner","ReactCurrentOwner","current","rerender","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","exports","signalsCore","batch","computed","effect","useComputed","compute","$compute","useRef","useMemo","useSignal"],"mappings":"0ZAuDAA,sBA/BmBC,EAAGC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACJ,aAANA,GAAoBC,aAAxBC,EAAAA,SAECH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAOP,EAAcQ,MAAMC,KAAMC,UACjC,EAkBD,IAAMC,EAAsB,IAA5BC,QAEA,SAASC,EAAkBC,GAEtBf,GAAcA,GAAa,GAAM,GAErCA,EAAee,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,IAAMG,EAAIC,EAAMA,YAACC,GAGjB,OAFAF,EAAEG,IAAe,EACjBH,EAAEI,GAAWP,EAEbG,CAAA,CAWD,IAAMK,EAAWtB,EAAc,KAAKsB,SACpCC,OAAOC,iBAAiBlB,EAAAA,OAAOmB,UAAW,CACzCH,SAAU,CAAEf,MAAOe,GACnBpB,KAAM,CAAEK,MATT,SAAwCmB,GACvC,OADuCA,EAAxBC,KACHpB,KACZ,GAQAJ,MAAO,CACNyB,IADM,WAEL,MAAO,CAAED,KAAMlB,KACf,GAEFoB,IAAK,CAAEtB,MAAO,QAWf,IAEIuB,KAFO,EACCC,EAAG,WAAO,MAAA,CAAP,CAAA,EAEfR,OAAOS,eAAeC,EAASC,mDAACC,uBAAwB,UAAW,CAClEP,IADkE,WAEjE,QACA,EACDQ,IAJkE,SAI9DC,GAEH,GADAP,EAAoBO,GAChBC,EACJ,GAAID,IAAQE,EAAsBF,GAAM,CAGvCC,GAAO,EACP,MAAiBD,EAAIG,WAAWT,EAAQ,CAAvB,GAA2B,GAC5CO,GAAO,EACP,IAAMG,EAAeR,EAASC,mDAACQ,kBAAkBC,QACtC7B,EAAGH,EAAoBiB,IAAIa,GACjC3B,IACJA,EAAUE,EAAc4B,GACxBjC,EAAoByB,IAAIK,EAAc3B,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAAMgC,EAAuB,IAA7BC,IACA,SAASP,EAAsBF,GAC9B,IAAMU,EAASF,EAAqBjB,IAAIS,GACxC,QAAelB,IAAX4B,EAAsB,OAAAA,EAE1B,IAAMC,EACLX,EAAIY,YAAYC,OAAS,GACzB,wBAAwBC,KAAKd,EAAIY,aAElC,OADAJ,EAAqBT,IAAIC,EAAKW,GACvBA,CACP,CAUAI,EAAA9C,OAAA+C,EAAA/C,OAAA8C,EAAAE,MAAAD,EAAAC,MAAAF,EAAAG,SAAAF,EAAAE,SAAAH,EAAAI,OAAAH,EAAAG,OAAAJ,EAAAlC,OAAAmC,EAAAnC,OAAAkC,EAAAK,YAJeA,SAAeC,GAC9B,IAAMC,EAAWC,EAAMA,OAACF,GAExB,OADAC,EAAShB,QAAUe,EACZG,EAAAA,QAAQ,WAAA,OAAcN,EAAAA,SAAI,WAAMI,OAAAA,EAAShB,SAAf,EAAlB,EAA6C,GAC5D,EAAAS,EAAAU,UAReA,SAAavD,GAC5B,OAAOsD,EAAOA,QAAC,WAAA,OAAY3C,EAAAA,OAAIX,EAAhB,EAAwB,GACvC,CAMA"}
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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["finishUpdate","createElement","React","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_updater","$$typeof","Object","defineProperties","prototype","_ref","data","get","ref","currentDispatcher","lock","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","isInvalidHookAccessor","rerender","useReducer","currentOwner","ReactCurrentOwner","current","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","exports","signalsCore","batch","computed","effect","useComputed","compute","useRef","$compute","useMemo","useSignal"],"mappings":"0ZAuDAA,sBA/BMC,EAAgBC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAATD,GAAqBC,EAC/B,IAAK,IAAIC,KAAKD,EAAO,CACpB,IAAIE,EAAIF,EAAMC,GACJ,aAANA,GAAoBC,aAAaC,EAAAA,SAEpCH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAOP,EAAcQ,MAAMC,KAAMC,UACjC,EAkBD,IAAMC,EAAsB,IAA5BC,QAEA,SAAAC,EAA2BC,GAEtBf,GAAcA,GAAa,GAAM,GAErCA,EAAee,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,IAAOG,EAAGC,EAAAA,YAAOC,GAEjB,OADAF,EAAEG,GAAWN,EAEbG,CAAA,CAWD,MAAiBjB,EAAc,KAAKqB,SACpCC,OAAOC,iBAAiBjB,EAAMA,OAACkB,UAAW,CACzCH,SAAU,CAAEd,MAAOc,GACnBnB,KAAM,CAAEK,MATT,SAAwCkB,GACvC,OADuCA,EAAxBC,KACHnB,KACZ,GAQAJ,MAAO,CACNwB,IAAG,WACF,MAAO,CAAED,KAAMjB,KACf,GAEFmB,IAAK,CAAErB,MAAO,QAWf,IAEAsB,EAFIC,GAAO,EACLC,EAAS,WAAA,MAAO,EAAP,EAEfT,OAAOU,eAAeC,EAAAA,mDAAUC,uBAAwB,UAAW,CAClEP,IAAG,WACF,OAAOE,CACP,EACDM,IAAIC,SAAAA,GAEH,GADAP,EAAoBO,GAChBN,EACJ,GAAIM,IAAQC,EAAsBD,GAAM,CAGvCN,GAAO,EACP,IAAMQ,EAAWF,EAAIG,WAAWR,EAAQ,CAAA,GAAI,GAC5CD,GAAO,EACP,IAAkBU,EAAGP,EAAAA,mDAAUQ,kBAAkBC,QAC7C5B,EAAUH,EAAoBgB,IAAIa,GACjC1B,IACJA,EAAUE,EAAcsB,GACxB3B,EAAoBwB,IAAIK,EAAc1B,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAAM8B,EAAuB,IAA7BC,IACA,SAASP,EAAsBD,GAC9B,IAAMS,EAASF,EAAqBhB,IAAIS,GACxC,QAAejB,IAAX0B,EAAsB,OAAOA,EAEjC,IAAaC,EACZV,EAAIW,YAAYC,OAAS,GACzB,wBAAwBC,KAAKb,EAAIW,aAElC,OADAJ,EAAqBR,IAAIC,EAAKU,GAE9BA,CAAA,CAUAI,EAAA5C,OAAA6C,EAAA7C,OAAA4C,EAAAE,MAAAD,EAAAC,MAAAF,EAAAG,SAAAF,EAAAE,SAAAH,EAAAI,OAAAH,EAAAG,OAAAJ,EAAAhC,OAAAiC,EAAAjC,OAAAgC,EAAAK,YAJK,SAAyBC,GAC9B,MAAiBC,EAAAA,OAAOD,GAExB,OADAE,EAAShB,QAAUc,EACZG,EAAOA,QAAC,WAAA,OAAcN,EAAAA,SAAI,WAAMK,OAAAA,EAAShB,SAAf,EAAlB,EAA6C,GAC5D,EAAAQ,EAAAU,UARK,SAAuBrD,GAC5B,OAAcoD,EAAAA,QAAC,WAAMzC,OAAAA,EAAMA,OAAIX,EAAhB,EAAwB,GACvC,CAMA"}
package/dist/signals.mjs CHANGED
@@ -1 +1 @@
1
- import t,{__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED as n,useMemo as e,useRef as o}from"react";import{Signal as r,signal as c,computed as i}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";const s=t.createElement;let a;t.createElement=function(t,n){if("string"==typeof t&&n)for(let t in n){let e=n[t];"children"!==t&&e instanceof r&&(n[t]=e.value)}return s.apply(this,arguments)};const f=new WeakMap;function u(t){a&&a(!0,!0),a=t&&t._()}function l(t){const n=c(void 0);return n._c=!0,n._u=t,n}const p=s("a").$$typeof;Object.defineProperties(r.prototype,{$$typeof:{value:p},type:{value:function({data:t}){return t.value}},props:{get(){return{data:this}}},ref:{value:null}});let d=!1;const g=()=>({});let m;Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:()=>m,set(t){if(m=t,!d)if(t&&!h(t)){d=!0;const e=t.useReducer(g,{})[1];d=!1;const o=n.ReactCurrentOwner.current;let r=f.get(o);r||(r=l(e),f.set(o,r)),u(r)}else u()}});const v=new Map;function h(t){const n=v.get(t);if(void 0!==n)return n;const e=t.useCallback.length<2||/warnInvalidHookAccess/.test(t.useCallback);return v.set(t,e),e}function b(t){return e(()=>c(t),[])}function w(t){const n=o(t);return n.current=t,e(()=>i(()=>n.current()),[])}export{w as useComputed,b 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}from"react";import{Signal as r,signal as c,computed as i}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";const s=t.createElement;let a;t.createElement=function(t,n){if("string"==typeof t&&n)for(let t in n){let e=n[t];"children"!==t&&e instanceof r&&(n[t]=e.value)}return s.apply(this,arguments)};const f=new WeakMap;function u(t){a&&a(!0,!0),a=t&&t._()}function l(t){const n=c(void 0);return n._u=t,n}const p=s("a").$$typeof;Object.defineProperties(r.prototype,{$$typeof:{value:p},type:{value:function({data:t}){return t.value}},props:{get(){return{data:this}}},ref:{value:null}});let d=!1;const g=()=>({});let m;Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:()=>m,set(t){if(m=t,!d)if(t&&!h(t)){d=!0;const e=t.useReducer(g,{})[1];d=!1;const o=n.ReactCurrentOwner.current;let r=f.get(o);r||(r=l(e),f.set(o,r)),u(r)}else u()}});const v=new Map;function h(t){const n=v.get(t);if(void 0!==n)return n;const e=t.useCallback.length<2||/warnInvalidHookAccess/.test(t.useCallback);return v.set(t,e),e}function b(t){return e(()=>c(t),[])}function w(t){const n=o(t);return n.current=t,e(()=>i(()=>n.current()),[])}export{w as useComputed,b as useSignal};//# 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._canActivate = true;\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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["createElement","React","finishUpdate","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","updater","_setCurrent","createUpdater","signal","undefined","s","_canActivate","_updater","$$typeof","Object","defineProperties","prototype","data","get","ref","lock","UPDATE","currentDispatcher","defineProperty","internals","ReactCurrentDispatcher","set","api","isInvalidHookAccessor","useReducer","currentOwner","ReactCurrentOwner","current","rerender","setCurrentUpdater","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","useSignal","useMemo","useComputed","compute","$compute","useRef","computed"],"mappings":"qPAwBA,MAAmBA,EAAGC,EAAMD,cA+B5B,IAAIE,EA7BJD,EAAMD,cAAgB,SAAUG,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACJ,aAANA,GAAoBC,aAAxBC,IAECH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAoBR,EAACS,MAAMC,KAAMC,UACjC,EAkBD,MAAyBC,EAAG,IAAIC,QAEhC,WAA2BC,GAEtBZ,GAAcA,GAAa,GAAM,GAErCA,EAAeY,GAAWA,EAAQC,GAClC,CAED,SAAAC,EAAuBF,GACtB,QAAUG,OAAOC,GAGjB,OAFAC,EAAEC,IAAe,EACjBD,EAAEE,GAAWP,EACNK,CACP,CAWD,MAAcG,EAAGtB,EAAc,KAAKsB,SACpCC,OAAOC,iBAAiBjB,EAAOkB,UAAW,CACzCH,SAAU,CAAEd,MAAOc,GACnBnB,KAAM,CAAEK,MATT,UAAckB,KAAEA,IACf,SAAYlB,KACZ,GAQAJ,MAAO,CACNuB,MACC,MAAO,CAAED,KAAMhB,KACf,GAEFkB,IAAK,CAAEpB,MAAO,QAWf,IAAIqB,GAAO,EACX,MAAYC,EAAG,KAAA,CAAA,GACf,IAAIC,EACJR,OAAOS,eAAeC,EAAUC,uBAAwB,UAAW,CAClEP,IAAG,MAGHQ,IAAIC,GAEH,GADAL,EAAoBK,GAChBP,EACJ,GAAIO,IAAQC,EAAsBD,GAAM,CAGvCP,GAAO,EACP,QAAiBO,EAAIE,WAAWR,EAAQ,CAAA,GAAI,GAC5CD,GAAO,EACP,MAAMU,EAAeN,EAAUO,kBAAkBC,QACjD,IAAW3B,EAAGF,EAAoBe,IAAIY,GACjCzB,IACJA,EAAUE,EAAc0B,GACxB9B,EAAoBuB,IAAII,EAAczB,IAEvC6B,EAAkB7B,EAClB,MACA6B,GAED,IAKF,MAA0BC,EAAG,IAAIC,IACjC,SAAAR,EAA+BD,GAC9B,MAAYU,EAAGF,EAAqBjB,IAAIS,GACxC,QAAelB,IAAX4B,EAAsB,OAAAA,EAE1B,MAAMC,EACLX,EAAIY,YAAYC,OAAS,GACzB,wBAAwBC,KAAKd,EAAIY,aAElC,OADAJ,EAAqBT,IAAIC,EAAKW,GACvBA,CACP,CAEeI,SAAAA,EAAa3C,GAC5B,OAAO4C,EAAQ,IAAMnC,EAAUT,GAAQ,GACvC,CAEK,SAAA6C,EAAyBC,GAC9B,MAAMC,EAAWC,EAAOF,GAExB,OADAC,EAASd,QAAUa,EACZF,EAAQ,IAAMK,EAAY,IAAMF,EAASd,WAAY,GAC5D,QAAAY,iBAAAF"}
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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["createElement","React","finishUpdate","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_updater","$$typeof","Object","defineProperties","prototype","data","get","ref","lock","UPDATE","currentDispatcher","defineProperty","internals","ReactCurrentDispatcher","set","api","isInvalidHookAccessor","rerender","useReducer","currentOwner","ReactCurrentOwner","current","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","useSignal","useMemo","useComputed","compute","$compute","useRef","computed"],"mappings":"qPAwBA,MAAMA,EAAgBC,EAAMD,cA+B5B,IAAIE,EA7BJD,EAAMD,cAAgB,SAAUG,EAAMC,GACrC,GAAoB,iBAATD,GAAqBC,EAC/B,IAAK,IAAIC,KAAKD,EAAO,CACpB,IAAIE,EAAIF,EAAMC,GACJ,aAANA,GAAoBC,aAAxBC,IAECH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAoBR,EAACS,MAAMC,KAAMC,UACjC,EAkBD,MAAyBC,EAAG,IAAIC,QAEhC,SAASC,EAAkBC,GAEtBb,GAAcA,GAAa,GAAM,GAErCA,EAAea,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,MAAOG,EAAGC,OAAOC,GAEjB,OADAF,EAAEG,GAAWN,EAEbG,CAAA,CAWD,MAAMI,EAAWtB,EAAc,KAAKsB,SACpCC,OAAOC,iBAAiBjB,EAAOkB,UAAW,CACzCH,SAAU,CAAEd,MAAOc,GACnBnB,KAAM,CAAEK,MATT,UAAckB,KAAEA,IACf,OAAOA,EAAKlB,KACZ,GAQAJ,MAAO,CACNuB,MACC,MAAO,CAAED,KAAMhB,KACf,GAEFkB,IAAK,CAAEpB,MAAO,QAWf,IAAIqB,GAAO,EACX,MAAMC,EAAS,KAAO,CAAP,GACf,IAAAC,EACAR,OAAOS,eAAeC,EAAUC,uBAAwB,UAAW,CAClEP,IAAG,IAEFI,EACDI,IAAIC,GAEH,GADAL,EAAoBK,GAChBP,EACJ,GAAIO,IAAQC,EAAsBD,GAAM,CAGvCP,GAAO,EACP,MAAcS,EAAGF,EAAIG,WAAWT,EAAQ,CAAvB,GAA2B,GAC5CD,GAAO,EACP,MAAkBW,EAAGP,EAAUQ,kBAAkBC,QACjD,IAAI3B,EAAUH,EAAoBe,IAAIa,GACjCzB,IACJA,EAAUE,EAAcqB,GACxB1B,EAAoBuB,IAAIK,EAAczB,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,MAAM6B,EAAuB,IAA7BC,IACA,SAASP,EAAsBD,GAC9B,MAAYS,EAAGF,EAAqBhB,IAAIS,GACxC,QAAehB,IAAXyB,EAAsB,OAAAA,EAE1B,MAAMC,EACLV,EAAIW,YAAYC,OAAS,GACzB,wBAAwBC,KAAKb,EAAIW,aAElC,OADAJ,EAAqBR,IAAIC,EAAKU,GACvBA,CACP,CAEeI,SAAAA,EAAa1C,GAC5B,OAAO2C,EAAQ,IAAMhC,EAAUX,GAAQ,GACvC,CAEK,SAAA4C,EAAyBC,GAC9B,MAAMC,EAAWC,EAAOF,GAExB,OADAC,EAASZ,QAAUW,EACZF,EAAQ,IAAMK,EAAY,IAAMF,EAASZ,WAAY,GAC5D,QAAAU,iBAAAF"}
@@ -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 a,signal as i,computed as o}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";var u,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 a&&(n[t]=e.value)}return c.apply(this,arguments)};var f=new WeakMap;function v(r){u&&u(!0,!0),u=r&&r._()}function p(r){var n=i(void 0);return n._c=!0,n._u=r,n}var s=c("a").$$typeof;Object.defineProperties(a.prototype,{$$typeof:{value:s},type:{value:function(r){return r.data.value}},props:{get:function(){return{data:this}}},ref:{value:null}});var l,g=!1,d=function(){return{}};Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:function(){return l},set:function(r){if(l=r,!g)if(r&&!h(r)){g=!0;var t=r.useReducer(d,{})[1];g=!1;var e=n.ReactCurrentOwner.current,a=f.get(e);a||(a=p(t),f.set(e,a)),v(a)}else v()}});var m=new Map;function h(r){var n=m.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/warnInvalidHookAccess/.test(r.useCallback);return m.set(r,t),t}function b(r){return t(function(){return i(r)},[])}function w(r){var n=e(r);return n.current=r,t(function(){return o(function(){return n.current()})},[])}export{w as useComputed,b as useSignal};//# sourceMappingURL=signals.module.js.map
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 a,signal as i,computed as o}from"@preact/signals-core";export{Signal,batch,computed,effect,signal}from"@preact/signals-core";var u,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 a&&(n[t]=e.value)}return c.apply(this,arguments)};var f=new WeakMap;function v(r){u&&u(!0,!0),u=r&&r._()}function p(r){var n=i(void 0);return n._u=r,n}var s=c("a").$$typeof;Object.defineProperties(a.prototype,{$$typeof:{value:s},type:{value:function(r){return r.data.value}},props:{get:function(){return{data:this}}},ref:{value:null}});var l,g=!1,d=function(){return{}};Object.defineProperty(n.ReactCurrentDispatcher,"current",{get:function(){return l},set:function(r){if(l=r,!g)if(r&&!h(r)){g=!0;var t=r.useReducer(d,{})[1];g=!1;var e=n.ReactCurrentOwner.current,a=f.get(e);a||(a=p(t),f.set(e,a)),v(a)}else v()}});var m=new Map;function h(r){var n=m.get(r);if(void 0!==n)return n;var t=r.useCallback.length<2||/warnInvalidHookAccess/.test(r.useCallback);return m.set(r,t),t}function b(r){return t(function(){return i(r)},[])}function w(r){var n=e(r);return n.current=r,t(function(){return o(function(){return n.current()})},[])}export{w as useComputed,b as useSignal};//# 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._canActivate = true;\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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["finishUpdate","createElement","React","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_canActivate","_updater","$$typeof","Object","defineProperties","prototype","_ref","data","get","ref","currentDispatcher","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","lock","isInvalidHookAccessor","useReducer","currentOwner","ReactCurrentOwner","current","rerender","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","useSignal","useMemo","useComputed","compute","$compute","useRef","computed"],"mappings":"qPAwBA,IA+BAA,EA/BmBC,EAAGC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAAhBD,GAA4BC,EAC/B,IAAK,IAALC,KAAAD,EAAqB,CACpB,IAAKE,EAAGF,EAAMC,GACJ,aAANA,GAAoBC,aAAxBC,IAECH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAOP,EAAcQ,MAAMC,KAAMC,UACjC,EAkBD,IAAMC,EAAsB,IAA5BC,QAEA,SAASC,EAAkBC,GAEtBf,GAAcA,GAAa,GAAM,GAErCA,EAAee,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,IAAMG,EAAIC,OAAOC,GAGjB,OAFAF,EAAEG,IAAe,EACjBH,EAAEI,GAAWP,EAEbG,CAAA,CAWD,IAAMK,EAAWtB,EAAc,KAAKsB,SACpCC,OAAOC,iBAAiBlB,EAAOmB,UAAW,CACzCH,SAAU,CAAEf,MAAOe,GACnBpB,KAAM,CAAEK,MATT,SAAwCmB,GACvC,OADuCA,EAAxBC,KACHpB,KACZ,GAQAJ,MAAO,CACNyB,IADM,WAEL,MAAO,CAAED,KAAMlB,KACf,GAEFoB,IAAK,CAAEtB,MAAO,QAWf,IAEIuB,KAFO,EACCC,EAAG,WAAO,MAAA,CAAP,CAAA,EAEfR,OAAOS,eAAeC,EAAUC,uBAAwB,UAAW,CAClEN,IADkE,WAEjE,QACA,EACDO,IAJkE,SAI9DC,GAEH,GADAN,EAAoBM,GAChBC,EACJ,GAAID,IAAQE,EAAsBF,GAAM,CAGvCC,GAAO,EACP,MAAiBD,EAAIG,WAAWR,EAAQ,CAAvB,GAA2B,GAC5CM,GAAO,EACP,IAAMG,EAAeP,EAAUQ,kBAAkBC,QACtC5B,EAAGH,EAAoBiB,IAAIY,GACjC1B,IACJA,EAAUE,EAAc2B,GACxBhC,EAAoBwB,IAAIK,EAAc1B,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAAM+B,EAAuB,IAA7BC,IACA,SAASP,EAAsBF,GAC9B,IAAMU,EAASF,EAAqBhB,IAAIQ,GACxC,QAAejB,IAAX2B,EAAsB,OAAAA,EAE1B,IAAMC,EACLX,EAAIY,YAAYC,OAAS,GACzB,wBAAwBC,KAAKd,EAAIY,aAElC,OADAJ,EAAqBT,IAAIC,EAAKW,GACvBA,CACP,CAEeI,SAAAA,EAAa5C,GAC5B,OAAO6C,EAAQ,WAAA,OAAYlC,EAAIX,EAAhB,EAAwB,GACvC,CAEe8C,SAAAA,EAAeC,GAC9B,IAAMC,EAAWC,EAAOF,GAExB,OADAC,EAASb,QAAUY,EACZF,EAAQ,WAAA,OAAcK,EAAI,WAAMF,OAAAA,EAASb,SAAf,EAAlB,EAA6C,GAC5D,QAAAW,iBAAAF"}
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: { value: $$typeof },\n\ttype: { value: Text },\n\tprops: {\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\tref: { value: null },\n});\n\n// Track the current owner (roughly equiv to current vnode)\n// let currentOwner: ReactOwner;\n// Object.defineProperty(internals.ReactCurrentOwner, \"current\", {\n// \tget() { return currentOwner; },\n// \tset(owner) { currentOwner = owner; },\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\t\t\tconst currentOwner = internals.ReactCurrentOwner.current;\n\t\t\tlet updater = updaterForComponent.get(currentOwner);\n\t\t\tif (!updater) {\n\t\t\t\tupdater = createUpdater(rerender);\n\t\t\t\tupdaterForComponent.set(currentOwner, updater);\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":["finishUpdate","createElement","React","type","props","i","v","Signal","value","apply","this","arguments","updaterForComponent","WeakMap","setCurrentUpdater","updater","_setCurrent","createUpdater","s","signal","undefined","_updater","$$typeof","Object","defineProperties","prototype","_ref","data","get","ref","currentDispatcher","lock","UPDATE","defineProperty","internals","ReactCurrentDispatcher","set","api","isInvalidHookAccessor","rerender","useReducer","currentOwner","ReactCurrentOwner","current","invalidHookAccessors","Map","cached","invalid","useCallback","length","test","useSignal","useMemo","useComputed","compute","useRef","$compute","computed"],"mappings":"qPAwBA,IA+BAA,EA/BMC,EAAgBC,EAAMD,cAE5BC,EAAMD,cAAgB,SAAUE,EAAMC,GACrC,GAAoB,iBAATD,GAAqBC,EAC/B,IAAK,IAAIC,KAAKD,EAAO,CACpB,IAAIE,EAAIF,EAAMC,GACJ,aAANA,GAAoBC,aAAaC,IAEpCH,EAAMC,GAAKC,EAAEE,MAEd,CAGF,OAAOP,EAAcQ,MAAMC,KAAMC,UACjC,EAkBD,IAAMC,EAAsB,IAA5BC,QAEA,SAAAC,EAA2BC,GAEtBf,GAAcA,GAAa,GAAM,GAErCA,EAAee,GAAWA,EAAQC,GAClC,CAED,SAASC,EAAcF,GACtB,IAAOG,EAAGC,OAAOC,GAEjB,OADAF,EAAEG,GAAWN,EAEbG,CAAA,CAWD,MAAiBjB,EAAc,KAAKqB,SACpCC,OAAOC,iBAAiBjB,EAAOkB,UAAW,CACzCH,SAAU,CAAEd,MAAOc,GACnBnB,KAAM,CAAEK,MATT,SAAwCkB,GACvC,OADuCA,EAAxBC,KACHnB,KACZ,GAQAJ,MAAO,CACNwB,IAAG,WACF,MAAO,CAAED,KAAMjB,KACf,GAEFmB,IAAK,CAAErB,MAAO,QAWf,IAEAsB,EAFIC,GAAO,EACLC,EAAS,WAAA,MAAO,EAAP,EAEfT,OAAOU,eAAeC,EAAUC,uBAAwB,UAAW,CAClEP,IAAG,WACF,OAAOE,CACP,EACDM,IAAIC,SAAAA,GAEH,GADAP,EAAoBO,GAChBN,EACJ,GAAIM,IAAQC,EAAsBD,GAAM,CAGvCN,GAAO,EACP,IAAMQ,EAAWF,EAAIG,WAAWR,EAAQ,CAAA,GAAI,GAC5CD,GAAO,EACP,IAAkBU,EAAGP,EAAUQ,kBAAkBC,QAC7C5B,EAAUH,EAAoBgB,IAAIa,GACjC1B,IACJA,EAAUE,EAAcsB,GACxB3B,EAAoBwB,IAAIK,EAAc1B,IAEvCD,EAAkBC,EAClB,MACAD,GAED,IAKF,IAAM8B,EAAuB,IAA7BC,IACA,SAASP,EAAsBD,GAC9B,IAAMS,EAASF,EAAqBhB,IAAIS,GACxC,QAAejB,IAAX0B,EAAsB,OAAOA,EAEjC,IAAaC,EACZV,EAAIW,YAAYC,OAAS,GACzB,wBAAwBC,KAAKb,EAAIW,aAElC,OADAJ,EAAqBR,IAAIC,EAAKU,GAE9BA,CAAA,CAEK,SAAAI,EAAuB3C,GAC5B,OAAc4C,EAAC,WAAMjC,OAAAA,EAAUX,EAAhB,EAAwB,GACvC,CAEK,SAAA6C,EAAyBC,GAC9B,MAAiBC,EAAOD,GAExB,OADAE,EAASb,QAAUW,EACZF,EAAQ,WAAA,OAAcK,EAAI,WAAMD,OAAAA,EAASb,SAAf,EAAlB,EAA6C,GAC5D,QAAAU,iBAAAF"}
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@preact/signals-react",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "license": "MIT",
5
5
  "description": "",
6
6
  "keywords": [],
7
7
  "authors": [
8
8
  "The Preact Authors (https://github.com/preactjs/signals/contributors)"
9
9
  ],
10
- "repository": "preactjs/signals",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/preactjs/signals"
13
+ },
11
14
  "bugs": "https://github.com/preactjs/signals/issues",
12
15
  "homepage": "https://preactjs.com",
13
16
  "funding": {
@@ -31,10 +34,10 @@
31
34
  },
32
35
  "mangle": "../../mangle.json",
33
36
  "dependencies": {
34
- "@preact/signals-core": "^1.0.0"
37
+ "@preact/signals-core": "^1.1.0"
35
38
  },
36
39
  "peerDependencies": {
37
- "react": "17.x | 18.x"
40
+ "react": "17.x || 18.x"
38
41
  },
39
42
  "devDependencies": {
40
43
  "react": "^18.2.0",
package/src/index.ts CHANGED
@@ -65,7 +65,6 @@ function setCurrentUpdater(updater?: Updater) {
65
65
 
66
66
  function createUpdater(updater: () => void) {
67
67
  const s = signal(undefined) as Updater;
68
- s._canActivate = true;
69
68
  s._updater = updater;
70
69
  return s;
71
70
  }
File without changes
@@ -2,7 +2,7 @@
2
2
  globalThis.IS_REACT_ACT_ENVIRONMENT = true;
3
3
 
4
4
  import { signal, useComputed } from "@preact/signals-react";
5
- import { createElement as h, useMemo } from "react";
5
+ import { createElement, useMemo } from "react";
6
6
  import { createRoot, Root } from "react-dom/client";
7
7
  import { act } from "react-dom/test-utils";
8
8
 
@@ -24,7 +24,7 @@ describe("@preact/signals-react", () => {
24
24
 
25
25
  describe("Text bindings", () => {
26
26
  it("should render text without signals", () => {
27
- render(h("span", null, "test"));
27
+ render(<span>test</span>);
28
28
  const span = scratch.firstChild;
29
29
  const text = span?.firstChild;
30
30
  expect(text).to.have.property("data", "test");
@@ -32,7 +32,7 @@ describe("@preact/signals-react", () => {
32
32
 
33
33
  it("should render Signals as Text", () => {
34
34
  const sig = signal("test");
35
- render(h("span", null, sig));
35
+ render(<span>{sig}</span>);
36
36
  const span = scratch.firstChild;
37
37
  expect(span).to.have.property("firstChild").that.is.an.instanceOf(Text);
38
38
  const text = span?.firstChild;
@@ -41,7 +41,7 @@ describe("@preact/signals-react", () => {
41
41
 
42
42
  it("should update Signal-based Text (no parent component)", () => {
43
43
  const sig = signal("test");
44
- render(h("span", null, sig));
44
+ render(<span>{sig}</span>);
45
45
 
46
46
  const text = scratch.firstChild!.firstChild!;
47
47
  expect(text).to.have.property("data", "test");
@@ -59,9 +59,9 @@ describe("@preact/signals-react", () => {
59
59
  it("should update Signal-based Text (in a parent component)", () => {
60
60
  const sig = signal("test");
61
61
  function App({ x }: { x: typeof sig }) {
62
- return h("span", null, x);
62
+ return <span>{x}</span>;
63
63
  }
64
- render(h(App, { x: sig }));
64
+ render(<App x={sig} />);
65
65
 
66
66
  const text = scratch.firstChild!.firstChild!;
67
67
  expect(text).to.have.property("data", "test");
@@ -83,10 +83,10 @@ describe("@preact/signals-react", () => {
83
83
 
84
84
  function App() {
85
85
  const value = sig.value;
86
- return h("p", null, value);
86
+ return <p>{value}</p>;
87
87
  }
88
88
 
89
- render(h(App, {}));
89
+ render(<App />);
90
90
  expect(scratch.textContent).to.equal("foo");
91
91
 
92
92
  act(() => {
@@ -107,10 +107,10 @@ describe("@preact/signals-react", () => {
107
107
  });
108
108
 
109
109
  const str = arr.value.join(", ");
110
- return h("p", null, str);
110
+ return <p>{str}</p>;
111
111
  }
112
112
 
113
- const fn = () => render(h(App, {}));
113
+ const fn = () => render(<App />);
114
114
  expect(fn).not.to.throw;
115
115
  });
116
116
 
@@ -119,16 +119,16 @@ describe("@preact/signals-react", () => {
119
119
 
120
120
  function Child() {
121
121
  const value = sig.value;
122
- return h("p", null, value);
122
+ return <p>{value}</p>;
123
123
  }
124
124
 
125
125
  const spy = sinon.spy();
126
126
  function App() {
127
127
  spy();
128
- return h(Child, null);
128
+ return <Child />;
129
129
  }
130
130
 
131
- render(h(App, {}));
131
+ render(<App />);
132
132
  expect(scratch.textContent).to.equal("foo");
133
133
 
134
134
  act(() => {
@@ -142,15 +142,15 @@ describe("@preact/signals-react", () => {
142
142
 
143
143
  function Inner() {
144
144
  const value = sig.value;
145
- return h("p", null, value);
145
+ return <p>{value}</p>;
146
146
  }
147
147
 
148
148
  function App() {
149
149
  sig.value;
150
- return useMemo(() => h(Inner, { foo: 1 }), []);
150
+ return useMemo(() => <Inner foo={1} />, []);
151
151
  }
152
152
 
153
- render(h(App, {}));
153
+ render(<App />);
154
154
  expect(scratch.textContent).to.equal("foo");
155
155
 
156
156
  act(() => {