@preact/signals 2.4.0 → 2.5.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,27 @@
1
1
  # @preact/signals
2
2
 
3
+ ## 2.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#795](https://github.com/preactjs/signals/pull/795) [`80712b1`](https://github.com/preactjs/signals/commit/80712b188b11b43efe9e95e09b78f57f0551f6eb) Thanks [@rschristian](https://github.com/rschristian)! - Widen utility component types to accept ComponentChildren/ReactNodes as children and fallbacks
8
+
9
+ - [#798](https://github.com/preactjs/signals/pull/798) [`e58734d`](https://github.com/preactjs/signals/commit/e58734d1ad752330c82b0ec949afda3d0cd114d2) Thanks [@marvinhagemeister](https://github.com/marvinhagemeister)! - Fix performance regression by checking if the `@preact/signals-debug` package is enabled only once.
10
+
11
+ - [#800](https://github.com/preactjs/signals/pull/800) [`bc5b573`](https://github.com/preactjs/signals/commit/bc5b573d3e24d1da2b1f91c051f70e57d7be6bc7) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Allow useLiveSignal to accept plain values
12
+
13
+ ## 2.5.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [#792](https://github.com/preactjs/signals/pull/792) [`95dcf41`](https://github.com/preactjs/signals/commit/95dcf41c95baa5d9c6aa8f94c7592722c0cefc3f) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Allow the `when` property of `Show` to be a function so not everything has to be transformed into a boolean computed
18
+
19
+ ### Patch Changes
20
+
21
+ - [#790](https://github.com/preactjs/signals/pull/790) [`4b143a7`](https://github.com/preactjs/signals/commit/4b143a7164d58edda05a23a482f06afc20543234) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Ensure the cached and non-cached shape is the same
22
+
23
+ - [#791](https://github.com/preactjs/signals/pull/791) [`358a758`](https://github.com/preactjs/signals/commit/358a7585a27deff6cf0b804f5f02739b893c7a02) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Prevent `For` cache from expanding infinitely
24
+
3
25
  ## 2.4.0
4
26
 
5
27
  ### Minor Changes
package/dist/signals.js CHANGED
@@ -1 +1 @@
1
- var i,n,t,r=require("preact"),o=require("preact/hooks"),e=require("@preact/signals-core"),f=[],u=[];e.effect(function(){i=this.N})();function a(i,n){r.options[i]=n.bind(null,r.options[i]||function(){})}function c(i){if(t)t();t=i&&i.S()}function s(i){var n=this,t=i.data,f=useSignal(t);f.value=t;var u=o.useMemo(function(){var i=n,t=n.__v;while(t=t.__)if(t.__c){t.__c.__$f|=4;break}var o=e.computed(function(){var i=f.value.value;return 0===i?0:!0===i?"":i||""}),u=e.computed(function(){return!Array.isArray(o.value)&&!r.isValidElement(o.value)}),a=e.effect(function(){this.N=y;if(u.value){var n=o.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=n}}),c=n.__$u.d;n.__$u.d=function(){a();c.call(this)};return[u,o]},[]),a=u[0],c=u[1];return a.value?c.peek():c.value}s.displayName="ReactiveTextNode";Object.defineProperties(e.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:s},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});a("__b",function(i,n){if("function"==typeof n.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof n.type){var t,r=n.props;for(var o in r)if("children"!==o){var f=r[o];if(f instanceof e.Signal){if(!t)n.__np=t={};t[o]=f;r[o]=f.peek()}}}i(n)});a("__r",function(i,t){if("function"==typeof t.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(t);if(t.type!==r.Fragment){c();var o,f=t.__c;if(f){f.__$f&=-2;if(void 0===(o=f.__$u))f.__$u=o=function(i){var n;e.effect(function(){n=this});n.c=function(){f.__$f|=1;f.setState({})};return n}()}n=f;c(o)}i(t)});a("__e",function(i,t,r,o){if("undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();c();n=void 0;i(t,r,o)});a("diffed",function(i,t){if("function"==typeof t.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();c();n=void 0;var r;if("string"==typeof t.type&&(r=t.__e)){var o=t.__np,e=t.props;if(o){var f=r.U;if(f)for(var u in f){var a=f[u];if(void 0!==a&&!(u in o)){a.d();f[u]=void 0}}else{f={};r.U=f}for(var s in o){var d=f[s],p=o[s];if(void 0===d){d=v(r,s,p,e);f[s]=d}else d.o(p,e)}}}i(t)});function v(i,n,t,r){var o=n in i&&void 0===i.ownerSVGElement,f=e.signal(t);return{o:function(i,n){f.value=i;r=n},d:e.effect(function(){this.N=y;var t=f.value.value;if(r[n]!==t){r[n]=t;if(o)i[n]=t;else if(null!=t&&(!1!==t||"-"===n[4]))i.setAttribute(n,t);else i.removeAttribute(n)}})}}a("unmount",function(i,n){if("string"==typeof n.type){var t=n.__e;if(t){var r=t.U;if(r){t.U=void 0;for(var o in r){var e=r[o];if(e)e.d()}}}}else{var f=n.__c;if(f){var u=f.__$u;if(u){f.__$u=void 0;u.d()}}}i(n)});a("__h",function(i,n,t,r){if(r<3||9===r)n.__$f|=2;i(n,t,r)});r.Component.prototype.shouldComponentUpdate=function(i,n){var t=this.__$u,r=t&&void 0!==t.s;for(var o in n)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){var e=2&this.__$f;if(!(r||e||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(r||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var f in i)if("__source"!==f&&i[f]!==this.props[f])return!0;for(var u in this.props)if(!(u in i))return!0;return!1};function useSignal(i,n){return o.useState(function(){return e.signal(i,n)})[0]}var d="undefined"==typeof requestAnimationFrame?setTimeout:function(i){var n=function(){clearTimeout(t);cancelAnimationFrame(r);i()},t=setTimeout(n,35),r=requestAnimationFrame(n)},p=function(i){queueMicrotask(function(){queueMicrotask(i)})};function h(){e.batch(function(){var n;while(n=f.shift())i.call(n)})}function w(){if(1===f.push(this))(r.options.requestAnimationFrame||d)(h)}function l(){e.batch(function(){var n;while(n=u.shift())i.call(n)})}function y(){if(1===u.push(this))(r.options.requestAnimationFrame||p)(l)}exports.Signal=e.Signal;exports.batch=e.batch;exports.computed=e.computed;exports.effect=e.effect;exports.signal=e.signal;exports.untracked=e.untracked;exports.useComputed=function(i,t){var r=o.useRef(i);r.current=i;n.__$f|=4;return o.useMemo(function(){return e.computed(function(){return r.current()},t)},[])};exports.useSignal=useSignal;exports.useSignalEffect=function(i,n){var t=o.useRef(i);t.current=i;o.useEffect(function(){return e.effect(function(){this.N=w;return t.current()},n)},[])};//# sourceMappingURL=signals.js.map
1
+ var i,n,t,r=require("preact"),o=require("preact/hooks"),e=require("@preact/signals-core"),f="undefined"!=typeof window&&!!window.__PREACT_SIGNALS_DEVTOOLS__,u=[],a=[];e.effect(function(){i=this.N})();function c(i,n){r.options[i]=n.bind(null,r.options[i]||function(){})}function s(i){if(t)t();t=i&&i.S()}function v(i){var n=this,t=i.data,f=useSignal(t);f.value=t;var u=o.useMemo(function(){var i=n,t=n.__v;while(t=t.__)if(t.__c){t.__c.__$f|=4;break}var o=e.computed(function(){var i=f.value.value;return 0===i?0:!0===i?"":i||""}),u=e.computed(function(){return!Array.isArray(o.value)&&!r.isValidElement(o.value)}),a=e.effect(function(){this.N=y;if(u.value){var n=o.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=n}}),c=n.__$u.d;n.__$u.d=function(){a();c.call(this)};return[u,o]},[]),a=u[0],c=u[1];return a.value?c.peek():c.value}v.displayName="ReactiveTextNode";Object.defineProperties(e.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:v},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});c("__b",function(i,n){if(f&&"function"==typeof n.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof n.type){var t,r=n.props;for(var o in r)if("children"!==o){var u=r[o];if(u instanceof e.Signal){if(!t)n.__np=t={};t[o]=u;r[o]=u.peek()}}}i(n)});c("__r",function(i,t){if(f&&"function"==typeof t.type)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(t);if(t.type!==r.Fragment){s();var o,u=t.__c;if(u){u.__$f&=-2;if(void 0===(o=u.__$u))u.__$u=o=function(i){var n;e.effect(function(){n=this});n.c=function(){u.__$f|=1;u.setState({})};return n}()}n=u;s(o)}i(t)});c("__e",function(i,t,r,o){if(f)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();s();n=void 0;i(t,r,o)});c("diffed",function(i,t){if(f&&"function"==typeof t.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();s();n=void 0;var r;if("string"==typeof t.type&&(r=t.__e)){var o=t.__np,e=t.props;if(o){var u=r.U;if(u)for(var a in u){var c=u[a];if(void 0!==c&&!(a in o)){c.d();u[a]=void 0}}else{u={};r.U=u}for(var v in o){var h=u[v],p=o[v];if(void 0===h){h=d(r,v,p,e);u[v]=h}else h.o(p,e)}}}i(t)});function d(i,n,t,r){var o=n in i&&void 0===i.ownerSVGElement,f=e.signal(t);return{o:function(i,n){f.value=i;r=n},d:e.effect(function(){this.N=y;var t=f.value.value;if(r[n]!==t){r[n]=t;if(o)i[n]=t;else if(null!=t&&(!1!==t||"-"===n[4]))i.setAttribute(n,t);else i.removeAttribute(n)}})}}c("unmount",function(i,n){if("string"==typeof n.type){var t=n.__e;if(t){var r=t.U;if(r){t.U=void 0;for(var o in r){var e=r[o];if(e)e.d()}}}}else{var f=n.__c;if(f){var u=f.__$u;if(u){f.__$u=void 0;u.d()}}}i(n)});c("__h",function(i,n,t,r){if(r<3||9===r)n.__$f|=2;i(n,t,r)});r.Component.prototype.shouldComponentUpdate=function(i,n){var t=this.__$u,r=t&&void 0!==t.s;for(var o in n)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){var e=2&this.__$f;if(!(r||e||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(r||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var f in i)if("__source"!==f&&i[f]!==this.props[f])return!0;for(var u in this.props)if(!(u in i))return!0;return!1};function useSignal(i,n){return o.useState(function(){return e.signal(i,n)})[0]}var h="undefined"==typeof requestAnimationFrame?setTimeout:function(i){var n=function(){clearTimeout(t);cancelAnimationFrame(r);i()},t=setTimeout(n,35),r=requestAnimationFrame(n)},p=function(i){queueMicrotask(function(){queueMicrotask(i)})};function l(){e.batch(function(){var n;while(n=u.shift())i.call(n)})}function w(){if(1===u.push(this))(r.options.requestAnimationFrame||h)(l)}function _(){e.batch(function(){var n;while(n=a.shift())i.call(n)})}function y(){if(1===a.push(this))(r.options.requestAnimationFrame||p)(_)}exports.Signal=e.Signal;exports.batch=e.batch;exports.computed=e.computed;exports.effect=e.effect;exports.signal=e.signal;exports.untracked=e.untracked;exports.useComputed=function(i,t){var r=o.useRef(i);r.current=i;n.__$f|=4;return o.useMemo(function(){return e.computed(function(){return r.current()},t)},[])};exports.useSignal=useSignal;exports.useSignalEffect=function(i,n){var t=o.useRef(i);t.current=i;o.useEffect(function(){return e.effect(function(){this.N=w;return t.current()},n)},[])};//# sourceMappingURL=signals.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (typeof window !== \"undefined\" && window.__PREACT_SIGNALS_DEVTOOLS__) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","_ref","_this","data","currentSignal","useSignal","value","_useMemo","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","s","isText","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","window","__PREACT_SIGNALS_DEVTOOLS__","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","HAS_PENDING_UPDATE","useState","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","exports","signalsCore","untracked","useComputed","compute","$compute","useRef","current","useSignalEffect","useEffect"],"mappings":"IAqCIA,EAiBAC,EACAC,kFAjBHC,EAA8B,GAC9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M,QAAA1F,SAAA2F,EAAA3F,SAAA0F,QAAArH,OAAAsH,EAAAtH,OAAAqH,QAAAzC,OAAA0C,EAAA1C,OAAAyC,QAAAE,UAAAD,EAAAC,UAAAF,QAAAG,YAtEgB,SAAeC,EAAkBnH,GAChD,IAAMoH,EAAWC,EAAMA,OAACF,GACxBC,EAASE,QAAUH,EAClB7H,EAAwC6B,MAzYpB,EA0YrB,OAAON,UAAQ,kBAAMQ,EAAQA,SAAI,WAAA,OAAM+F,EAASE,SAAS,EAAEtH,EAAQ,EAAE,GACtE,EAiEA+G,QAAArG,UAAAA,UAAAqG,QAAAQ,gBAbgB,SACfjB,EACAtG,GAEA,IAAM+F,EAAWsB,EAAAA,OAAOf,GACxBP,EAASuB,QAAUhB,EAEnBkB,EAAAA,UAAU,WACT,OAAO9H,EAAAA,OAAO,WACbC,KAAKC,EAAUgH,EACf,OAAOb,EAASuB,SACjB,EAAGtH,EACJ,EAAG,GACJ"}
1
+ {"version":3,"file":"signals.js","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst DEVTOOLS_ENABLED =\n\ttypeof window !== \"undefined\" && !!window.__PREACT_SIGNALS_DEVTOOLS__;\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (DEVTOOLS_ENABLED) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","DEVTOOLS_ENABLED","window","__PREACT_SIGNALS_DEVTOOLS__","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","_ref","_this","data","currentSignal","useSignal","value","_useMemo","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","s","isText","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","useState","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","exports","signalsCore","untracked","useComputed","compute","$compute","useRef","current","useSignalEffect","useEffect"],"mappings":"IAwCIA,EAiBAC,EACAC,kFAzBEC,EACa,oBAAXC,UAA4BA,OAAOC,4BAO1CC,EAA8B,GAC9BC,EAA0B,GAK3BC,SAAO,WACNR,EAAYS,KAAKC,CAClB,EAFAF,GAKA,SAASG,EAA6BC,EAAaC,GAElDC,EAAOA,QAACF,GAAYC,EAAOE,KAAK,KAAMD,EAAOA,QAACF,IAAc,WAAO,EACpE,CAKA,SAASI,EAAkBC,GAE1B,GAAIf,EAAcA,IAElBA,EAAee,GAAWA,EAAQC,GACnC,CAwBA,SAASC,EAAWC,GAAqD,IAAAC,EAAAZ,KAAxBa,EAAIF,EAAJE,KAK1CC,EAAgBC,UAAUF,GAChCC,EAAcE,MAAQH,EAEtB,IAAAI,EAAoBC,EAAOA,QAAC,WAC3B,IAAIC,EAAOP,EAE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C,EAAU6G,EACf,OAAOb,EAASuB,SACjB,EAAGnH,EACJ,EAAG,GACJ"}
@@ -1 +1 @@
1
- !function(i,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("preact"),require("preact/hooks"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","preact","preact/hooks","@preact/signals-core"],n):n((i||self).preactSignals={},i.preact,i.preactHooks,i.preactSignalsCore)}(this,function(i,n,t,e){var r,o,f,u=[],a=[];e.effect(function(){r=this.N})();function c(i,t){n.options[i]=t.bind(null,n.options[i]||function(){})}function s(i){if(f)f();f=i&&i.S()}function v(i){var r=this,o=i.data,f=useSignal(o);f.value=o;var u=t.useMemo(function(){var i=r,t=r.__v;while(t=t.__)if(t.__c){t.__c.__$f|=4;break}var o=e.computed(function(){var i=f.value.value;return 0===i?0:!0===i?"":i||""}),u=e.computed(function(){return!Array.isArray(o.value)&&!n.isValidElement(o.value)}),a=e.effect(function(){this.N=_;if(u.value){var n=o.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=n}}),c=r.__$u.d;r.__$u.d=function(){a();c.call(this)};return[u,o]},[]),a=u[0],c=u[1];return a.value?c.peek():c.value}v.displayName="ReactiveTextNode";Object.defineProperties(e.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:v},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});c("__b",function(i,n){if("function"==typeof n.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof n.type){var t,r=n.props;for(var o in r)if("children"!==o){var f=r[o];if(f instanceof e.Signal){if(!t)n.__np=t={};t[o]=f;r[o]=f.peek()}}}i(n)});c("__r",function(i,t){if("function"==typeof t.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(t);if(t.type!==n.Fragment){s();var r,f=t.__c;if(f){f.__$f&=-2;if(void 0===(r=f.__$u))f.__$u=r=function(i){var n;e.effect(function(){n=this});n.c=function(){f.__$f|=1;f.setState({})};return n}()}o=f;s(r)}i(t)});c("__e",function(i,n,t,e){if("undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();s();o=void 0;i(n,t,e)});c("diffed",function(i,n){if("function"==typeof n.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();s();o=void 0;var t;if("string"==typeof n.type&&(t=n.__e)){var e=n.__np,r=n.props;if(e){var f=t.U;if(f)for(var u in f){var a=f[u];if(void 0!==a&&!(u in e)){a.d();f[u]=void 0}}else{f={};t.U=f}for(var c in e){var v=f[c],l=e[c];if(void 0===v){v=d(t,c,l,r);f[c]=v}else v.o(l,r)}}}i(n)});function d(i,n,t,r){var o=n in i&&void 0===i.ownerSVGElement,f=e.signal(t);return{o:function(i,n){f.value=i;r=n},d:e.effect(function(){this.N=_;var t=f.value.value;if(r[n]!==t){r[n]=t;if(o)i[n]=t;else if(null!=t&&(!1!==t||"-"===n[4]))i.setAttribute(n,t);else i.removeAttribute(n)}})}}c("unmount",function(i,n){if("string"==typeof n.type){var t=n.__e;if(t){var e=t.U;if(e){t.U=void 0;for(var r in e){var o=e[r];if(o)o.d()}}}}else{var f=n.__c;if(f){var u=f.__$u;if(u){f.__$u=void 0;u.d()}}}i(n)});c("__h",function(i,n,t,e){if(e<3||9===e)n.__$f|=2;i(n,t,e)});n.Component.prototype.shouldComponentUpdate=function(i,n){var t=this.__$u,e=t&&void 0!==t.s;for(var r in n)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){var o=2&this.__$f;if(!(e||o||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(e||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var f in i)if("__source"!==f&&i[f]!==this.props[f])return!0;for(var u in this.props)if(!(u in i))return!0;return!1};function useSignal(i,n){return t.useState(function(){return e.signal(i,n)})[0]}var l="undefined"==typeof requestAnimationFrame?setTimeout:function(i){var n=function(){clearTimeout(t);cancelAnimationFrame(e);i()},t=setTimeout(n,35),e=requestAnimationFrame(n)},h=function(i){queueMicrotask(function(){queueMicrotask(i)})};function p(){e.batch(function(){var i;while(i=u.shift())r.call(i)})}function w(){if(1===u.push(this))(n.options.requestAnimationFrame||l)(p)}function y(){e.batch(function(){var i;while(i=a.shift())r.call(i)})}function _(){if(1===a.push(this))(n.options.requestAnimationFrame||h)(y)}i.Signal=e.Signal;i.batch=e.batch;i.computed=e.computed;i.effect=e.effect;i.signal=e.signal;i.untracked=e.untracked;i.useComputed=function(i,n){var r=t.useRef(i);r.current=i;o.__$f|=4;return t.useMemo(function(){return e.computed(function(){return r.current()},n)},[])};i.useSignal=useSignal;i.useSignalEffect=function(i,n){var r=t.useRef(i);r.current=i;t.useEffect(function(){return e.effect(function(){this.N=w;return r.current()},n)},[])}});//# sourceMappingURL=signals.min.js.map
1
+ !function(i,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("preact"),require("preact/hooks"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","preact","preact/hooks","@preact/signals-core"],n):n((i||self).preactSignals={},i.preact,i.preactHooks,i.preactSignalsCore)}(this,function(i,n,t,r){var e,f,o,u="undefined"!=typeof window&&!!window.__PREACT_SIGNALS_DEVTOOLS__,a=[],c=[];r.effect(function(){e=this.N})();function s(i,t){n.options[i]=t.bind(null,n.options[i]||function(){})}function v(i){if(o)o();o=i&&i.S()}function d(i){var e=this,f=i.data,o=useSignal(f);o.value=f;var u=t.useMemo(function(){var i=e,t=e.__v;while(t=t.__)if(t.__c){t.__c.__$f|=4;break}var f=r.computed(function(){var i=o.value.value;return 0===i?0:!0===i?"":i||""}),u=r.computed(function(){return!Array.isArray(f.value)&&!n.isValidElement(f.value)}),a=r.effect(function(){this.N=b;if(u.value){var n=f.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=n}}),c=e.__$u.d;e.__$u.d=function(){a();c.call(this)};return[u,f]},[]),a=u[0],c=u[1];return a.value?c.peek():c.value}d.displayName="ReactiveTextNode";Object.defineProperties(r.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:d},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});s("__b",function(i,n){if(u&&"function"==typeof n.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof n.type){var t,e=n.props;for(var f in e)if("children"!==f){var o=e[f];if(o instanceof r.Signal){if(!t)n.__np=t={};t[f]=o;e[f]=o.peek()}}}i(n)});s("__r",function(i,t){if(u&&"function"==typeof t.type)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(t);if(t.type!==n.Fragment){v();var e,o=t.__c;if(o){o.__$f&=-2;if(void 0===(e=o.__$u))o.__$u=e=function(i){var n;r.effect(function(){n=this});n.c=function(){o.__$f|=1;o.setState({})};return n}()}f=o;v(e)}i(t)});s("__e",function(i,n,t,r){if(u)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();v();f=void 0;i(n,t,r)});s("diffed",function(i,n){if(u&&"function"==typeof n.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();v();f=void 0;var t;if("string"==typeof n.type&&(t=n.__e)){var r=n.__np,e=n.props;if(r){var o=t.U;if(o)for(var a in o){var c=o[a];if(void 0!==c&&!(a in r)){c.d();o[a]=void 0}}else{o={};t.U=o}for(var s in r){var d=o[s],h=r[s];if(void 0===d){d=l(t,s,h,e);o[s]=d}else d.o(h,e)}}}i(n)});function l(i,n,t,e){var f=n in i&&void 0===i.ownerSVGElement,o=r.signal(t);return{o:function(i,n){o.value=i;e=n},d:r.effect(function(){this.N=b;var t=o.value.value;if(e[n]!==t){e[n]=t;if(f)i[n]=t;else if(null!=t&&(!1!==t||"-"===n[4]))i.setAttribute(n,t);else i.removeAttribute(n)}})}}s("unmount",function(i,n){if("string"==typeof n.type){var t=n.__e;if(t){var r=t.U;if(r){t.U=void 0;for(var e in r){var f=r[e];if(f)f.d()}}}}else{var o=n.__c;if(o){var u=o.__$u;if(u){o.__$u=void 0;u.d()}}}i(n)});s("__h",function(i,n,t,r){if(r<3||9===r)n.__$f|=2;i(n,t,r)});n.Component.prototype.shouldComponentUpdate=function(i,n){var t=this.__$u,r=t&&void 0!==t.s;for(var e in n)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){var f=2&this.__$f;if(!(r||f||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(r||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var o in i)if("__source"!==o&&i[o]!==this.props[o])return!0;for(var u in this.props)if(!(u in i))return!0;return!1};function useSignal(i,n){return t.useState(function(){return r.signal(i,n)})[0]}var h="undefined"==typeof requestAnimationFrame?setTimeout:function(i){var n=function(){clearTimeout(t);cancelAnimationFrame(r);i()},t=setTimeout(n,35),r=requestAnimationFrame(n)},p=function(i){queueMicrotask(function(){queueMicrotask(i)})};function w(){r.batch(function(){var i;while(i=a.shift())e.call(i)})}function y(){if(1===a.push(this))(n.options.requestAnimationFrame||h)(w)}function _(){r.batch(function(){var i;while(i=c.shift())e.call(i)})}function b(){if(1===c.push(this))(n.options.requestAnimationFrame||p)(_)}i.Signal=r.Signal;i.batch=r.batch;i.computed=r.computed;i.effect=r.effect;i.signal=r.signal;i.untracked=r.untracked;i.useComputed=function(i,n){var e=t.useRef(i);e.current=i;f.__$f|=4;return t.useMemo(function(){return r.computed(function(){return e.current()},n)},[])};i.useSignal=useSignal;i.useSignalEffect=function(i,n){var e=t.useRef(i);e.current=i;t.useEffect(function(){return r.effect(function(){this.N=y;return e.current()},n)},[])}});//# sourceMappingURL=signals.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.min.js","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (typeof window !== \"undefined\" && window.__PREACT_SIGNALS_DEVTOOLS__) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","_ref","_this","data","currentSignal","useSignal","value","_useMemo","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","s","isText","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","window","__PREACT_SIGNALS_DEVTOOLS__","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","HAS_PENDING_UPDATE","useState","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","exports","signalsCore","untracked","useComputed","compute","$compute","useRef","current","useSignalEffect","useEffect"],"mappings":"iZAiCA,IAIIA,EAiBAC,EACAC,EAjBHC,EAA8B,GAC9BC,EAA0B,GAK3BC,EAAAA,OAAO,WACNL,EAAYM,KAAKC,CAClB,EAFAF,GAKA,SAASG,EAA6BC,EAAaC,GAElDC,EAAAA,QAAQF,GAAYC,EAAOE,KAAK,KAAMD,EAAAA,QAAQF,IAAc,WAAS,EACtE,CAKA,SAASI,EAAkBC,GAE1B,GAAIZ,EAAcA,IAElBA,EAAeY,GAAWA,EAAQC,GACnC,CAwBA,SAASC,EAAWC,GAAqD,IAAAC,EAAAZ,KAAxBa,EAAIF,EAAJE,KAK1CC,EAAgBC,UAAUF,GAChCC,EAAcE,MAAQH,EAEtB,IAAAI,EAAoBC,EAAAA,QAAQ,WAC3B,IAAIC,EAAOP,EAEPQ,EAAIR,EAAKS,IACb,MAAQD,EAAIA,EAAEE,GACb,GAAIF,EAAEG,IAAK,CACVH,EAAEG,IAAIC,MAjEY,EAkElB,KACD,CAGD,IAAMC,EAAgBC,EAAQA,SAAC,WAC9B,IAAIC,EAAIb,EAAcE,MAAMA,MAC5B,OAAa,IAANW,EAAU,GAAU,IAANA,EAAa,GAAKA,GAAK,EAC7C,GAEMC,EAASF,EAAAA,SACd,WACC,OAACG,MAAMC,QAAQL,EAAcT,SAC5Be,EAAAA,eAAeN,EAAcT,MAAM,GAIhCgB,EAAUjC,EAAAA,OAAO,WACtBC,KAAKC,EAAUgC,EAGf,GAAIL,EAAOZ,MAAO,CAIjB,IAAMA,EAAQS,EAAcT,MAC5B,GAAIG,EAAKE,KAAOF,EAAKE,IAAIa,KAAiC,IAA1Bf,EAAKE,IAAIa,IAAIC,SAC3ChB,EAAKE,IAAIa,IAAarB,KAA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C,EACJ,MAAQA,EAAOjH,EAASkH,QACvBtH,EAAU6C,KAAKwE,EAEjB,EACD,CAEA,SAAS9E,IACR,GAA4B,IAAxBnC,EAASoH,KAAKlH,OAChBK,EAAAA,QAAQ6F,uBAAyBQ,GAAiBS,EAErD,CAeAC,EAAAxE,OAAAyE,EAAAzE,OAAAwE,EAAAN,MAAAO,EAAAP,MAAAM,EAAA1F,SAAA2F,EAAA3F,SAAA0F,EAAArH,OAAAsH,EAAAtH,OAAAqH,EAAAzC,OAAA0C,EAAA1C,OAAAyC,EAAAE,UAAAD,EAAAC,UAAAF,EAAAG,YAtEgB,SAAeC,EAAkBnH,GAChD,IAAMoH,EAAWC,EAAMA,OAACF,GACxBC,EAASE,QAAUH,EAClB7H,EAAwC6B,MAzYpB,EA0YrB,OAAON,UAAQ,kBAAMQ,EAAQA,SAAI,WAAA,OAAM+F,EAASE,SAAS,EAAEtH,EAAQ,EAAE,GACtE,EAiEA+G,EAAArG,UAAAA,UAAAqG,EAAAQ,gBAbgB,SACfjB,EACAtG,GAEA,IAAM+F,EAAWsB,EAAAA,OAAOf,GACxBP,EAASuB,QAAUhB,EAEnBkB,EAAAA,UAAU,WACT,OAAO9H,EAAAA,OAAO,WACbC,KAAKC,EAAUgH,EACf,OAAOb,EAASuB,SACjB,EAAGtH,EACJ,EAAG,GACJ,CAAA"}
1
+ {"version":3,"file":"signals.min.js","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst DEVTOOLS_ENABLED =\n\ttypeof window !== \"undefined\" && !!window.__PREACT_SIGNALS_DEVTOOLS__;\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (DEVTOOLS_ENABLED) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","DEVTOOLS_ENABLED","window","__PREACT_SIGNALS_DEVTOOLS__","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","_ref","_this","data","currentSignal","useSignal","value","_useMemo","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","s","isText","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","useState","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","exports","signalsCore","untracked","useComputed","compute","$compute","useRef","current","useSignalEffect","useEffect"],"mappings":"iZAiCA,IAOIA,EAiBAC,EACAC,EAzBEC,EACa,oBAAXC,UAA4BA,OAAOC,4BAO1CC,EAA8B,GAC9BC,EAA0B,GAK3BC,SAAO,WACNR,EAAYS,KAAKC,CAClB,EAFAF,GAKA,SAASG,EAA6BC,EAAaC,GAElDC,EAAOA,QAACF,GAAYC,EAAOE,KAAK,KAAMD,EAAOA,QAACF,IAAc,WAAO,EACp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AAQA,SAAI,WAAM,OAAA4F,EAASE,SAAS,EAAEnH,EAAQ,EAAE,GACtE,EAiEA4G,EAAAlG,UAAAA,UAAAkG,EAAAQ,gBAbgB,SACfjB,EACAnG,GAEA,IAAM4F,EAAWsB,EAAAA,OAAOf,GACxBP,EAASuB,QAAUhB,EAEnBkB,EAAAA,UAAU,WACT,OAAO3H,EAAAA,OAAO,WACbC,KAAKC,EAAU6G,EACf,OAAOb,EAASuB,SACjB,EAAGnH,EACJ,EAAG,GACJ,CAAA"}
package/dist/signals.mjs CHANGED
@@ -1 +1 @@
1
- import{Component as i,options as t,isValidElement as n,Fragment as e}from"preact";import{useMemo as o,useState as f,useRef as r,useEffect as u}from"preact/hooks";import{effect as s,Signal as c,computed as l,signal as d,batch as a}from"@preact/signals-core";export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";let h,p,w,m=[],v=[];s(function(){h=this.N})();function y(i,n){t[i]=n.bind(null,t[i]||(()=>{}))}function _(i){if(w)w();w=i&&i.S()}function g({data:i}){const t=useSignal(i);t.value=i;const[e,f]=o(()=>{let i=this,e=this.__v;while(e=e.__)if(e.__c){e.__c.__$f|=4;break}const o=l(()=>{let i=t.value.value;return 0===i?0:!0===i?"":i||""}),f=l(()=>!Array.isArray(o.value)&&!n(o.value)),r=s(function(){this.N=F;if(f.value){const t=o.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=t}}),u=this.__$u.d;this.__$u.d=function(){r();u.call(this)};return[f,o]},[]);return e.value?f.peek():f.value}g.displayName="ReactiveTextNode";Object.defineProperties(c.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:g},props:{configurable:!0,get(){return{data:this}}},__b:{configurable:!0,value:1}});y("__b",(i,t)=>{if("function"==typeof t.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof t.type){let i,n=t.props;for(let e in n){if("children"===e)continue;let o=n[e];if(o instanceof c){if(!i)t.__np=i={};i[e]=o;n[e]=o.peek()}}}i(t)});y("__r",(i,t)=>{if("function"==typeof t.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(t);if(t.type!==e){_();let i,n=t.__c;if(n){n.__$f&=-2;i=n.__$u;if(void 0===i)n.__$u=i=function(i){let t;s(function(){t=this});t.c=()=>{n.__$f|=1;n.setState({})};return t}()}p=n;_(i)}i(t)});y("__e",(i,t,n,e)=>{if("undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();_();p=void 0;i(t,n,e)});y("diffed",(i,t)=>{if("function"==typeof t.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();_();p=void 0;let n;if("string"==typeof t.type&&(n=t.__e)){let i=t.__np,e=t.props;if(i){let t=n.U;if(t)for(let n in t){let e=t[n];if(void 0!==e&&!(n in i)){e.d();t[n]=void 0}}else{t={};n.U=t}for(let o in i){let f=t[o],r=i[o];if(void 0===f){f=b(n,o,r,e);t[o]=f}else f.o(r,e)}}}i(t)});function b(i,t,n,e){const o=t in i&&void 0===i.ownerSVGElement,f=d(n);return{o:(i,t)=>{f.value=i;e=t},d:s(function(){this.N=F;const n=f.value.value;if(e[t]!==n){e[t]=n;if(o)i[t]=n;else if(null!=n&&(!1!==n||"-"===t[4]))i.setAttribute(t,n);else i.removeAttribute(t)}})}}y("unmount",(i,t)=>{if("string"==typeof t.type){let i=t.__e;if(i){const t=i.U;if(t){i.U=void 0;for(let i in t){let n=t[i];if(n)n.d()}}}}else{let i=t.__c;if(i){const t=i.__$u;if(t){i.__$u=void 0;t.d()}}}i(t)});y("__h",(i,t,n,e)=>{if(e<3||9===e)t.__$f|=2;i(t,n,e)});i.prototype.shouldComponentUpdate=function(i,t){const n=this.__$u,e=n&&void 0!==n.s;for(let i in t)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){const i=2&this.__$f;if(!(e||i||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(e||4&this.__$f))return!0;if(3&this.__$f)return!0}for(let t in i)if("__source"!==t&&i[t]!==this.props[t])return!0;for(let t in this.props)if(!(t in i))return!0;return!1};function useSignal(i,t){return f(()=>d(i,t))[0]}function useComputed(i,t){const n=r(i);n.current=i;p.__$f|=4;return o(()=>l(()=>n.current(),t),[])}const k="undefined"==typeof requestAnimationFrame?setTimeout:function(i){const t=()=>{clearTimeout(n);cancelAnimationFrame(e);i()},n=setTimeout(t,35),e=requestAnimationFrame(t)},q=i=>{queueMicrotask(()=>{queueMicrotask(i)})};function A(){a(()=>{let i;while(i=m.shift())h.call(i)})}function T(){if(1===m.push(this))(t.requestAnimationFrame||k)(A)}function x(){a(()=>{let i;while(i=v.shift())h.call(i)})}function F(){if(1===v.push(this))(t.requestAnimationFrame||q)(x)}function useSignalEffect(i,t){const n=r(i);n.current=i;u(()=>s(function(){this.N=T;return n.current()},t),[])}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.mjs.map
1
+ import{Component as t,options as i,isValidElement as n,Fragment as e}from"preact";import{useMemo as o,useState as f,useRef as r,useEffect as u}from"preact/hooks";import{effect as s,Signal as c,computed as l,signal as a,batch as d}from"@preact/signals-core";export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";const h="undefined"!=typeof window&&!!window.__PREACT_SIGNALS_DEVTOOLS__;let p,m,v,w=[],_=[];s(function(){p=this.N})();function g(t,n){i[t]=n.bind(null,i[t]||(()=>{}))}function y(t){if(v)v();v=t&&t.S()}function b({data:t}){const i=useSignal(t);i.value=t;const[e,f]=o(()=>{let t=this,e=this.__v;while(e=e.__)if(e.__c){e.__c.__$f|=4;break}const o=l(()=>{let t=i.value.value;return 0===t?0:!0===t?"":t||""}),f=l(()=>!Array.isArray(o.value)&&!n(o.value)),r=s(function(){this.N=M;if(f.value){const i=o.value;if(t.__v&&t.__v.__e&&3===t.__v.__e.nodeType)t.__v.__e.data=i}}),u=this.__$u.d;this.__$u.d=function(){r();u.call(this)};return[f,o]},[]);return e.value?f.peek():f.value}b.displayName="ReactiveTextNode";Object.defineProperties(c.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:b},props:{configurable:!0,get(){return{data:this}}},__b:{configurable:!0,value:1}});g("__b",(t,i)=>{if(h&&"function"==typeof i.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof i.type){let t,n=i.props;for(let e in n){if("children"===e)continue;let o=n[e];if(o instanceof c){if(!t)i.__np=t={};t[e]=o;n[e]=o.peek()}}}t(i)});g("__r",(t,i)=>{if(h&&"function"==typeof i.type)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(i);if(i.type!==e){y();let t,n=i.__c;if(n){n.__$f&=-2;t=n.__$u;if(void 0===t)n.__$u=t=function(t){let i;s(function(){i=this});i.c=()=>{n.__$f|=1;n.setState({})};return i}()}m=n;y(t)}t(i)});g("__e",(t,i,n,e)=>{if(h)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();y();m=void 0;t(i,n,e)});g("diffed",(t,i)=>{if(h&&"function"==typeof i.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();y();m=void 0;let n;if("string"==typeof i.type&&(n=i.__e)){let t=i.__np,e=i.props;if(t){let i=n.U;if(i)for(let n in i){let e=i[n];if(void 0!==e&&!(n in t)){e.d();i[n]=void 0}}else{i={};n.U=i}for(let o in t){let f=i[o],r=t[o];if(void 0===f){f=k(n,o,r,e);i[o]=f}else f.o(r,e)}}}t(i)});function k(t,i,n,e){const o=i in t&&void 0===t.ownerSVGElement,f=a(n);return{o:(t,i)=>{f.value=t;e=i},d:s(function(){this.N=M;const n=f.value.value;if(e[i]!==n){e[i]=n;if(o)t[i]=n;else if(null!=n&&(!1!==n||"-"===i[4]))t.setAttribute(i,n);else t.removeAttribute(i)}})}}g("unmount",(t,i)=>{if("string"==typeof i.type){let t=i.__e;if(t){const i=t.U;if(i){t.U=void 0;for(let t in i){let n=i[t];if(n)n.d()}}}}else{let t=i.__c;if(t){const i=t.__$u;if(i){t.__$u=void 0;i.d()}}}t(i)});g("__h",(t,i,n,e)=>{if(e<3||9===e)i.__$f|=2;t(i,n,e)});t.prototype.shouldComponentUpdate=function(t,i){const n=this.__$u,e=n&&void 0!==n.s;for(let t in i)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){const t=2&this.__$f;if(!(e||t||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(e||4&this.__$f))return!0;if(3&this.__$f)return!0}for(let i in t)if("__source"!==i&&t[i]!==this.props[i])return!0;for(let i in this.props)if(!(i in t))return!0;return!1};function useSignal(t,i){return f(()=>a(t,i))[0]}function useComputed(t,i){const n=r(t);n.current=t;m.__$f|=4;return o(()=>l(()=>n.current(),i),[])}const q="undefined"==typeof requestAnimationFrame?setTimeout:function(t){const i=()=>{clearTimeout(n);cancelAnimationFrame(e);t()},n=setTimeout(i,35),e=requestAnimationFrame(i)},A=t=>{queueMicrotask(()=>{queueMicrotask(t)})};function T(){d(()=>{let t;while(t=w.shift())p.call(t)})}function x(){if(1===w.push(this))(i.requestAnimationFrame||q)(T)}function F(){d(()=>{let t;while(t=_.shift())p.call(t)})}function M(){if(1===_.push(this))(i.requestAnimationFrame||A)(F)}function useSignalEffect(t,i){const n=r(t);n.current=t;u(()=>s(function(){this.N=x;return n.current()},i),[])}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (typeof window !== \"undefined\" && window.__PREACT_SIGNALS_DEVTOOLS__) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","data","currentSignal","useSignal","value","isText","s","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","window","__PREACT_SIGNALS_DEVTOOLS__","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","HAS_PENDING_UPDATE","useState","useComputed","compute","$compute","useRef","current","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","useSign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ACxBP,EAASJ,QAAUW,EAEnBU,EAAU,IACFxH,EAAO,WACbC,KAAKC,EAAUkH,EACf,OAAOb,EAASJ,SACjB,EAAG7F,GACD,GACJ,QAAAyF,YAAAjF,UAAAyG"}
1
+ {"version":3,"file":"signals.mjs","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst DEVTOOLS_ENABLED =\n\ttypeof window !== \"undefined\" && !!window.__PREACT_SIGNALS_DEVTOOLS__;\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (DEVTOOLS_ENABLED) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["DEVTOOLS_ENABLED","window","__PREACT_SIGNALS_DEVTOOLS__","oldNotify","currentComponent","finishUpdate","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","data","currentSignal","useSignal","value","isText","s","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","HAS_PENDING_UPDATE","useState","useComputed","compute","$compute","useRef","current","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","useSignalEffect","useEffect"],"mappings":"iVAiCA,MAAMA,EACa,oBAAXC,UAA4BA,OAAOC,4BAM3C,IAAIC,EAiBAC,EACAC,EAjBHC,EAA8B,GAC9BC,EAA0B,GAK3BC,EAAO,WACNL,EAAYM,KAAKC,CAClB,EAFAF,GAKA,SAASG,EAA6BC,EAAaC,GAElDC,EAAQF,GAAYC,EAAOE,KAAK,KAAMD,EAAQF,UAAsB,GACrE,CAKA,SAASI,EAAkBC,GAE1B,GAAIZ,EAAcA,IAElBA,EAAeY,GAAWA,EAAQC,GACnC,CAwBA,SAASC,GAAsCC,KAAEA,IAKhD,MAAMC,EAAgBC,UAAUF,GAChCC,EAAcE,MAAQH,EAEtB,MAAOI,EAAQC,GAAKC,EAAQ,KAC3B,IAAIC,EAAOlB,KAEPmB,EAAInB,KAAKoB,IACb,MAAQD,EAAIA,EAAEE,GACb,GAAIF,EAAEG,IAAK,CACVH,EAAEG,IAAIC,MAjEY,EAkElB,KACD,CAGD,MAAMC,EAAgBC,EAAS,KAC9B,IAAIT,EAAIJ,EAAcE,MAAMA,MAC5B,OAAa,IAANE,EAAU,GAAU,IAANA,EAAa,GAAKA,GAAK,KAGvCD,EAASU,EACd,KACEC,MAAMC,QAAQH,EAAcV,SAC5Bc,EAAeJ,EAAcV,QAI1Be,EAAU9B,EAAO,WACtBC,KAAKC,EAAU6B,EAGf,GAAIf,EAAOD,MAAO,CAIjB,MAAMA,EAAQU,EAAcV,MAC5B,GAAII,EAAKE,KAAOF,EAAKE,IAAIW,KAAiC,IAA1Bb,EAAKE,IAAIW,IAAIC,SAC3C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AAM,KACL,IAAIC,EACJ,MAAQA,EAAOjH,EAASkH,QACvBtH,EAAU0C,KAAK2E,EAChB,EAEF,CAEA,SAASjF,IACR,GAA4B,IAAxBhC,EAASoH,KAAKlH,OAChBK,EAAQ6F,uBAAyBQ,GAAiBS,EAErD,CAEgB,SAAAC,gBACfT,EACAtG,GAEA,MAAM+F,EAAWL,EAAOY,GACxBP,EAASJ,QAAUW,EAEnBU,EAAU,IACFtH,EAAO,WACbC,KAAKC,EAAUgH,EACf,OAAOb,EAASJ,SACjB,EAAG3F,GACD,GACJ,QAAAuF,YAAA/E,UAAAuG"}
@@ -1 +1 @@
1
- import{Component as i,options as n,isValidElement as t,Fragment as r}from"preact";import{useMemo as o,useState as f,useRef as e,useEffect as u}from"preact/hooks";import{effect as a,Signal as c,computed as v,signal as s,batch as d}from"@preact/signals-core";export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";var h,l,p,w=[],m=[];a(function(){h=this.N})();function y(i,t){n[i]=t.bind(null,n[i]||function(){})}function _(i){if(p)p();p=i&&i.S()}function g(i){var n=this,r=i.data,f=useSignal(r);f.value=r;var e=o(function(){var i=n,r=n.__v;while(r=r.__)if(r.__c){r.__c.__$f|=4;break}var o=v(function(){var i=f.value.value;return 0===i?0:!0===i?"":i||""}),e=v(function(){return!Array.isArray(o.value)&&!t(o.value)}),u=a(function(){this.N=F;if(e.value){var n=o.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=n}}),c=n.__$u.d;n.__$u.d=function(){u();c.call(this)};return[e,o]},[]),u=e[0],c=e[1];return u.value?c.peek():c.value}g.displayName="ReactiveTextNode";Object.defineProperties(c.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:g},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});y("__b",function(i,n){if("function"==typeof n.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof n.type){var t,r=n.props;for(var o in r)if("children"!==o){var f=r[o];if(f instanceof c){if(!t)n.__np=t={};t[o]=f;r[o]=f.peek()}}}i(n)});y("__r",function(i,n){if("function"==typeof n.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(n);if(n.type!==r){_();var t,o=n.__c;if(o){o.__$f&=-2;if(void 0===(t=o.__$u))o.__$u=t=function(i){var n;a(function(){n=this});n.c=function(){o.__$f|=1;o.setState({})};return n}()}l=o;_(t)}i(n)});y("__e",function(i,n,t,r){if("undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();_();l=void 0;i(n,t,r)});y("diffed",function(i,n){if("function"==typeof n.type&&"undefined"!=typeof window&&window.__PREACT_SIGNALS_DEVTOOLS__)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();_();l=void 0;var t;if("string"==typeof n.type&&(t=n.__e)){var r=n.__np,o=n.props;if(r){var f=t.U;if(f)for(var e in f){var u=f[e];if(void 0!==u&&!(e in r)){u.d();f[e]=void 0}}else{f={};t.U=f}for(var a in r){var c=f[a],v=r[a];if(void 0===c){c=b(t,a,v,o);f[a]=c}else c.o(v,o)}}}i(n)});function b(i,n,t,r){var o=n in i&&void 0===i.ownerSVGElement,f=s(t);return{o:function(i,n){f.value=i;r=n},d:a(function(){this.N=F;var t=f.value.value;if(r[n]!==t){r[n]=t;if(o)i[n]=t;else if(null!=t&&(!1!==t||"-"===n[4]))i.setAttribute(n,t);else i.removeAttribute(n)}})}}y("unmount",function(i,n){if("string"==typeof n.type){var t=n.__e;if(t){var r=t.U;if(r){t.U=void 0;for(var o in r){var f=r[o];if(f)f.d()}}}}else{var e=n.__c;if(e){var u=e.__$u;if(u){e.__$u=void 0;u.d()}}}i(n)});y("__h",function(i,n,t,r){if(r<3||9===r)n.__$f|=2;i(n,t,r)});i.prototype.shouldComponentUpdate=function(i,n){var t=this.__$u,r=t&&void 0!==t.s;for(var o in n)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){var f=2&this.__$f;if(!(r||f||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(r||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var e in i)if("__source"!==e&&i[e]!==this.props[e])return!0;for(var u in this.props)if(!(u in i))return!0;return!1};function useSignal(i,n){return f(function(){return s(i,n)})[0]}function useComputed(i,n){var t=e(i);t.current=i;l.__$f|=4;return o(function(){return v(function(){return t.current()},n)},[])}var k="undefined"==typeof requestAnimationFrame?setTimeout:function(i){var n=function(){clearTimeout(t);cancelAnimationFrame(r);i()},t=setTimeout(n,35),r=requestAnimationFrame(n)},q=function(i){queueMicrotask(function(){queueMicrotask(i)})};function A(){d(function(){var i;while(i=w.shift())h.call(i)})}function T(){if(1===w.push(this))(n.requestAnimationFrame||k)(A)}function x(){d(function(){var i;while(i=m.shift())h.call(i)})}function F(){if(1===m.push(this))(n.requestAnimationFrame||q)(x)}function useSignalEffect(i,n){var t=e(i);t.current=i;u(function(){return a(function(){this.N=T;return t.current()},n)},[])}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
1
+ import{Component as i,options as n,isValidElement as t,Fragment as r}from"preact";import{useMemo as f,useState as o,useRef as e,useEffect as u}from"preact/hooks";import{effect as a,Signal as c,computed as v,signal as s,batch as d}from"@preact/signals-core";export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";var h,l,p,m="undefined"!=typeof window&&!!window.__PREACT_SIGNALS_DEVTOOLS__,w=[],_=[];a(function(){h=this.N})();function g(i,t){n[i]=t.bind(null,n[i]||function(){})}function y(i){if(p)p();p=i&&i.S()}function b(i){var n=this,r=i.data,o=useSignal(r);o.value=r;var e=f(function(){var i=n,r=n.__v;while(r=r.__)if(r.__c){r.__c.__$f|=4;break}var f=v(function(){var i=o.value.value;return 0===i?0:!0===i?"":i||""}),e=v(function(){return!Array.isArray(f.value)&&!t(f.value)}),u=a(function(){this.N=M;if(e.value){var n=f.value;if(i.__v&&i.__v.__e&&3===i.__v.__e.nodeType)i.__v.__e.data=n}}),c=n.__$u.d;n.__$u.d=function(){u();c.call(this)};return[e,f]},[]),u=e[0],c=e[1];return u.value?c.peek():c.value}b.displayName="ReactiveTextNode";Object.defineProperties(c.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:b},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});g("__b",function(i,n){if(m&&"function"==typeof n.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();if("string"==typeof n.type){var t,r=n.props;for(var f in r)if("children"!==f){var o=r[f];if(o instanceof c){if(!t)n.__np=t={};t[f]=o;r[f]=o.peek()}}}i(n)});g("__r",function(i,n){if(m&&"function"==typeof n.type)window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(n);if(n.type!==r){y();var t,f=n.__c;if(f){f.__$f&=-2;if(void 0===(t=f.__$u))f.__$u=t=function(i){var n;a(function(){n=this});n.c=function(){f.__$f|=1;f.setState({})};return n}()}l=f;y(t)}i(n)});g("__e",function(i,n,t,r){if(m)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();y();l=void 0;i(n,t,r)});g("diffed",function(i,n){if(m&&"function"==typeof n.type)window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();y();l=void 0;var t;if("string"==typeof n.type&&(t=n.__e)){var r=n.__np,f=n.props;if(r){var o=t.U;if(o)for(var e in o){var u=o[e];if(void 0!==u&&!(e in r)){u.d();o[e]=void 0}}else{o={};t.U=o}for(var a in r){var c=o[a],v=r[a];if(void 0===c){c=k(t,a,v,f);o[a]=c}else c.o(v,f)}}}i(n)});function k(i,n,t,r){var f=n in i&&void 0===i.ownerSVGElement,o=s(t);return{o:function(i,n){o.value=i;r=n},d:a(function(){this.N=M;var t=o.value.value;if(r[n]!==t){r[n]=t;if(f)i[n]=t;else if(null!=t&&(!1!==t||"-"===n[4]))i.setAttribute(n,t);else i.removeAttribute(n)}})}}g("unmount",function(i,n){if("string"==typeof n.type){var t=n.__e;if(t){var r=t.U;if(r){t.U=void 0;for(var f in r){var o=r[f];if(o)o.d()}}}}else{var e=n.__c;if(e){var u=e.__$u;if(u){e.__$u=void 0;u.d()}}}i(n)});g("__h",function(i,n,t,r){if(r<3||9===r)n.__$f|=2;i(n,t,r)});i.prototype.shouldComponentUpdate=function(i,n){var t=this.__$u,r=t&&void 0!==t.s;for(var f in n)return!0;if(this.__f||"boolean"==typeof this.u&&!0===this.u){var o=2&this.__$f;if(!(r||o||4&this.__$f))return!0;if(1&this.__$f)return!0}else{if(!(r||4&this.__$f))return!0;if(3&this.__$f)return!0}for(var e in i)if("__source"!==e&&i[e]!==this.props[e])return!0;for(var u in this.props)if(!(u in i))return!0;return!1};function useSignal(i,n){return o(function(){return s(i,n)})[0]}function useComputed(i,n){var t=e(i);t.current=i;l.__$f|=4;return f(function(){return v(function(){return t.current()},n)},[])}var q="undefined"==typeof requestAnimationFrame?setTimeout:function(i){var n=function(){clearTimeout(t);cancelAnimationFrame(r);i()},t=setTimeout(n,35),r=requestAnimationFrame(n)},A=function(i){queueMicrotask(function(){queueMicrotask(i)})};function T(){d(function(){var i;while(i=w.shift())h.call(i)})}function x(){if(1===w.push(this))(n.requestAnimationFrame||q)(T)}function F(){d(function(){var i;while(i=_.shift())h.call(i)})}function M(){if(1===_.push(this))(n.requestAnimationFrame||A)(F)}function useSignalEffect(i,n){var t=e(i);t.current=i;u(function(){return a(function(){this.N=x;return t.current()},n)},[])}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signals.module.js","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (typeof window !== \"undefined\" && window.__PREACT_SIGNALS_DEVTOOLS__) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (\n\t\ttypeof vnode.type === \"function\" &&\n\t\ttypeof window !== \"undefined\" &&\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__\n\t) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","_ref","_this","data","currentSignal","useSignal","value","_useMemo","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","s","isText","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","window","__PREACT_SIGNALS_DEVTOOLS__","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","HAS_PENDING_UPDATE","useState","useComputed","compute","$compute","useRef","current","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrot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AEjB,EACD,CAEA,SAASnF,IACR,GAA4B,IAAxBnC,EAASyH,KAAKvH,OAChBK,EAAQkG,uBAAyBQ,GAAiBS,EAErD,CAEgB,SAAAC,gBACfT,EACA3G,GAEA,IAAMoG,EAAWL,EAAOY,GACxBP,EAASJ,QAAUW,EAEnBU,EAAU,WACT,OAAO3H,EAAO,WACbC,KAAKC,EAAUqH,EACf,OAAOb,EAASJ,SACjB,EAAGhG,EACJ,EAAG,GACJ,QAAA4F,YAAAlF,UAAA0G"}
1
+ {"version":3,"file":"signals.module.js","sources":["../src/index.ts"],"sourcesContent":["import { options, Component, isValidElement, Fragment } from \"preact\";\nimport { useRef, useMemo, useEffect, useState } from \"preact/hooks\";\nimport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n\tSignalOptions,\n\tEffectOptions,\n} from \"@preact/signals-core\";\nimport {\n\tVNode,\n\tOptionsTypes,\n\tHookFn,\n\tEffect,\n\tPropertyUpdater,\n\tAugmentedComponent,\n\tAugmentedElement as Element,\n} from \"./internal\";\n\nexport {\n\tsignal,\n\tcomputed,\n\tbatch,\n\teffect,\n\tSignal,\n\ttype ReadonlySignal,\n\tuntracked,\n};\n\nconst DEVTOOLS_ENABLED =\n\ttypeof window !== \"undefined\" && !!window.__PREACT_SIGNALS_DEVTOOLS__;\n\nconst HAS_PENDING_UPDATE = 1 << 0;\nconst HAS_HOOK_STATE = 1 << 1;\nconst HAS_COMPUTEDS = 1 << 2;\n\nlet oldNotify: (this: Effect) => void,\n\teffectsQueue: Array<Effect> = [],\n\tdomQueue: Array<Effect> = [];\n\n// Capture the original `Effect.prototype._notify` method so that we can install\n// custom `._notify`s for each different use-case but still call the original\n// implementation in the end. Dispose the temporary effect immediately afterwards.\neffect(function (this: Effect) {\n\toldNotify = this._notify;\n})();\n\n// Install a Preact options hook\nfunction hook<T extends OptionsTypes>(hookName: T, hookFn: HookFn<T>) {\n\t// @ts-ignore-next-line private options hooks usage\n\toptions[hookName] = hookFn.bind(null, options[hookName] || (() => {}));\n}\n\nlet currentComponent: AugmentedComponent | undefined;\nlet finishUpdate: (() => void) | undefined;\n\nfunction setCurrentUpdater(updater?: Effect) {\n\t// end tracking for the current update:\n\tif (finishUpdate) finishUpdate();\n\t// start tracking the new update:\n\tfinishUpdate = updater && updater._start();\n}\n\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/** @todo This may be needed for complex prop value detection. */\n// function isSignalValue(value: any): value is Signal {\n// \tif (typeof value !== \"object\" || value == null) return false;\n// \tif (value instanceof Signal) return true;\n// \t// @TODO: uncomment this when we land Reactive (ideally behind a brand check)\n// \t// for (let i in value) if (value[i] instanceof Signal) return true;\n// \treturn false;\n// }\n\n/**\n * A wrapper component that renders a Signal directly as a Text node.\n * @todo: in Preact 11, just decorate Signal with `type:null`\n */\nfunction SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {\n\t// hasComputeds.add(this);\n\n\t// Store the props.data signal in another signal so that\n\t// passing a new signal reference re-runs the text computed:\n\tconst currentSignal = useSignal(data);\n\tcurrentSignal.value = data;\n\n\tconst [isText, s] = useMemo(() => {\n\t\tlet self = this;\n\t\t// mark the parent component as having computeds so it gets optimized\n\t\tlet v = this.__v;\n\t\twhile ((v = v.__!)) {\n\t\t\tif (v.__c) {\n\t\t\t\tv.__c._updateFlags |= HAS_COMPUTEDS;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\tconst wrappedSignal = computed(() => {\n\t\t\tlet s = currentSignal.value.value;\n\t\t\treturn s === 0 ? 0 : s === true ? \"\" : s || \"\";\n\t\t});\n\n\t\tconst isText = computed(\n\t\t\t() =>\n\t\t\t\t!Array.isArray(wrappedSignal.value) &&\n\t\t\t\t!isValidElement(wrappedSignal.value)\n\t\t);\n\t\t// Update text nodes directly without rerendering when the new value\n\t\t// is also text.\n\t\tconst dispose = effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\n\t\t\t// Subscribe to wrappedSignal updates only when its values are text...\n\t\t\tif (isText.value) {\n\t\t\t\t// ...but regardless of `self.base`'s current value, as it can be\n\t\t\t\t// undefined before mounting or a non-text node. In both of those cases\n\t\t\t\t// the update gets handled by a full rerender.\n\t\t\t\tconst value = wrappedSignal.value;\n\t\t\t\tif (self.__v && self.__v.__e && self.__v.__e.nodeType === 3) {\n\t\t\t\t\t(self.__v.__e as Text).data = value;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Piggyback this._updater's disposal to ensure that the text updater effect\n\t\t// above also gets disposed on unmount.\n\t\tconst oldDispose = this._updater!._dispose;\n\t\tthis._updater!._dispose = function () {\n\t\t\tdispose();\n\t\t\toldDispose.call(this);\n\t\t};\n\n\t\treturn [isText, wrappedSignal];\n\t}, []);\n\n\t// Rerender the component whenever `data.value` changes from a VNode\n\t// to another VNode, from text to a VNode, or from a VNode to text.\n\t// That is, everything else except text-to-text updates.\n\t//\n\t// This also ensures that the backing DOM node types gets updated to\n\t// text nodes and back when needed.\n\t//\n\t// For text-to-text updates, `.peek()` is used to skip full rerenders,\n\t// leaving them to the optimized path above.\n\treturn isText.value ? s.peek() : s.value;\n}\n\nSignalValue.displayName = \"ReactiveTextNode\";\n\nObject.defineProperties(Signal.prototype, {\n\tconstructor: { configurable: true, value: undefined },\n\ttype: { configurable: true, value: SignalValue },\n\tprops: {\n\t\tconfigurable: true,\n\t\tget() {\n\t\t\treturn { data: this };\n\t\t},\n\t},\n\t// Setting a VNode's _depth to 1 forces Preact to clone it before modifying:\n\t// https://github.com/preactjs/preact/blob/d7a433ee8463a7dc23a05111bb47de9ec729ad4d/src/diff/children.js#L77\n\t// @todo remove this for Preact 11\n\t__b: { configurable: true, value: 1 },\n});\n\n/** Inject low-level property/attribute bindings for Signals into Preact's diff */\nhook(OptionsTypes.DIFF, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tif (typeof vnode.type === \"string\") {\n\t\tlet signalProps: Record<string, any> | undefined;\n\n\t\tlet props = vnode.props;\n\t\tfor (let i in props) {\n\t\t\tif (i === \"children\") continue;\n\n\t\t\tlet value = props[i];\n\t\t\tif (value instanceof Signal) {\n\t\t\t\tif (!signalProps) vnode.__np = signalProps = {};\n\t\t\t\tsignalProps[i] = value;\n\t\t\t\tprops[i] = value.peek();\n\t\t\t}\n\t\t}\n\t}\n\n\told(vnode);\n});\n\n/** Set up Updater before rendering a component */\nhook(OptionsTypes.RENDER, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);\n\t}\n\n\t// Ignore the Fragment inserted by preact.createElement().\n\tif (vnode.type !== Fragment) {\n\t\tsetCurrentUpdater();\n\n\t\tlet updater;\n\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tcomponent._updateFlags &= ~HAS_PENDING_UPDATE;\n\n\t\t\tupdater = component._updater;\n\t\t\tif (updater === undefined) {\n\t\t\t\tcomponent._updater = updater = createUpdater(() => {\n\t\t\t\t\tcomponent._updateFlags |= HAS_PENDING_UPDATE;\n\t\t\t\t\tcomponent.setState({});\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tcurrentComponent = component;\n\t\tsetCurrentUpdater(updater);\n\t}\n\n\told(vnode);\n});\n\n/** Finish current updater if a component errors */\nhook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {\n\tif (DEVTOOLS_ENABLED) {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\told(error, vnode, oldVNode);\n});\n\n/** Finish current updater after rendering any VNode */\nhook(OptionsTypes.DIFFED, (old, vnode) => {\n\tif (DEVTOOLS_ENABLED && typeof vnode.type === \"function\") {\n\t\twindow.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();\n\t}\n\n\tsetCurrentUpdater();\n\tcurrentComponent = undefined;\n\n\tlet dom: Element;\n\n\t// vnode._dom is undefined during string rendering,\n\t// so we use this to skip prop subscriptions during SSR.\n\tif (typeof vnode.type === \"string\" && (dom = vnode.__e as Element)) {\n\t\tlet props = vnode.__np;\n\t\tlet renderedProps = vnode.props;\n\t\tif (props) {\n\t\t\tlet updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater !== undefined && !(prop in props)) {\n\t\t\t\t\t\tupdater._dispose();\n\t\t\t\t\t\t// @todo we could just always invoke _dispose() here\n\t\t\t\t\t\tupdaters[prop] = undefined;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tupdaters = {};\n\t\t\t\tdom._updaters = updaters;\n\t\t\t}\n\t\t\tfor (let prop in props) {\n\t\t\t\tlet updater = updaters[prop];\n\t\t\t\tlet signal = props[prop];\n\t\t\t\tif (updater === undefined) {\n\t\t\t\t\tupdater = createPropUpdater(dom, prop, signal, renderedProps);\n\t\t\t\t\tupdaters[prop] = updater;\n\t\t\t\t} else {\n\t\t\t\t\tupdater._update(signal, renderedProps);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\nfunction createPropUpdater(\n\tdom: Element,\n\tprop: string,\n\tpropSignal: Signal,\n\tprops: Record<string, any>\n): PropertyUpdater {\n\tconst setAsProperty =\n\t\tprop in dom &&\n\t\t// SVG elements need to go through `setAttribute` because they\n\t\t// expect things like SVGAnimatedTransformList instead of strings.\n\t\t// @ts-ignore\n\t\tdom.ownerSVGElement === undefined;\n\n\tconst changeSignal = signal(propSignal);\n\treturn {\n\t\t_update: (newSignal: Signal, newProps: typeof props) => {\n\t\t\tchangeSignal.value = newSignal;\n\t\t\tprops = newProps;\n\t\t},\n\t\t_dispose: effect(function (this: Effect) {\n\t\t\tthis._notify = notifyDomUpdates;\n\t\t\tconst value = changeSignal.value.value;\n\t\t\t// If Preact just rendered this value, don't render it again:\n\t\t\tif (props[prop] === value) return;\n\t\t\tprops[prop] = value;\n\t\t\tif (setAsProperty) {\n\t\t\t\t// @ts-ignore-next-line silly\n\t\t\t\tdom[prop] = value;\n\t\t\t\t// Match Preact's attribute handling: data-* and aria-* attributes\n\t\t\t\t// https://github.com/preactjs/preact/blob/main/src/diff/props.js#L132\n\t\t\t} else if (value != null && (value !== false || prop[4] === \"-\")) {\n\t\t\t\tdom.setAttribute(prop, value);\n\t\t\t} else {\n\t\t\t\tdom.removeAttribute(prop);\n\t\t\t}\n\t\t}),\n\t};\n}\n\n/** Unsubscribe from Signals when unmounting components/vnodes */\nhook(OptionsTypes.UNMOUNT, (old, vnode: VNode) => {\n\tif (typeof vnode.type === \"string\") {\n\t\tlet dom = vnode.__e as Element | undefined;\n\t\t// vnode._dom is undefined during string rendering\n\t\tif (dom) {\n\t\t\tconst updaters = dom._updaters;\n\t\t\tif (updaters) {\n\t\t\t\tdom._updaters = undefined;\n\t\t\t\tfor (let prop in updaters) {\n\t\t\t\t\tlet updater = updaters[prop];\n\t\t\t\t\tif (updater) updater._dispose();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tlet component = vnode.__c;\n\t\tif (component) {\n\t\t\tconst updater = component._updater;\n\t\t\tif (updater) {\n\t\t\t\tcomponent._updater = undefined;\n\t\t\t\tupdater._dispose();\n\t\t\t}\n\t\t}\n\t}\n\told(vnode);\n});\n\n/** Mark components that use hook state so we can skip sCU optimization. */\nhook(OptionsTypes.HOOK, (old, component, index, type) => {\n\tif (type < 3 || type === 9)\n\t\t(component as AugmentedComponent)._updateFlags |= HAS_HOOK_STATE;\n\told(component, index, type);\n});\n\n/**\n * Auto-memoize components that use Signals/Computeds.\n * Note: Does _not_ optimize components that use hook/class state.\n */\nComponent.prototype.shouldComponentUpdate = function (\n\tthis: AugmentedComponent,\n\tprops,\n\tstate\n) {\n\t// @todo: Once preactjs/preact#3671 lands, this could just use `currentUpdater`:\n\tconst updater = this._updater;\n\tconst hasSignals = updater && updater._sources !== undefined;\n\n\t// If this is a component using state, rerender\n\t// @ts-ignore\n\tfor (let i in state) return true;\n\n\tif (this.__f || (typeof this.u == \"boolean\" && this.u === true)) {\n\t\tconst hasHooksState = this._updateFlags & HAS_HOOK_STATE;\n\t\t// if this component used no signals or computeds and no hooks state, update:\n\t\tif (!hasSignals && !hasHooksState && !(this._updateFlags & HAS_COMPUTEDS))\n\t\t\treturn true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & HAS_PENDING_UPDATE) return true;\n\t} else {\n\t\t// if this component used no signals or computeds, update:\n\t\tif (!hasSignals && !(this._updateFlags & HAS_COMPUTEDS)) return true;\n\n\t\t// if there is a pending re-render triggered from Signals,\n\t\t// or if there is hooks state, update:\n\t\tif (this._updateFlags & (HAS_PENDING_UPDATE | HAS_HOOK_STATE)) return true;\n\t}\n\n\t// if any non-Signal props changed, update:\n\tfor (let i in props) {\n\t\tif (i !== \"__source\" && props[i] !== this.props[i]) return true;\n\t}\n\tfor (let i in this.props) if (!(i in props)) return true;\n\n\t// this is a purely Signal-driven component, don't update:\n\treturn false;\n};\n\nexport function useSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;\nexport function useSignal<T = undefined>(): Signal<T | undefined>;\nexport function useSignal<T>(value?: T, options?: SignalOptions<T>) {\n\treturn useState(() =>\n\t\tsignal<T | undefined>(value, options as SignalOptions)\n\t)[0];\n}\n\nexport function useComputed<T>(compute: () => T, options?: SignalOptions<T>) {\n\tconst $compute = useRef(compute);\n\t$compute.current = compute;\n\t(currentComponent as AugmentedComponent)._updateFlags |= HAS_COMPUTEDS;\n\treturn useMemo(() => computed<T>(() => $compute.current(), options), []);\n}\n\nfunction safeRaf(callback: () => void) {\n\tconst done = () => {\n\t\tclearTimeout(timeout);\n\t\tcancelAnimationFrame(raf);\n\t\tcallback();\n\t};\n\n\tconst timeout = setTimeout(done, 35);\n\tconst raf = requestAnimationFrame(done);\n}\n\nconst deferEffects =\n\ttypeof requestAnimationFrame === \"undefined\" ? setTimeout : safeRaf;\n\nconst deferDomUpdates = (cb: any) => {\n\tqueueMicrotask(() => {\n\t\tqueueMicrotask(cb);\n\t});\n};\n\nfunction flushEffects() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = effectsQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyEffects(this: Effect) {\n\tif (effectsQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferEffects)(flushEffects);\n\t}\n}\n\nfunction flushDomUpdates() {\n\tbatch(() => {\n\t\tlet inst: Effect | undefined;\n\t\twhile ((inst = domQueue.shift())) {\n\t\t\toldNotify.call(inst);\n\t\t}\n\t});\n}\n\nfunction notifyDomUpdates(this: Effect) {\n\tif (domQueue.push(this) === 1) {\n\t\t(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);\n\t}\n}\n\nexport function useSignalEffect(\n\tcb: () => void | (() => void),\n\toptions?: EffectOptions\n) {\n\tconst callback = useRef(cb);\n\tcallback.current = cb;\n\n\tuseEffect(() => {\n\t\treturn effect(function (this: Effect) {\n\t\t\tthis._notify = notifyEffects;\n\t\t\treturn callback.current();\n\t\t}, options);\n\t}, []);\n}\n\n/**\n * @todo Determine which Reactive implementation we'll be using.\n * @internal\n */\n// export function useReactive<T extends object>(value: T): Reactive<T> {\n// \treturn useMemo(() => reactive<T>(value), []);\n// }\n\n/**\n * @internal\n * Update a Reactive's using the properties of an object or other Reactive.\n * Also works for Signals.\n * @example\n * // Update a Reactive with Object.assign()-like syntax:\n * const r = reactive({ name: \"Alice\" });\n * update(r, { name: \"Bob\" });\n * update(r, { age: 42 }); // property 'age' does not exist in type '{ name?: string }'\n * update(r, 2); // '2' has no properties in common with '{ name?: string }'\n * console.log(r.name.value); // \"Bob\"\n *\n * @example\n * // Update a Reactive with the properties of another Reactive:\n * const A = reactive({ name: \"Alice\" });\n * const B = reactive({ name: \"Bob\", age: 42 });\n * update(A, B);\n * console.log(`${A.name} is ${A.age}`); // \"Bob is 42\"\n *\n * @example\n * // Update a signal with assign()-like syntax:\n * const s = signal(42);\n * update(s, \"hi\"); // Argument type 'string' not assignable to type 'number'\n * update(s, {}); // Argument type '{}' not assignable to type 'number'\n * update(s, 43);\n * console.log(s.value); // 43\n *\n * @param obj The Reactive or Signal to be updated\n * @param update The value, Signal, object or Reactive to update `obj` to match\n * @param overwrite If `true`, any properties `obj` missing from `update` are set to `undefined`\n */\n/*\nexport function update<T extends SignalOrReactive>(\n\tobj: T,\n\tupdate: Partial<Unwrap<T>>,\n\toverwrite = false\n) {\n\tif (obj instanceof Signal) {\n\t\tobj.value = peekValue(update);\n\t} else {\n\t\tfor (let i in update) {\n\t\t\tif (i in obj) {\n\t\t\t\tobj[i].value = peekValue(update[i]);\n\t\t\t} else {\n\t\t\t\tlet sig = signal(peekValue(update[i]));\n\t\t\t\tsig[KEY] = i;\n\t\t\t\tobj[i] = sig;\n\t\t\t}\n\t\t}\n\t\tif (overwrite) {\n\t\t\tfor (let i in obj) {\n\t\t\t\tif (!(i in update)) {\n\t\t\t\t\tobj[i].value = undefined;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n*/\n"],"names":["oldNotify","currentComponent","finishUpdate","DEVTOOLS_ENABLED","window","__PREACT_SIGNALS_DEVTOOLS__","effectsQueue","domQueue","effect","this","_notify","hook","hookName","hookFn","options","bind","setCurrentUpdater","updater","_start","SignalValue","_ref","_this","data","currentSignal","useSignal","value","_useMemo","useMemo","self","v","__v","__","__c","_updateFlags","wrappedSignal","computed","s","isText","Array","isArray","isValidElement","dispose","notifyDomUpdates","__e","nodeType","oldDispose","_updater","_dispose","call","peek","displayName","Object","defineProperties","Signal","prototype","constructor","configurable","undefined","type","props","get","__b","old","vnode","exitComponent","signalProps","i","__np","enterComponent","Fragment","component","update","_callback","setState","createUpdater","error","oldVNode","dom","renderedProps","updaters","_updaters","prop","signal","createPropUpdater","_update","propSignal","setAsProperty","ownerSVGElement","changeSignal","newSignal","newProps","setAttribute","removeAttribute","index","Component","shouldComponentUpdate","state","hasSignals","_sources","__f","u","hasHooksState","useState","useComputed","compute","$compute","useRef","current","deferEffects","requestAnimationFrame","setTimeout","callback","done","clearTimeout","timeout","cancelAnimationFrame","raf","deferDomUpdates","cb","queueMicrotask","flushEffects","batch","inst","shift","notifyEffects","push","flushDomUpdates","useSignalEffect","useEffect"],"mappings":"iVAiCA,IAOIA,EAiBAC,EACAC,EAzBEC,EACa,oBAAXC,UAA4BA,OAAOC,4BAO1CC,EAA8B,GAC9BC,EAA0B,GAK3BC,EAAO,WACNR,EAAYS,KAAKC,CAClB,EAFAF,GAKA,SAASG,EAA6BC,EAAaC,GAElDC,EAAQF,GAAYC,EAAOE,KAAK,KAAMD,EAAQF,IAAc,WAAO,EACpE,CAKA,SAASI,EAAkBC,GAE1B,GAAIf,EAAcA,IAElBA,EAAee,GAAWA,EAAQC,GACnC,CAwBA,SAASC,EAAWC,GAAqD,IAAAC,EAAAZ,KAAxBa,EAAIF,EAAJE,KAK1CC,EAAgBC,UAAUF,GAChCC,EAAcE,MAAQH,EAEtB,IAAAI,EAAoBC,EAAQ,WAC3B,IAAIC,EAAOP,EAEPQ,EAAIR,EAAKS,IACb,MAAQD,EAAIA,EAAEE,GACb,GAAIF,EAAEG,IAAK,CACVH,EAAEG,IAAIC,MAjEY,EAkElB,KACD,CAGD,IAAMC,EAAgBC,EAAS,WAC9B,IAAIC,EAAIb,EAAcE,MAAMA,MAC5B,OAAa,IAANW,EAAU,GAAU,IAANA,EAAa,GAAKA,GAAK,EAC7C,GAEMC,EAASF,EACd,WACC,OAACG,MAAMC,QAAQL,EAAcT,SAC5Be,EAAe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EAKMK,EAAkB,SAACC,GACxBC,eAAe,WACdA,eAAeD,EAChB,EACD,EAEA,SAASE,IACRC,EAAM,WACL,IAAIC,EACJ,MAAQA,EAAOpH,EAAaqH,QAC3B3H,EAAUgD,KAAK0E,EAEjB,EACD,CAEA,SAASE,IACR,GAAgC,IAA5BtH,EAAauH,KAAKpH,OACpBK,EAAQ+F,uBAAyBD,GAAcY,EAElD,CAEA,SAASM,IACRL,EAAM,WACL,IAAIC,EACJ,MAAQA,EAAOnH,EAASoH,QACvB3H,EAAUgD,KAAK0E,EAEjB,EACD,CAEA,SAAShF,IACR,GAA4B,IAAxBnC,EAASsH,KAAKpH,OAChBK,EAAQ+F,uBAAyBQ,GAAiBS,EAErD,CAEgB,SAAAC,gBACfT,EACAxG,GAEA,IAAMiG,EAAWL,EAAOY,GACxBP,EAASJ,QAAUW,EAEnBU,EAAU,WACT,OAAOxH,EAAO,WACbC,KAAKC,EAAUkH,EACf,OAAOb,EAASJ,SACjB,EAAG7F,EACJ,EAAG,GACJ,QAAAyF,YAAA/E,UAAAuG"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preact/signals",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "license": "MIT",
5
5
  "description": "Manage state with style in Preact",
6
6
  "keywords": [],
package/src/index.ts CHANGED
@@ -31,6 +31,9 @@ export {
31
31
  untracked,
32
32
  };
33
33
 
34
+ const DEVTOOLS_ENABLED =
35
+ typeof window !== "undefined" && !!window.__PREACT_SIGNALS_DEVTOOLS__;
36
+
34
37
  const HAS_PENDING_UPDATE = 1 << 0;
35
38
  const HAS_HOOK_STATE = 1 << 1;
36
39
  const HAS_COMPUTEDS = 1 << 2;
@@ -172,11 +175,7 @@ Object.defineProperties(Signal.prototype, {
172
175
 
173
176
  /** Inject low-level property/attribute bindings for Signals into Preact's diff */
174
177
  hook(OptionsTypes.DIFF, (old, vnode) => {
175
- if (
176
- typeof vnode.type === "function" &&
177
- typeof window !== "undefined" &&
178
- window.__PREACT_SIGNALS_DEVTOOLS__
179
- ) {
178
+ if (DEVTOOLS_ENABLED && typeof vnode.type === "function") {
180
179
  window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();
181
180
  }
182
181
 
@@ -201,11 +200,7 @@ hook(OptionsTypes.DIFF, (old, vnode) => {
201
200
 
202
201
  /** Set up Updater before rendering a component */
203
202
  hook(OptionsTypes.RENDER, (old, vnode) => {
204
- if (
205
- typeof vnode.type === "function" &&
206
- typeof window !== "undefined" &&
207
- window.__PREACT_SIGNALS_DEVTOOLS__
208
- ) {
203
+ if (DEVTOOLS_ENABLED && typeof vnode.type === "function") {
209
204
  window.__PREACT_SIGNALS_DEVTOOLS__.enterComponent(vnode);
210
205
  }
211
206
 
@@ -237,7 +232,7 @@ hook(OptionsTypes.RENDER, (old, vnode) => {
237
232
 
238
233
  /** Finish current updater if a component errors */
239
234
  hook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {
240
- if (typeof window !== "undefined" && window.__PREACT_SIGNALS_DEVTOOLS__) {
235
+ if (DEVTOOLS_ENABLED) {
241
236
  window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();
242
237
  }
243
238
 
@@ -248,11 +243,7 @@ hook(OptionsTypes.CATCH_ERROR, (old, error, vnode, oldVNode) => {
248
243
 
249
244
  /** Finish current updater after rendering any VNode */
250
245
  hook(OptionsTypes.DIFFED, (old, vnode) => {
251
- if (
252
- typeof vnode.type === "function" &&
253
- typeof window !== "undefined" &&
254
- window.__PREACT_SIGNALS_DEVTOOLS__
255
- ) {
246
+ if (DEVTOOLS_ENABLED && typeof vnode.type === "function") {
256
247
  window.__PREACT_SIGNALS_DEVTOOLS__.exitComponent();
257
248
  }
258
249
 
@@ -1,18 +1,18 @@
1
1
  import { ReadonlySignal, Signal } from "@preact/signals-core";
2
- import { JSX } from "preact";
2
+ import { ComponentChildren } from "preact";
3
3
  interface ShowProps<T = boolean> {
4
- when: Signal<T> | ReadonlySignal<T>;
5
- fallback?: JSX.Element;
6
- children: JSX.Element | ((value: NonNullable<T>) => JSX.Element);
4
+ when: Signal<T> | ReadonlySignal<T> | (() => T);
5
+ fallback?: ComponentChildren;
6
+ children: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);
7
7
  }
8
- export declare function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null;
8
+ export declare function Show<T = boolean>(props: ShowProps<T>): ComponentChildren | null;
9
9
  interface ForProps<T> {
10
10
  each: Signal<Array<T>> | ReadonlySignal<Array<T>> | (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);
11
- fallback?: JSX.Element;
12
- children: (value: T, index: number) => JSX.Element;
11
+ fallback?: ComponentChildren;
12
+ children: (value: T, index: number) => ComponentChildren;
13
13
  }
14
- export declare function For<T>(props: ForProps<T>): JSX.Element | null;
15
- export declare function useLiveSignal<T>(value: Signal<T> | ReadonlySignal<T>): Signal<Signal<T> | ReadonlySignal<T>>;
14
+ export declare function For<T>(props: ForProps<T>): ComponentChildren | null;
15
+ export declare function useLiveSignal<T>(value: T): Signal<T>;
16
16
  export declare function useSignalRef<T>(value: T): Signal<T> & {
17
17
  current: T;
18
18
  };
@@ -1 +1 @@
1
- var r=require("@preact/signals"),n=require("preact"),e=require("preact/hooks"),t=function(r){var n="function"==typeof r.children?r.children(r.v,r.i):r.children;if(r.cache)r.cache.set(r.v,n);return n},u={configurable:!0,get:function(){return this.value},set:function(r){this.value=r}};exports.For=function(r){var u=e.useMemo(function(){return new Map},[]),i=("function"==typeof r.each?r.each():r.each).value;if(!i.length)return r.fallback||null;var c=i.map(function(e,i){if(!u.has(e))return n.createElement(t,{v:e,i:i,children:r.children,cache:u});else return u.get(e)});return n.createElement(n.Fragment,null,c)};exports.Show=function(r){var e=r.when.value;if(!e)return r.fallback||null;else return n.createElement(t,{v:e,children:r.children})};exports.useLiveSignal=function(n){var e=r.useSignal(n);if(e.peek()!==n)e.value=n;return e};exports.useSignalRef=function(n){var e=r.useSignal(n);if(!("current"in e))Object.defineProperty(e,"current",u);return e};//# sourceMappingURL=utils.js.map
1
+ var n=require("@preact/signals"),r=require("preact"),t=require("preact/hooks"),e=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children},u={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};exports.For=function(n){var u=t.useMemo(function(){return new Map},[]),i=("function"==typeof n.each?n.each():n.each).value;if(!i.length)return n.fallback||null;var o=new Set(u.keys()),c=i.map(function(t,i){o.delete(t);if(!u.has(t)){var c=r.createElement(e,{v:t,i:i,children:n.children});u.set(t,c);return c}return u.get(t)});o.forEach(function(n){u.delete(n)});return r.createElement(r.Fragment,null,c)};exports.Show=function(n){var t="function"==typeof n.when?n.when():n.when.value;if(!t)return n.fallback||null;else return r.createElement(e,{v:t,children:n.children})};exports.useLiveSignal=function(r){var t=n.useSignal(r);if(t.peek()!==r)t.value=r;return t};exports.useSignalRef=function(r){var t=n.useSignal(r);if(!("current"in t))Object.defineProperty(t,"current",u);return t};//# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, JSX } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T>;\n\tfallback?: JSX.Element;\n\tchildren: JSX.Element | ((value: NonNullable<T>) => JSX.Element);\n}\n\nconst Item = (props: any) => {\n\tconst result =\n\t\ttypeof props.children === \"function\"\n\t\t\t? props.children(props.v, props.i)\n\t\t\t: props.children;\n\tif (props.cache) {\n\t\tprops.cache.set(props.v, result);\n\t}\n\treturn result;\n};\n\nexport function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {\n\tconst value = props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: JSX.Element;\n\tchildren: (value: T, index: number) => JSX.Element;\n}\n\nexport function For<T>(props: ForProps<T>): JSX.Element | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst items = list.map((value, key) => {\n\t\tif (!cache.has(value)) {\n\t\t\treturn <Item v={value} i={key} children={props.children} cache={cache} />;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(\n\tvalue: Signal<T> | ReadonlySignal<T>\n): Signal<Signal<T> | ReadonlySignal<T>> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["signals","require","preact","hooks","Item","props","result","children","v","i","cache","set","refSignalProto","configurable","get","value","this","exports","For","useMemo","Map","list","each","length","fallback","items","map","key","has","createElement","Fragment","Show","when","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"AAWA,IAAAA,EAAAC,QAAA,mBAAAC,EAAAD,QAAA,UAAAE,EAAAF,QAAA,gBAAMG,EAAO,SAACC,GACb,IAAMC,EACqB,mBAAnBD,EAAME,SACVF,EAAME,SAASF,EAAMG,EAAGH,EAAMI,GAC9BJ,EAAME,SACV,GAAIF,EAAMK,MACTL,EAAMK,MAAMC,IAAIN,EAAMG,EAAGF,GAE1B,OAAOA,CACR,EAmDMM,EAAiB,CACtBC,cAAc,EACdC,IAAG,WACF,YAAYC,KACb,EACAJ,aAAkBH,GACjBQ,KAAKD,MAAQP,CACd,GACAS,QAAAC,aA1CsBb,GACtB,IAAMK,EAAQS,EAAAA,QAAQ,WAAM,OAAA,IAAIC,GAAK,EAAE,IACnCC,GACoB,mBAAfhB,EAAMiB,KAAsBjB,EAAMiB,OAASjB,EAAMiB,MAGxDP,MAEF,IAAKM,EAAKE,OAAQ,OAAOlB,EAAMmB,UAAY,KAE3C,IAAMC,EAAQJ,EAAKK,IAAI,SAACX,EAAOY,GAC9B,IAAKjB,EAAMkB,IAAIb,GACd,OAAOc,EAAAA,cAACzB,EAAK,CAAAI,EAAGO,EAAON,EAAGkB,EAAKpB,SAAUF,EAAME,SAAUG,MAAOA,SAEjE,OAAOA,EAAMI,IAAIC,EAClB,GAEA,OAAOc,EAAAA,cAAcC,EAAQA,SAAE,KAAML,EACtC,EAwBCR,QAAAc,KAzDe,SAAkB1B,GACjC,IAAMU,EAAQV,EAAM2B,KAAKjB,MACzB,IAAKA,EAAO,OAAOV,EAAMmB,UAAY,UACrC,OAAOK,EAACA,cAAAzB,EAAK,CAAAI,EAAGO,EAAOR,SAAUF,EAAME,UACxC,EAqDCU,QAAAgB,uBArBAlB,GAEA,IAAMmB,EAAIC,EAAAA,UAAUpB,GACpB,GAAImB,EAAEE,SAAWrB,EAAOmB,EAAEnB,MAAQA,EAClC,OAAOmB,CACR,EAgBCjB,QAAAoB,aAde,SAAgBtB,GAC/B,IAAMuB,EAAMH,EAAAA,UAAUpB,GACtB,KAAM,YAAauB,GAClBC,OAAOC,eAAeF,EAAK,UAAW1B,GACvC,OAAO0B,CACR"}
1
+ {"version":3,"file":"utils.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["signals","require","preact","hooks","Item","props","children","v","i","refSignalProto","configurable","get","this","value","set","exports","For","cache","useMemo","Map","list","each","length","fallback","removed","Set","keys","items","map","key","has","result","createElement","forEach","Fragment","Show","when","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"AAWA,IAAAA,EAAAC,QAAA,mBAAAC,EAAAD,QAAA,UAAAE,EAAAF,QAAA,gBAAMG,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,EA6DMG,EAAiB,CACtBC,cAAc,EACdC,IAAA,WACC,OAAOC,KAAKC,KACb,EACAC,IAAA,SAAkBP,GACjBK,KAAKC,MAAQN,CACd,GACAQ,QAAAC,IAjDe,SAAOX,GACtB,IAAMY,EAAQC,EAAAA,QAAQ,WAAM,OAAA,IAAIC,GAAK,EAAE,IACnCC,GACoB,mBAAff,EAAMgB,KAAsBhB,EAAMgB,OAAShB,EAAMgB,MAGxDR,MAEF,IAAKO,EAAKE,OAAQ,OAAOjB,EAAMkB,UAAY,KAE3C,IAAMC,EAAU,IAAIC,IAAIR,EAAMS,QAExBC,EAAQP,EAAKQ,IAAI,SAACf,EAAOgB,GAC9BL,SAAeX,GACf,IAAKI,EAAMa,IAAIjB,GAAQ,CACtB,IAAMkB,EAASC,gBAAC5B,EAAK,CAAAG,EAAGM,EAAOL,EAAGqB,EAAKvB,SAAUD,EAAMC,WACvDW,EAAMH,IAAID,EAAOkB,GACjB,OAAOA,CACR,CACA,OAAOd,EAAMN,IAAIE,EAClB,GAEAW,EAAQS,QAAQ,SAAApB,GACfI,EAAY,OAACJ,EACd,GAEA,OAAOmB,EAAAA,cAAcE,EAAQA,SAAE,KAAMP,EACtC,EAsBCZ,QAAAoB,cAlEA9B,GAEA,IAAMQ,EACiB,mBAAfR,EAAM+B,KAAsB/B,EAAM+B,OAAS/B,EAAM+B,KAAKvB,MAC9D,IAAKA,EAAO,OAAOR,EAAMkB,UAAY,UACrC,OAAOS,EAAAA,cAAC5B,EAAK,CAAAG,EAAGM,EAAOP,SAAUD,EAAMC,UACxC,EA4DCS,QAAAsB,cApBe,SAAiBxB,GAChC,IAAMyB,EAAIC,EAAAA,UAAU1B,GACpB,GAAIyB,EAAEE,SAAW3B,EAAOyB,EAAEzB,MAAQA,EAClC,OAAOyB,CACR,EAgBCvB,QAAA0B,aAde,SAAgB5B,GAC/B,IAAM6B,EAAMH,EAAAA,UAAU1B,GACtB,KAAM,YAAa6B,GAClBC,OAAOC,eAAeF,EAAK,UAAWjC,GACvC,OAAOiC,CACR"}
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@preact/signals"),require("preact"),require("preact/hooks")):"function"==typeof define&&define.amd?define(["exports","@preact/signals","preact","preact/hooks"],n):n((e||self).preactSignalsutils={},e.signals,e.preact,e.preactHooks)}(this,function(e,n,r,t){var i=function(e){var n="function"==typeof e.children?e.children(e.v,e.i):e.children;if(e.cache)e.cache.set(e.v,n);return n},u={configurable:!0,get:function(){return this.value},set:function(e){this.value=e}};e.For=function(e){var n=t.useMemo(function(){return new Map},[]),u=("function"==typeof e.each?e.each():e.each).value;if(!u.length)return e.fallback||null;var f=u.map(function(t,u){if(!n.has(t))return r.createElement(i,{v:t,i:u,children:e.children,cache:n});else return n.get(t)});return r.createElement(r.Fragment,null,f)};e.Show=function(e){var n=e.when.value;if(!n)return e.fallback||null;else return r.createElement(i,{v:n,children:e.children})};e.useLiveSignal=function(e){var r=n.useSignal(e);if(r.peek()!==e)r.value=e;return r};e.useSignalRef=function(e){var r=n.useSignal(e);if(!("current"in r))Object.defineProperty(r,"current",u);return r}});//# sourceMappingURL=utils.min.js.map
1
+ !function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@preact/signals"),require("preact"),require("preact/hooks")):"function"==typeof define&&define.amd?define(["exports","@preact/signals","preact","preact/hooks"],e):e((n||self).preactSignalsutils={},n.signals,n.preact,n.preactHooks)}(this,function(n,e,t,r){var i=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children},u={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};n.For=function(n){var e=r.useMemo(function(){return new Map},[]),u=("function"==typeof n.each?n.each():n.each).value;if(!u.length)return n.fallback||null;var f=new Set(e.keys()),o=u.map(function(r,u){f.delete(r);if(!e.has(r)){var o=t.createElement(i,{v:r,i:u,children:n.children});e.set(r,o);return o}return e.get(r)});f.forEach(function(n){e.delete(n)});return t.createElement(t.Fragment,null,o)};n.Show=function(n){var e="function"==typeof n.when?n.when():n.when.value;if(!e)return n.fallback||null;else return t.createElement(i,{v:e,children:n.children})};n.useLiveSignal=function(n){var t=e.useSignal(n);if(t.peek()!==n)t.value=n;return t};n.useSignalRef=function(n){var t=e.useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",u);return t}});//# sourceMappingURL=utils.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.min.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, JSX } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T>;\n\tfallback?: JSX.Element;\n\tchildren: JSX.Element | ((value: NonNullable<T>) => JSX.Element);\n}\n\nconst Item = (props: any) => {\n\tconst result =\n\t\ttypeof props.children === \"function\"\n\t\t\t? props.children(props.v, props.i)\n\t\t\t: props.children;\n\tif (props.cache) {\n\t\tprops.cache.set(props.v, result);\n\t}\n\treturn result;\n};\n\nexport function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {\n\tconst value = props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: JSX.Element;\n\tchildren: (value: T, index: number) => JSX.Element;\n}\n\nexport function For<T>(props: ForProps<T>): JSX.Element | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst items = list.map((value, key) => {\n\t\tif (!cache.has(value)) {\n\t\t\treturn <Item v={value} i={key} children={props.children} cache={cache} />;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(\n\tvalue: Signal<T> | ReadonlySignal<T>\n): Signal<Signal<T> | ReadonlySignal<T>> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["g","f","exports","module","require","define","amd","globalThis","self","preactSignalsutils","signals","preact","preactHooks","this","hooks","Item","props","result","children","v","i","cache","set","refSignalProto","configurable","get","value","For","useMemo","Map","list","each","length","fallback","items","map","key","has","createElement","Fragment","Show","when","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"CAWA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,QAAA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UACxC,EAqDChB,EAAAwC,uBArBAhB,GAEA,IAAMiB,EAAIC,EAAAA,UAAUlB,GACpB,GAAIiB,EAAEE,SAAWnB,EAAOiB,EAAEjB,MAAQA,EAClC,OAAOiB,CACR,EAgBCzC,EAAA4C,aAde,SAAgBpB,GAC/B,IAAMqB,EAAMH,EAAAA,UAAUlB,GACtB,KAAM,YAAaqB,GAClBC,OAAOC,eAAeF,EAAK,UAAWxB,GACvC,OAAOwB,CACR,CASC"}
1
+ {"version":3,"file":"utils.min.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["g","f","exports","module","require","define","amd","globalThis","self","preactSignalsutils","signals","preact","preactHooks","this","hooks","Item","props","children","v","i","refSignalProto","configurable","get","value","set","For","cache","useMemo","Map","list","each","length","fallback","removed","Set","keys","items","map","key","has","result","createElement","forEach","Fragment","Show","when","useLiveSignal","s","useSignal","peek","useSignalRef","ref","Object","defineProperty"],"mappings":"CAWA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,QAAAE,QAAA,mBAAAA,QAAA,UAAAA,QAAA,iBAAA,mBAAAC,QAAAA,OAAAC,IAAAD,OAAA,CAAA,UAAA,kBAAA,SAAA,gBAAAJ,GAAAA,GAAAD,EAAA,oBAAAO,WAAAA,WAAAP,GAAAQ,MAAAC,mBAAA,CAAA,EAAAT,EAAAU,QAAAV,EAAAW,OAAAX,EAAAY,YAAA,CAAA,CAAAC,KAAA,SAAAX,EAAAQ,EAAAC,EAAAG,GAAA,IAAMC,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EA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C,OAAOC,eAAeF,EAAK,UAAW/B,GACvC,OAAO+B,CACR,CASC"}
@@ -1 +1 @@
1
- import{useSignal}from"@preact/signals";import{createElement as n,Fragment as t}from"preact";import{useMemo as r}from"preact/hooks";const e=n=>{const t="function"==typeof n.children?n.children(n.v,n.i):n.children;if(n.cache)n.cache.set(n.v,t);return t};function o(t){const r=t.when.value;if(!r)return t.fallback||null;else return n(e,{v:r,children:t.children})}function c(o){const c=r(()=>new Map,[]);let i=("function"==typeof o.each?o.each():o.each).value;if(!i.length)return o.fallback||null;const u=i.map((t,r)=>{if(!c.has(t))return n(e,{v:t,i:r,children:o.children,cache:c});else return c.get(t)});return n(t,null,u)}function i(n){const t=useSignal(n);if(t.peek()!==n)t.value=n;return t}function u(n){const t=useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",f);return t}const f={configurable:!0,get(){return this.value},set(n){this.value=n}};export{c as For,o as Show,i as useLiveSignal,u as useSignalRef};//# sourceMappingURL=utils.mjs.map
1
+ import{useSignal}from"@preact/signals";import{createElement as n,Fragment as t}from"preact";import{useMemo as r}from"preact/hooks";const e=n=>"function"==typeof n.children?n.children(n.v,n.i):n.children;function o(t){const r="function"==typeof t.when?t.when():t.when.value;if(!r)return t.fallback||null;else return n(e,{v:r,children:t.children})}function c(o){const c=r(()=>new Map,[]);let i=("function"==typeof o.each?o.each():o.each).value;if(!i.length)return o.fallback||null;const u=new Set(c.keys()),f=i.map((t,r)=>{u.delete(t);if(!c.has(t)){const i=n(e,{v:t,i:r,children:o.children});c.set(t,i);return i}return c.get(t)});u.forEach(n=>{c.delete(n)});return n(t,null,f)}function i(n){const t=useSignal(n);if(t.peek()!==n)t.value=n;return t}function u(n){const t=useSignal(n);if(!("current"in t))Object.defineProperty(t,"current",f);return t}const f={configurable:!0,get(){return this.value},set(n){this.value=n}};export{c as For,o as Show,i as useLiveSignal,u as useSignalRef};//# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, JSX } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T>;\n\tfallback?: JSX.Element;\n\tchildren: JSX.Element | ((value: NonNullable<T>) => JSX.Element);\n}\n\nconst Item = (props: any) => {\n\tconst result =\n\t\ttypeof props.children === \"function\"\n\t\t\t? props.children(props.v, props.i)\n\t\t\t: props.children;\n\tif (props.cache) {\n\t\tprops.cache.set(props.v, result);\n\t}\n\treturn result;\n};\n\nexport function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {\n\tconst value = props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: JSX.Element;\n\tchildren: (value: T, index: number) => JSX.Element;\n}\n\nexport function For<T>(props: ForProps<T>): JSX.Element | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst items = list.map((value, key) => {\n\t\tif (!cache.has(value)) {\n\t\t\treturn <Item v={value} i={key} children={props.children} cache={cache} />;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(\n\tvalue: Signal<T> | ReadonlySignal<T>\n): Signal<Signal<T> | ReadonlySignal<T>> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","result","children","v","i","cache","set","Show","value","when","fallback","For","Map","list","each","length","items","map","key","has","get","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,MAAMC,EAAQC,IACb,MAAMC,EACqB,mBAAnBD,EAAME,SACVF,EAAME,SAASF,EAAMG,EAAGH,EAAMI,GAC9BJ,EAAME,SACV,GAAIF,EAAMK,MACTL,EAAMK,MAAMC,IAAIN,EAAMG,EAAGF,GAE1B,OAAOA,GAGF,SAAUM,EAAkBP,GACjC,MAAMQ,EAAQR,EAAMS,KAAKD,MACzB,IAAKA,EAAO,OAAOR,EAAMU,UAAY,UACrC,OAAOd,EAACG,EAAK,CAAAI,EAAGK,EAAON,SAAUF,EAAME,UACxC,CAWM,SAAUS,EAAOX,GACtB,MAAMK,EAAQP,EAAQ,IAAM,IAAIc,IAAO,IACvC,IAAIC,GACoB,mBAAfb,EAAMc,KAAsBd,EAAMc,OAASd,EAAMc,MAGxDN,MAEF,IAAKK,EAAKE,OAAQ,OAAOf,EAAMU,UAAY,KAE3C,MAAMM,EAAQH,EAAKI,IAAI,CAACT,EAAOU,KAC9B,IAAKb,EAAMc,IAAIX,GACd,OAAOZ,EAACG,EAAK,CAAAI,EAAGK,EAAOJ,EAAGc,EAAKhB,SAAUF,EAAME,SAAUG,MAAOA,SAEjE,OAAOA,EAAMe,IAAIZ,EAAK,GAGvB,OAAOZ,EAAcC,EAAU,KAAMmB,EACtC,CAEgB,SAAAK,EACfb,GAEA,MAAMc,EAAI3B,UAAUa,GACpB,GAAIc,EAAEC,SAAWf,EAAOc,EAAEd,MAAQA,EAClC,OAAOc,CACR,CAEM,SAAUE,EAAgBhB,GAC/B,MAAMiB,EAAM9B,UAAUa,GACtB,KAAM,YAAaiB,GAClBC,OAAOC,eAAeF,EAAK,UAAWG,GACvC,OAAOH,CACR,CACA,MAAMG,EAAiB,CACtBC,cAAc,EACdT,MACC,YAAYZ,KACb,EACAF,IAAkBH,GACjB2B,KAAKtB,MAAQL,CACd,UACAQ,SAAAJ,UAAAc,mBAAAG"}
1
+ {"version":3,"file":"utils.mjs","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","children","v","i","Show","value","when","fallback","For","cache","Map","list","each","length","removed","Set","keys","items","map","key","delete","has","result","set","get","forEach","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,MAAMC,EAAQC,GACoB,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,kBAGMG,EACfJ,GAEA,MAAMK,EACiB,mBAAfL,EAAMM,KAAsBN,EAAMM,OAASN,EAAMM,KAAKD,MAC9D,IAAKA,EAAO,OAAOL,EAAMO,UAAY,UACrC,OAAOX,EAACG,EAAK,CAAAG,EAAGG,EAAOJ,SAAUD,EAAMC,UACxC,UAWgBO,EAAOR,GACtB,MAAMS,EAAQX,EAAQ,IAAM,IAAIY,IAAO,IACvC,IAAIC,GACoB,mBAAfX,EAAMY,KAAsBZ,EAAMY,OAASZ,EAAMY,MAGxDP,MAEF,IAAKM,EAAKE,OAAQ,OAAOb,EAAMO,UAAY,KAE3C,MAAMO,EAAU,IAAIC,IAAIN,EAAMO,QAExBC,EAAQN,EAAKO,IAAI,CAACb,EAAOc,KAC9BL,EAAQM,OAAOf,GACf,IAAKI,EAAMY,IAAIhB,GAAQ,CACtB,MAAMiB,EAAS1B,EAACG,EAAK,CAAAG,EAAGG,EAAOF,EAAGgB,EAAKlB,SAAUD,EAAMC,WACvDQ,EAAMc,IAAIlB,EAAOiB,GACjB,OAAOA,CACR,CACA,OAAOb,EAAMe,IAAInB,EAAK,GAGvBS,EAAQW,QAAQpB,IACfI,EAAMW,OAAOf,EACd,GAEA,OAAOT,EAAcC,EAAU,KAAMoB,EACtC,CAEM,SAAUS,EAAiBrB,GAChC,MAAMsB,EAAIhC,UAAUU,GACpB,GAAIsB,EAAEC,SAAWvB,EAAOsB,EAAEtB,MAAQA,EAClC,OAAOsB,CACR,UAEgBE,EAAgBxB,GAC/B,MAAMyB,EAAMnC,UAAUU,GACtB,KAAM,YAAayB,GAClBC,OAAOC,eAAeF,EAAK,UAAWG,GACvC,OAAOH,CACR,CACA,MAAMG,EAAiB,CACtBC,cAAc,EACdV,MACC,OAAOW,KAAK9B,KACb,EACAkB,IAAkBrB,GACjBiC,KAAK9B,MAAQH,CACd,UACAM,SAAAJ,UAAAsB,mBAAAG"}
@@ -1 +1 @@
1
- import{useSignal}from"@preact/signals";import{createElement as r,Fragment as n}from"preact";import{useMemo as t}from"preact/hooks";var e=function(r){var n="function"==typeof r.children?r.children(r.v,r.i):r.children;if(r.cache)r.cache.set(r.v,n);return n};function i(n){var t=n.when.value;if(!t)return n.fallback||null;else return r(e,{v:t,children:n.children})}function u(i){var u=t(function(){return new Map},[]),f=("function"==typeof i.each?i.each():i.each).value;if(!f.length)return i.fallback||null;var o=f.map(function(n,t){if(!u.has(n))return r(e,{v:n,i:t,children:i.children,cache:u});else return u.get(n)});return r(n,null,o)}function f(r){var n=useSignal(r);if(n.peek()!==r)n.value=r;return n}function o(r){var n=useSignal(r);if(!("current"in n))Object.defineProperty(n,"current",c);return n}var c={configurable:!0,get:function(){return this.value},set:function(r){this.value=r}};export{u as For,i as Show,f as useLiveSignal,o as useSignalRef};//# sourceMappingURL=utils.module.js.map
1
+ import{useSignal}from"@preact/signals";import{createElement as n,Fragment as r}from"preact";import{useMemo as t}from"preact/hooks";var e=function(n){return"function"==typeof n.children?n.children(n.v,n.i):n.children};function u(r){var t="function"==typeof r.when?r.when():r.when.value;if(!t)return r.fallback||null;else return n(e,{v:t,children:r.children})}function i(u){var i=t(function(){return new Map},[]),o=("function"==typeof u.each?u.each():u.each).value;if(!o.length)return u.fallback||null;var f=new Set(i.keys()),c=o.map(function(r,t){f.delete(r);if(!i.has(r)){var o=n(e,{v:r,i:t,children:u.children});i.set(r,o);return o}return i.get(r)});f.forEach(function(n){i.delete(n)});return n(r,null,c)}function o(n){var r=useSignal(n);if(r.peek()!==n)r.value=n;return r}function f(n){var r=useSignal(n);if(!("current"in r))Object.defineProperty(r,"current",c);return r}var c={configurable:!0,get:function(){return this.value},set:function(n){this.value=n}};export{i as For,u as Show,o as useLiveSignal,f as useSignalRef};//# sourceMappingURL=utils.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.module.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, JSX } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T>;\n\tfallback?: JSX.Element;\n\tchildren: JSX.Element | ((value: NonNullable<T>) => JSX.Element);\n}\n\nconst Item = (props: any) => {\n\tconst result =\n\t\ttypeof props.children === \"function\"\n\t\t\t? props.children(props.v, props.i)\n\t\t\t: props.children;\n\tif (props.cache) {\n\t\tprops.cache.set(props.v, result);\n\t}\n\treturn result;\n};\n\nexport function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {\n\tconst value = props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: JSX.Element;\n\tchildren: (value: T, index: number) => JSX.Element;\n}\n\nexport function For<T>(props: ForProps<T>): JSX.Element | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst items = list.map((value, key) => {\n\t\tif (!cache.has(value)) {\n\t\t\treturn <Item v={value} i={key} children={props.children} cache={cache} />;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(\n\tvalue: Signal<T> | ReadonlySignal<T>\n): Signal<Signal<T> | ReadonlySignal<T>> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","result","children","v","i","cache","set","Show","value","when","fallback","For","Map","list","each","length","items","map","key","has","get","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,IAAMC,EAAO,SAACC,GACb,IAAMC,EACqB,mBAAnBD,EAAME,SACVF,EAAME,SAASF,EAAMG,EAAGH,EAAMI,GAC9BJ,EAAME,SACV,GAAIF,EAAMK,MACTL,EAAMK,MAAMC,IAAIN,EAAMG,EAAGF,GAE1B,OAAOA,CACR,EAEgB,SAAAM,EAAkBP,GACjC,IAAMQ,EAAQR,EAAMS,KAAKD,MACzB,IAAKA,EAAO,OAAOR,EAAMU,UAAY,UACrC,OAAOd,EAACG,EAAK,CAAAI,EAAGK,EAAON,SAAUF,EAAME,UACxC,UAWgBS,EAAOX,GACtB,IAAMK,EAAQP,EAAQ,WAAM,OAAA,IAAIc,GAAK,EAAE,IACnCC,GACoB,mBAAfb,EAAMc,KAAsBd,EAAMc,OAASd,EAAMc,MAGxDN,MAEF,IAAKK,EAAKE,OAAQ,OAAOf,EAAMU,UAAY,KAE3C,IAAMM,EAAQH,EAAKI,IAAI,SAACT,EAAOU,GAC9B,IAAKb,EAAMc,IAAIX,GACd,OAAOZ,EAACG,EAAK,CAAAI,EAAGK,EAAOJ,EAAGc,EAAKhB,SAAUF,EAAME,SAAUG,MAAOA,SAEjE,OAAOA,EAAMe,IAAIZ,EAClB,GAEA,OAAOZ,EAAcC,EAAU,KAAMmB,EACtC,UAEgBK,EACfb,GAEA,IAAMc,EAAI3B,UAAUa,GACpB,GAAIc,EAAEC,SAAWf,EAAOc,EAAEd,MAAQA,EAClC,OAAOc,CACR,CAEgB,SAAAE,EAAgBhB,GAC/B,IAAMiB,EAAM9B,UAAUa,GACtB,KAAM,YAAaiB,GAClBC,OAAOC,eAAeF,EAAK,UAAWG,GACvC,OAAOH,CACR,CACA,IAAMG,EAAiB,CACtBC,cAAc,EACdT,IAAG,WACF,YAAYZ,KACb,EACAF,aAAkBH,GACjB2B,KAAKtB,MAAQL,CACd,UACAQ,SAAAJ,UAAAc,mBAAAG"}
1
+ {"version":3,"file":"utils.module.js","sources":["../src/index.tsx"],"sourcesContent":["import { ReadonlySignal, Signal } from \"@preact/signals-core\";\nimport { useSignal } from \"@preact/signals\";\nimport { Fragment, createElement, ComponentChildren } from \"preact\";\nimport { useMemo } from \"preact/hooks\";\n\ninterface ShowProps<T = boolean> {\n\twhen: Signal<T> | ReadonlySignal<T> | (() => T);\n\tfallback?: ComponentChildren;\n\tchildren: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);\n}\n\nconst Item = (props: any) => {\n\treturn typeof props.children === \"function\"\n\t\t? props.children(props.v, props.i)\n\t\t: props.children;\n};\n\nexport function Show<T = boolean>(\n\tprops: ShowProps<T>\n): ComponentChildren | null {\n\tconst value =\n\t\ttypeof props.when === \"function\" ? props.when() : props.when.value;\n\tif (!value) return props.fallback || null;\n\treturn <Item v={value} children={props.children} />;\n}\n\ninterface ForProps<T> {\n\teach:\n\t\t| Signal<Array<T>>\n\t\t| ReadonlySignal<Array<T>>\n\t\t| (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);\n\tfallback?: ComponentChildren;\n\tchildren: (value: T, index: number) => ComponentChildren;\n}\n\nexport function For<T>(props: ForProps<T>): ComponentChildren | null {\n\tconst cache = useMemo(() => new Map(), []);\n\tlet list = (\n\t\t(typeof props.each === \"function\" ? props.each() : props.each) as Signal<\n\t\t\tArray<T>\n\t\t>\n\t).value;\n\n\tif (!list.length) return props.fallback || null;\n\n\tconst removed = new Set(cache.keys());\n\n\tconst items = list.map((value, key) => {\n\t\tremoved.delete(value);\n\t\tif (!cache.has(value)) {\n\t\t\tconst result = <Item v={value} i={key} children={props.children} />;\n\t\t\tcache.set(value, result);\n\t\t\treturn result;\n\t\t}\n\t\treturn cache.get(value);\n\t});\n\n\tremoved.forEach(value => {\n\t\tcache.delete(value);\n\t});\n\n\treturn createElement(Fragment, null, items);\n}\n\nexport function useLiveSignal<T>(value: T): Signal<T> {\n\tconst s = useSignal(value);\n\tif (s.peek() !== value) s.value = value;\n\treturn s;\n}\n\nexport function useSignalRef<T>(value: T): Signal<T> & { current: T } {\n\tconst ref = useSignal(value) as Signal<T> & { current: T };\n\tif (!(\"current\" in ref))\n\t\tObject.defineProperty(ref, \"current\", refSignalProto);\n\treturn ref;\n}\nconst refSignalProto = {\n\tconfigurable: true,\n\tget(this: Signal) {\n\t\treturn this.value;\n\t},\n\tset(this: Signal, v: any) {\n\t\tthis.value = v;\n\t},\n};\n"],"names":["useSignal","createElement","Fragment","useMemo","Item","props","children","v","i","Show","value","when","fallback","For","cache","Map","list","each","length","removed","Set","keys","items","map","key","has","result","set","get","forEach","useLiveSignal","s","peek","useSignalRef","ref","Object","defineProperty","refSignalProto","configurable","this"],"mappings":"OAWAA,cAAA,0CAAAC,cAAAC,MAAA,2BAAAC,MAAA,eAAA,IAAMC,EAAO,SAACC,GACb,MAAiC,mBAAnBA,EAAMC,SACjBD,EAAMC,SAASD,EAAME,EAAGF,EAAMG,GAC9BH,EAAMC,QACV,WAEgBG,EACfJ,GAEA,IAAMK,EACiB,mBAAfL,EAAMM,KAAsBN,EAAMM,OAASN,EAAMM,KAAKD,MAC9D,IAAKA,EAAO,OAAOL,EAAMO,UAAY,UACrC,OAAOX,EAACG,EAAK,CAAAG,EAAGG,EAAOJ,SAAUD,EAAMC,UACxC,CAWgB,SAAAO,EAAOR,GACtB,IAAMS,EAAQX,EAAQ,WAAM,OAAA,IAAIY,GAAK,EAAE,IACnCC,GACoB,mBAAfX,EAAMY,KAAsBZ,EAAMY,OAASZ,EAAMY,MAGxDP,MAEF,IAAKM,EAAKE,OAAQ,OAAOb,EAAMO,UAAY,KAE3C,IAAMO,EAAU,IAAIC,IAAIN,EAAMO,QAExBC,EAAQN,EAAKO,IAAI,SAACb,EAAOc,GAC9BL,SAAeT,GACf,IAAKI,EAAMW,IAAIf,GAAQ,CACtB,IAAMgB,EAASzB,EAACG,EAAK,CAAAG,EAAGG,EAAOF,EAAGgB,EAAKlB,SAAUD,EAAMC,WACvDQ,EAAMa,IAAIjB,EAAOgB,GACjB,OAAOA,CACR,CACA,OAAOZ,EAAMc,IAAIlB,EAClB,GAEAS,EAAQU,QAAQ,SAAAnB,GACfI,EAAY,OAACJ,EACd,GAEA,OAAOT,EAAcC,EAAU,KAAMoB,EACtC,CAEgB,SAAAQ,EAAiBpB,GAChC,IAAMqB,EAAI/B,UAAUU,GACpB,GAAIqB,EAAEC,SAAWtB,EAAOqB,EAAErB,MAAQA,EAClC,OAAOqB,CACR,CAEgB,SAAAE,EAAgBvB,GAC/B,IAAMwB,EAAMlC,UAAUU,GACtB,KAAM,YAAawB,GAClBC,OAAOC,eAAeF,EAAK,UAAWG,GACvC,OAAOH,CACR,CACA,IAAMG,EAAiB,CACtBC,cAAc,EACdV,IAAA,WACC,OAAOW,KAAK7B,KACb,EACAiB,IAAA,SAAkBpB,GACjBgC,KAAK7B,MAAQH,CACd,UACAM,SAAAJ,UAAAqB,mBAAAG"}
@@ -1,27 +1,25 @@
1
1
  import { ReadonlySignal, Signal } from "@preact/signals-core";
2
2
  import { useSignal } from "@preact/signals";
3
- import { Fragment, createElement, JSX } from "preact";
3
+ import { Fragment, createElement, ComponentChildren } from "preact";
4
4
  import { useMemo } from "preact/hooks";
5
5
 
6
6
  interface ShowProps<T = boolean> {
7
- when: Signal<T> | ReadonlySignal<T>;
8
- fallback?: JSX.Element;
9
- children: JSX.Element | ((value: NonNullable<T>) => JSX.Element);
7
+ when: Signal<T> | ReadonlySignal<T> | (() => T);
8
+ fallback?: ComponentChildren;
9
+ children: ComponentChildren | ((value: NonNullable<T>) => ComponentChildren);
10
10
  }
11
11
 
12
12
  const Item = (props: any) => {
13
- const result =
14
- typeof props.children === "function"
15
- ? props.children(props.v, props.i)
16
- : props.children;
17
- if (props.cache) {
18
- props.cache.set(props.v, result);
19
- }
20
- return result;
13
+ return typeof props.children === "function"
14
+ ? props.children(props.v, props.i)
15
+ : props.children;
21
16
  };
22
17
 
23
- export function Show<T = boolean>(props: ShowProps<T>): JSX.Element | null {
24
- const value = props.when.value;
18
+ export function Show<T = boolean>(
19
+ props: ShowProps<T>
20
+ ): ComponentChildren | null {
21
+ const value =
22
+ typeof props.when === "function" ? props.when() : props.when.value;
25
23
  if (!value) return props.fallback || null;
26
24
  return <Item v={value} children={props.children} />;
27
25
  }
@@ -31,11 +29,11 @@ interface ForProps<T> {
31
29
  | Signal<Array<T>>
32
30
  | ReadonlySignal<Array<T>>
33
31
  | (() => Signal<Array<T>> | ReadonlySignal<Array<T>>);
34
- fallback?: JSX.Element;
35
- children: (value: T, index: number) => JSX.Element;
32
+ fallback?: ComponentChildren;
33
+ children: (value: T, index: number) => ComponentChildren;
36
34
  }
37
35
 
38
- export function For<T>(props: ForProps<T>): JSX.Element | null {
36
+ export function For<T>(props: ForProps<T>): ComponentChildren | null {
39
37
  const cache = useMemo(() => new Map(), []);
40
38
  let list = (
41
39
  (typeof props.each === "function" ? props.each() : props.each) as Signal<
@@ -45,19 +43,26 @@ export function For<T>(props: ForProps<T>): JSX.Element | null {
45
43
 
46
44
  if (!list.length) return props.fallback || null;
47
45
 
46
+ const removed = new Set(cache.keys());
47
+
48
48
  const items = list.map((value, key) => {
49
+ removed.delete(value);
49
50
  if (!cache.has(value)) {
50
- return <Item v={value} i={key} children={props.children} cache={cache} />;
51
+ const result = <Item v={value} i={key} children={props.children} />;
52
+ cache.set(value, result);
53
+ return result;
51
54
  }
52
55
  return cache.get(value);
53
56
  });
54
57
 
58
+ removed.forEach(value => {
59
+ cache.delete(value);
60
+ });
61
+
55
62
  return createElement(Fragment, null, items);
56
63
  }
57
64
 
58
- export function useLiveSignal<T>(
59
- value: Signal<T> | ReadonlySignal<T>
60
- ): Signal<Signal<T> | ReadonlySignal<T>> {
65
+ export function useLiveSignal<T>(value: T): Signal<T> {
61
66
  const s = useSignal(value);
62
67
  if (s.peek() !== value) s.value = value;
63
68
  return s;