Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@preact/signals

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@preact/signals - npm Package Compare versions

Comparing version 1.3.1 to 2.0.0

25

CHANGELOG.md
# @preact/signals
## 1.3.1
## 2.0.0
### Major Changes
- [#604](https://github.com/preactjs/signals/pull/604) [`fea3e8d`](https://github.com/preactjs/signals/commit/fea3e8da7a36944d87310678fad291aeacc55d8d) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Defer all DOM updates by an animation frame, this should make it so
that any previously synchronous DOM update will be instead delayed by an
animation frame. This allows Preact to first perform its own render
cycle and then our direct DOM updates to occur. These will now
be performed in a batched way which is more performant as the browser
is prepared to handle these during the animation frame.
This does impact how Preact based signals are tested, when
you perform a signal update, you'll need to wrap it in `act`. In a way
this was always the case, as a signal update that resulted in
a Preact state update would require it to be wrapped in `act`, but
now this is the norm.
### Minor Changes
- [#595](https://github.com/preactjs/signals/pull/595) [`499428a`](https://github.com/preactjs/signals/commit/499428aa7e7db3e250b3c257debf054a6368c010) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Align signal effects with animation-frames for better performance
### Patch Changes
- [#620](https://github.com/preactjs/signals/pull/620) [`4cda002`](https://github.com/preactjs/signals/commit/4cda002b9661b0fc936e9659e59d8b5979e7793b) Thanks [@developit](https://github.com/developit)! - Simplify text update patch to avoid using new internals
- [#609](https://github.com/preactjs/signals/pull/609) [`8e6e2de`](https://github.com/preactjs/signals/commit/8e6e2de5a2af27832ea139a7b76fc63ae56cc1f1) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Change timing to a double microtask so we are behind the Preact render queue but can't delay as much as a user-input coming in.
- [#618](https://github.com/preactjs/signals/pull/618) [`021c726`](https://github.com/preactjs/signals/commit/021c726452046614eadae548d54af6ccb9832c14) Thanks [@JoviDeCroock](https://github.com/JoviDeCroock)! - Ensure that the Effects versions are updated when using it as a JSX Signal
## 1.3.0

@@ -12,0 +29,0 @@

2

dist/signals.js

@@ -1,1 +0,1 @@

var r,i,n=require("preact"),t=require("preact/hooks"),f=require("@preact/signals-core");function o(r,i){n.options[r]=i.bind(null,n.options[r]||function(){})}function e(r){if(i)i();i=r&&r.S()}function u(r){var i=this,o=r.data,e=useSignal(o);e.value=o;var u=t.useMemo(function(){var r=i.__v;while(r=r.__)if(r.__c){r.__c.__$f|=4;break}i.__$u.c=function(){var r,t=i.__$u.S(),f=u.value;t();if(n.isValidElement(f)||3!==(null==(r=i.base)?void 0:r.nodeType)){i.__$f|=1;i.setState({})}else i.base.data=f};return f.computed(function(){var r=e.value.value;return 0===r?0:!0===r?"":r||""})},[]);return u.value}u.displayName="_st";Object.defineProperties(f.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:u},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});o("__b",function(r,i){if("string"==typeof i.type){var n,t=i.props;for(var o in t)if("children"!==o){var e=t[o];if(e instanceof f.Signal){if(!n)i.__np=n={};n[o]=e;t[o]=e.peek()}}}r(i)});o("__r",function(i,n){e();var t,o=n.__c;if(o){o.__$f&=-2;if(void 0===(t=o.__$u))o.__$u=t=function(r){var i;f.effect(function(){i=this});i.c=function(){o.__$f|=1;o.setState({})};return i}()}r=o;e(t);i(n)});o("__e",function(i,n,t,f){e();r=void 0;i(n,t,f)});o("diffed",function(i,n){e();r=void 0;var t;if("string"==typeof n.type&&(t=n.__e)){var f=n.__np,o=n.props;if(f){var u=t.U;if(u)for(var v in u){var c=u[v];if(void 0!==c&&!(v in f)){c.d();u[v]=void 0}}else t.U=u={};for(var s in f){var l=u[s],p=f[s];if(void 0===l){l=a(t,s,p,o);u[s]=l}else l.o(p,o)}}}i(n)});function a(r,i,n,t){var o=i in r&&void 0===r.ownerSVGElement,e=f.signal(n);return{o:function(r,i){e.value=r;t=i},d:f.effect(function(){var n=e.value.value;if(t[i]!==n){t[i]=n;if(o)r[i]=n;else if(n)r.setAttribute(i,n);else r.removeAttribute(i)}})}}o("unmount",function(r,i){if("string"==typeof i.type){var n=i.__e;if(n){var t=n.U;if(t){n.U=void 0;for(var f in t){var o=t[f];if(o)o.d()}}}}else{var e=i.__c;if(e){var u=e.__$u;if(u){e.__$u=void 0;u.d()}}}r(i)});o("__h",function(r,i,n,t){if(t<3||9===t)i.__$f|=2;r(i,n,t)});n.Component.prototype.shouldComponentUpdate=function(r,i){var n=this.__$u;if(!(n&&void 0!==n.s||4&this.__$f))return!0;if(3&this.__$f)return!0;for(var t in i)return!0;for(var f in r)if("__source"!==f&&r[f]!==this.props[f])return!0;for(var o in this.props)if(!(o in r))return!0;return!1};function useSignal(r){return t.useMemo(function(){return f.signal(r)},[])}exports.Signal=f.Signal;exports.batch=f.batch;exports.computed=f.computed;exports.effect=f.effect;exports.signal=f.signal;exports.untracked=f.untracked;exports.useComputed=function(i){var n=t.useRef(i);n.current=i;r.__$f|=4;return t.useMemo(function(){return f.computed(function(){return n.current()})},[])};exports.useSignal=useSignal;exports.useSignalEffect=function(r){var i=t.useRef(r);i.current=r;t.useEffect(function(){return f.effect(function(){return i.current()})},[])};//# sourceMappingURL=signals.js.map
var i,n,r=require("preact"),t=require("preact/hooks"),f=require("@preact/signals-core");function o(i,n){r.options[i]=n.bind(null,r.options[i]||function(){})}function e(i){if(n)n();n=i&&i.S()}function u(i){var n=this,o=i.data,e=useSignal(o);e.value=o;var u=t.useMemo(function(){var i=n,t=n.__v;while(t=t.__)if(t.__c){t.__c.__$f|=4;break}var o=f.computed(function(){var i=e.value.value;return 0===i?0:!0===i?"":i||""}),a=f.computed(function(){var i;return r.isValidElement(o.value)||3!==(null==(i=n.base)?void 0:i.nodeType)});n.__$u.c=function(){var i;if(!r.isValidElement(u.peek())&&3===(null==(i=n.base)?void 0:i.nodeType))n.base.data=u.peek();else{n.__$f|=1;n.setState({})}};f.effect(function(){if(!c)c=this.N;this.N=g;if(a.value&&i.base)i.base.data=o.value});return o},[]);return u.value}u.displayName="_st";Object.defineProperties(f.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:u},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});o("__b",function(i,n){if("string"==typeof n.type){var r,t=n.props;for(var o in t)if("children"!==o){var e=t[o];if(e instanceof f.Signal){if(!r)n.__np=r={};r[o]=e;t[o]=e.peek()}}}i(n)});o("__r",function(n,r){e();var t,o=r.__c;if(o){o.__$f&=-2;if(void 0===(t=o.__$u))o.__$u=t=function(i){var n;f.effect(function(){n=this});n.c=function(){o.__$f|=1;o.setState({})};return n}()}i=o;e(t);n(r)});o("__e",function(n,r,t,f){e();i=void 0;n(r,t,f)});o("diffed",function(n,r){e();i=void 0;var t;if("string"==typeof r.type&&(t=r.__e)){var f=r.__np,o=r.props;if(f){var u=t.U;if(u)for(var c in u){var v=u[c];if(void 0!==v&&!(c in f)){v.d();u[c]=void 0}}else t.U=u={};for(var s in f){var l=u[s],h=f[s];if(void 0===l){l=a(t,s,h,o);u[s]=l}else l.o(h,o)}}}n(r)});function a(i,n,r,t){var o=n in i&&void 0===i.ownerSVGElement,e=f.signal(r);return{o:function(i,n){e.value=i;t=n},d:f.effect(function(){if(!c)c=this.N;this.N=g;var r=e.value.value;if(t[n]!==r){t[n]=r;if(o)i[n]=r;else if(r)i.setAttribute(n,r);else i.removeAttribute(n)}})}}o("unmount",function(i,n){if("string"==typeof n.type){var r=n.__e;if(r){var t=r.U;if(t){r.U=void 0;for(var f in t){var o=t[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)});o("__h",function(i,n,r,t){if(t<3||9===t)n.__$f|=2;i(n,r,t)});r.Component.prototype.shouldComponentUpdate=function(i,n){var r=this.__$u;if(!(r&&void 0!==r.s||4&this.__$f))return!0;if(3&this.__$f)return!0;for(var t in n)return!0;for(var f in i)if("__source"!==f&&i[f]!==this.props[f])return!0;for(var o in this.props)if(!(o in i))return!0;return!1};function useSignal(i){return t.useMemo(function(){return f.signal(i)},[])}var c,v=[],s=[],l="undefined"==typeof requestAnimationFrame?setTimeout:requestAnimationFrame,h=function(i){queueMicrotask(function(){queueMicrotask(i)})};function d(){f.batch(function(){var i;while(i=v.shift())c.call(i)})}function p(){if(1===v.push(this))(r.options.requestAnimationFrame||l)(d)}function _(){f.batch(function(){var i;while(i=s.shift())c.call(i)})}function g(){if(1===s.push(this))(r.options.requestAnimationFrame||h)(_)}exports.Signal=f.Signal;exports.batch=f.batch;exports.computed=f.computed;exports.effect=f.effect;exports.signal=f.signal;exports.untracked=f.untracked;exports.useComputed=function(n){var r=t.useRef(n);r.current=n;i.__$f|=4;return t.useMemo(function(){return f.computed(function(){return r.current()})},[])};exports.useSignal=useSignal;exports.useSignalEffect=function(i){var n=t.useRef(i);n.current=i;t.useEffect(function(){return f.effect(function(){if(!c)c=this.N;this.N=p;return n.current()})},[])};//# sourceMappingURL=signals.js.map

@@ -1,1 +0,1 @@

!function(n,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("preact"),require("preact/hooks"),require("@preact/signals-core")):"function"==typeof define&&define.amd?define(["exports","preact","preact/hooks","@preact/signals-core"],i):i((n||self).preactSignals={},n.preact,n.preactHooks,n.preactSignalsCore)}(this,function(n,i,r,t){var e,f;function o(n,r){i.options[n]=r.bind(null,i.options[n]||function(){})}function u(n){if(f)f();f=n&&n.S()}function a(n){var e=this,f=n.data,o=useSignal(f);o.value=f;var u=r.useMemo(function(){var n=e.__v;while(n=n.__)if(n.__c){n.__c.__$f|=4;break}e.__$u.c=function(){var n,r=e.__$u.S(),t=u.value;r();if(i.isValidElement(t)||3!==(null==(n=e.base)?void 0:n.nodeType)){e.__$f|=1;e.setState({})}else e.base.data=t};return t.computed(function(){var n=o.value.value;return 0===n?0:!0===n?"":n||""})},[]);return u.value}a.displayName="_st";Object.defineProperties(t.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:a},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});o("__b",function(n,i){if("string"==typeof i.type){var r,e=i.props;for(var f in e)if("children"!==f){var o=e[f];if(o instanceof t.Signal){if(!r)i.__np=r={};r[f]=o;e[f]=o.peek()}}}n(i)});o("__r",function(n,i){u();var r,f=i.__c;if(f){f.__$f&=-2;if(void 0===(r=f.__$u))f.__$u=r=function(n){var i;t.effect(function(){i=this});i.c=function(){f.__$f|=1;f.setState({})};return i}()}e=f;u(r);n(i)});o("__e",function(n,i,r,t){u();e=void 0;n(i,r,t)});o("diffed",function(n,i){u();e=void 0;var r;if("string"==typeof i.type&&(r=i.__e)){var t=i.__np,f=i.props;if(t){var o=r.U;if(o)for(var a in o){var v=o[a];if(void 0!==v&&!(a in t)){v.d();o[a]=void 0}}else r.U=o={};for(var s in t){var l=o[s],d=t[s];if(void 0===l){l=c(r,s,d,f);o[s]=l}else l.o(d,f)}}}n(i)});function c(n,i,r,e){var f=i in n&&void 0===n.ownerSVGElement,o=t.signal(r);return{o:function(n,i){o.value=n;e=i},d:t.effect(function(){var r=o.value.value;if(e[i]!==r){e[i]=r;if(f)n[i]=r;else if(r)n.setAttribute(i,r);else n.removeAttribute(i)}})}}o("unmount",function(n,i){if("string"==typeof i.type){var r=i.__e;if(r){var t=r.U;if(t){r.U=void 0;for(var e in t){var f=t[e];if(f)f.d()}}}}else{var o=i.__c;if(o){var u=o.__$u;if(u){o.__$u=void 0;u.d()}}}n(i)});o("__h",function(n,i,r,t){if(t<3||9===t)i.__$f|=2;n(i,r,t)});i.Component.prototype.shouldComponentUpdate=function(n,i){var r=this.__$u;if(!(r&&void 0!==r.s||4&this.__$f))return!0;if(3&this.__$f)return!0;for(var t in i)return!0;for(var e in n)if("__source"!==e&&n[e]!==this.props[e])return!0;for(var f in this.props)if(!(f in n))return!0;return!1};function useSignal(n){return r.useMemo(function(){return t.signal(n)},[])}n.Signal=t.Signal;n.batch=t.batch;n.computed=t.computed;n.effect=t.effect;n.signal=t.signal;n.untracked=t.untracked;n.useComputed=function(n){var i=r.useRef(n);i.current=n;e.__$f|=4;return r.useMemo(function(){return t.computed(function(){return i.current()})},[])};n.useSignal=useSignal;n.useSignalEffect=function(n){var i=r.useRef(n);i.current=n;r.useEffect(function(){return t.effect(function(){return i.current()})},[])}});//# sourceMappingURL=signals.min.js.map
!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,r,t){var e,f;function o(i,r){n.options[i]=r.bind(null,n.options[i]||function(){})}function u(i){if(f)f();f=i&&i.S()}function a(i){var e=this,f=i.data,o=useSignal(f);o.value=f;var u=r.useMemo(function(){var i=e,r=e.__v;while(r=r.__)if(r.__c){r.__c.__$f|=4;break}var f=t.computed(function(){var i=o.value.value;return 0===i?0:!0===i?"":i||""}),a=t.computed(function(){var i;return n.isValidElement(f.value)||3!==(null==(i=e.base)?void 0:i.nodeType)});e.__$u.c=function(){var i;if(!n.isValidElement(u.peek())&&3===(null==(i=e.base)?void 0:i.nodeType))e.base.data=u.peek();else{e.__$f|=1;e.setState({})}};t.effect(function(){if(!v)v=this.N;this.N=b;if(a.value&&i.base)i.base.data=f.value});return f},[]);return u.value}a.displayName="_st";Object.defineProperties(t.Signal.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:a},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});o("__b",function(i,n){if("string"==typeof n.type){var r,e=n.props;for(var f in e)if("children"!==f){var o=e[f];if(o instanceof t.Signal){if(!r)n.__np=r={};r[f]=o;e[f]=o.peek()}}}i(n)});o("__r",function(i,n){u();var r,f=n.__c;if(f){f.__$f&=-2;if(void 0===(r=f.__$u))f.__$u=r=function(i){var n;t.effect(function(){n=this});n.c=function(){f.__$f|=1;f.setState({})};return n}()}e=f;u(r);i(n)});o("__e",function(i,n,r,t){u();e=void 0;i(n,r,t)});o("diffed",function(i,n){u();e=void 0;var r;if("string"==typeof n.type&&(r=n.__e)){var t=n.__np,f=n.props;if(t){var o=r.U;if(o)for(var a in o){var v=o[a];if(void 0!==v&&!(a in t)){v.d();o[a]=void 0}}else r.U=o={};for(var s in t){var l=o[s],d=t[s];if(void 0===l){l=c(r,s,d,f);o[s]=l}else l.o(d,f)}}}i(n)});function c(i,n,r,e){var f=n in i&&void 0===i.ownerSVGElement,o=t.signal(r);return{o:function(i,n){o.value=i;e=n},d:t.effect(function(){if(!v)v=this.N;this.N=b;var r=o.value.value;if(e[n]!==r){e[n]=r;if(f)i[n]=r;else if(r)i.setAttribute(n,r);else i.removeAttribute(n)}})}}o("unmount",function(i,n){if("string"==typeof n.type){var r=n.__e;if(r){var t=r.U;if(t){r.U=void 0;for(var e in t){var f=t[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)});o("__h",function(i,n,r,t){if(t<3||9===t)n.__$f|=2;i(n,r,t)});n.Component.prototype.shouldComponentUpdate=function(i,n){var r=this.__$u;if(!(r&&void 0!==r.s||4&this.__$f))return!0;if(3&this.__$f)return!0;for(var t in n)return!0;for(var e in i)if("__source"!==e&&i[e]!==this.props[e])return!0;for(var f in this.props)if(!(f in i))return!0;return!1};function useSignal(i){return r.useMemo(function(){return t.signal(i)},[])}var v,s=[],l=[],d="undefined"==typeof requestAnimationFrame?setTimeout:requestAnimationFrame,h=function(i){queueMicrotask(function(){queueMicrotask(i)})};function p(){t.batch(function(){var i;while(i=s.shift())v.call(i)})}function _(){if(1===s.push(this))(n.options.requestAnimationFrame||d)(p)}function g(){t.batch(function(){var i;while(i=l.shift())v.call(i)})}function b(){if(1===l.push(this))(n.options.requestAnimationFrame||h)(g)}i.Signal=t.Signal;i.batch=t.batch;i.computed=t.computed;i.effect=t.effect;i.signal=t.signal;i.untracked=t.untracked;i.useComputed=function(i){var n=r.useRef(i);n.current=i;e.__$f|=4;return r.useMemo(function(){return t.computed(function(){return n.current()})},[])};i.useSignal=useSignal;i.useSignalEffect=function(i){var n=r.useRef(i);n.current=i;r.useEffect(function(){return t.effect(function(){if(!v)v=this.N;this.N=_;return n.current()})},[])}});//# sourceMappingURL=signals.min.js.map

@@ -1,1 +0,1 @@

import{Component as n,options as r,isValidElement as i}from"preact";import{useMemo as t,useRef as f,useEffect as o}from"preact/hooks";import{Signal as e,computed as u,signal as a,effect as c}from"@preact/signals-core";export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";var v,s;function l(n,i){r[n]=i.bind(null,r[n]||function(){})}function d(n){if(s)s();s=n&&n.S()}function p(n){var r=this,f=n.data,o=useSignal(f);o.value=f;var e=t(function(){var n=r.__v;while(n=n.__)if(n.__c){n.__c.__$f|=4;break}r.__$u.c=function(){var n,t=r.__$u.S(),f=e.value;t();if(i(f)||3!==(null==(n=r.base)?void 0:n.nodeType)){r.__$f|=1;r.setState({})}else r.base.data=f};return u(function(){var n=o.value.value;return 0===n?0:!0===n?"":n||""})},[]);return e.value}p.displayName="_st";Object.defineProperties(e.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:p},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});l("__b",function(n,r){if("string"==typeof r.type){var i,t=r.props;for(var f in t)if("children"!==f){var o=t[f];if(o instanceof e){if(!i)r.__np=i={};i[f]=o;t[f]=o.peek()}}}n(r)});l("__r",function(n,r){d();var i,t=r.__c;if(t){t.__$f&=-2;if(void 0===(i=t.__$u))t.__$u=i=function(n){var r;c(function(){r=this});r.c=function(){t.__$f|=1;t.setState({})};return r}()}v=t;d(i);n(r)});l("__e",function(n,r,i,t){d();v=void 0;n(r,i,t)});l("diffed",function(n,r){d();v=void 0;var i;if("string"==typeof r.type&&(i=r.__e)){var t=r.__np,f=r.props;if(t){var o=i.U;if(o)for(var e in o){var u=o[e];if(void 0!==u&&!(e in t)){u.d();o[e]=void 0}}else i.U=o={};for(var a in t){var c=o[a],s=t[a];if(void 0===c){c=_(i,a,s,f);o[a]=c}else c.o(s,f)}}}n(r)});function _(n,r,i,t){var f=r in n&&void 0===n.ownerSVGElement,o=a(i);return{o:function(n,r){o.value=n;t=r},d:c(function(){var i=o.value.value;if(t[r]!==i){t[r]=i;if(f)n[r]=i;else if(i)n.setAttribute(r,i);else n.removeAttribute(r)}})}}l("unmount",function(n,r){if("string"==typeof r.type){var i=r.__e;if(i){var t=i.U;if(t){i.U=void 0;for(var f in t){var o=t[f];if(o)o.d()}}}}else{var e=r.__c;if(e){var u=e.__$u;if(u){e.__$u=void 0;u.d()}}}n(r)});l("__h",function(n,r,i,t){if(t<3||9===t)r.__$f|=2;n(r,i,t)});n.prototype.shouldComponentUpdate=function(n,r){var i=this.__$u;if(!(i&&void 0!==i.s||4&this.__$f))return!0;if(3&this.__$f)return!0;for(var t in r)return!0;for(var f in n)if("__source"!==f&&n[f]!==this.props[f])return!0;for(var o in this.props)if(!(o in n))return!0;return!1};function useSignal(n){return t(function(){return a(n)},[])}function useComputed(n){var r=f(n);r.current=n;v.__$f|=4;return t(function(){return u(function(){return r.current()})},[])}function useSignalEffect(n){var r=f(n);r.current=n;o(function(){return c(function(){return r.current()})},[])}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
import{Component as i,options as n,isValidElement as r}from"preact";import{useMemo as t,useRef as f,useEffect as o}from"preact/hooks";import{Signal as u,computed as e,effect as a,signal as c,batch as v}from"@preact/signals-core";export{Signal,batch,computed,effect,signal,untracked}from"@preact/signals-core";var s,l;function d(i,r){n[i]=r.bind(null,n[i]||function(){})}function h(i){if(l)l();l=i&&i.S()}function p(i){var n=this,f=i.data,o=useSignal(f);o.value=f;var u=t(function(){var i=n,t=n.__v;while(t=t.__)if(t.__c){t.__c.__$f|=4;break}var f=e(function(){var i=o.value.value;return 0===i?0:!0===i?"":i||""}),c=e(function(){var i;return r(f.value)||3!==(null==(i=n.base)?void 0:i.nodeType)});n.__$u.c=function(){var i;if(!r(u.peek())&&3===(null==(i=n.base)?void 0:i.nodeType))n.base.data=u.peek();else{n.__$f|=1;n.setState({})}};a(function(){if(!m)m=this.N;this.N=A;if(c.value&&i.base)i.base.data=f.value});return f},[]);return u.value}p.displayName="_st";Object.defineProperties(u.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:p},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});d("__b",function(i,n){if("string"==typeof n.type){var r,t=n.props;for(var f in t)if("children"!==f){var o=t[f];if(o instanceof u){if(!r)n.__np=r={};r[f]=o;t[f]=o.peek()}}}i(n)});d("__r",function(i,n){h();var r,t=n.__c;if(t){t.__$f&=-2;if(void 0===(r=t.__$u))t.__$u=r=function(i){var n;a(function(){n=this});n.c=function(){t.__$f|=1;t.setState({})};return n}()}s=t;h(r);i(n)});d("__e",function(i,n,r,t){h();s=void 0;i(n,r,t)});d("diffed",function(i,n){h();s=void 0;var r;if("string"==typeof n.type&&(r=n.__e)){var t=n.__np,f=n.props;if(t){var o=r.U;if(o)for(var u in o){var e=o[u];if(void 0!==e&&!(u in t)){e.d();o[u]=void 0}}else r.U=o={};for(var a in t){var c=o[a],v=t[a];if(void 0===c){c=_(r,a,v,f);o[a]=c}else c.o(v,f)}}}i(n)});function _(i,n,r,t){var f=n in i&&void 0===i.ownerSVGElement,o=c(r);return{o:function(i,n){o.value=i;t=n},d:a(function(){if(!m)m=this.N;this.N=A;var r=o.value.value;if(t[n]!==r){t[n]=r;if(f)i[n]=r;else if(r)i.setAttribute(n,r);else i.removeAttribute(n)}})}}d("unmount",function(i,n){if("string"==typeof n.type){var r=n.__e;if(r){var t=r.U;if(t){r.U=void 0;for(var f in t){var o=t[f];if(o)o.d()}}}}else{var u=n.__c;if(u){var e=u.__$u;if(e){u.__$u=void 0;e.d()}}}i(n)});d("__h",function(i,n,r,t){if(t<3||9===t)n.__$f|=2;i(n,r,t)});i.prototype.shouldComponentUpdate=function(i,n){var r=this.__$u;if(!(r&&void 0!==r.s||4&this.__$f))return!0;if(3&this.__$f)return!0;for(var t in n)return!0;for(var f in i)if("__source"!==f&&i[f]!==this.props[f])return!0;for(var o in this.props)if(!(o in i))return!0;return!1};function useSignal(i){return t(function(){return c(i)},[])}function useComputed(i){var n=f(i);n.current=i;s.__$f|=4;return t(function(){return e(function(){return n.current()})},[])}var m,g=[],b=[],k="undefined"==typeof requestAnimationFrame?setTimeout:requestAnimationFrame,y=function(i){queueMicrotask(function(){queueMicrotask(i)})};function q(){v(function(){var i;while(i=g.shift())m.call(i)})}function w(){if(1===g.push(this))(n.requestAnimationFrame||k)(q)}function x(){v(function(){var i;while(i=b.shift())m.call(i)})}function A(){if(1===b.push(this))(n.requestAnimationFrame||y)(x)}function useSignalEffect(i){var n=f(i);n.current=i;o(function(){return a(function(){if(!m)m=this.N;this.N=w;return n.current()})},[])}export{useComputed,useSignal,useSignalEffect};//# sourceMappingURL=signals.module.js.map
{
"name": "@preact/signals",
"version": "1.3.1",
"version": "2.0.0",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Manage state with style in Preact",

@@ -83,2 +83,3 @@ import { options, Component, isValidElement } from "preact";

const s = useMemo(() => {
let self = this;
// mark the parent component as having computeds so it gets optimized

@@ -93,20 +94,31 @@ let v = this.__v;

const wrappedSignal = computed(function (this: Effect) {
let data = currentSignal.value;
let s = data.value;
return s === 0 ? 0 : s === true ? "" : s || "";
});
const isText = computed(
() => isValidElement(wrappedSignal.value) || this.base?.nodeType !== 3
);
this._updater!._callback = () => {
const end = this._updater!._start();
const value = s.value;
end();
if (isValidElement(value) || this.base?.nodeType !== 3) {
if (isValidElement(s.peek()) || this.base?.nodeType !== 3) {
this._updateFlags |= HAS_PENDING_UPDATE;
this.setState({});
} else {
(this.base as Text).data = value;
return;
}
(this.base as Text).data = s.peek();
};
return computed(() => {
let data = currentSignal.value;
let s = data.value;
return s === 0 ? 0 : s === true ? "" : s || "";
effect(function (this: Effect) {
if (!oldNotify) oldNotify = this._notify;
this._notify = notifyDomUpdates;
const val = wrappedSignal.value;
if (isText.value && self.base) {
(self.base as Text).data = val;
}
});
return wrappedSignal;
}, []);

@@ -246,3 +258,5 @@

},
_dispose: effect(() => {
_dispose: effect(function (this: Effect) {
if (!oldNotify) oldNotify = this._notify;
this._notify = notifyDomUpdates;
const value = changeSignal.value.value;

@@ -367,2 +381,47 @@ // If Preact just rendered this value, don't render it again:

let oldNotify: (this: Effect) => void,
effectsQueue: Array<Effect> = [],
domQueue: Array<Effect> = [];
const deferEffects =
typeof requestAnimationFrame === "undefined"
? setTimeout
: requestAnimationFrame;
const deferDomUpdates = (cb: any) => {
queueMicrotask(() => {
queueMicrotask(cb);
});
};
function flushEffects() {
batch(() => {
let inst: Effect | undefined;
while ((inst = effectsQueue.shift())) {
oldNotify.call(inst);
}
});
}
function notifyEffects(this: Effect) {
if (effectsQueue.push(this) === 1) {
(options.requestAnimationFrame || deferEffects)(flushEffects);
}
}
function flushDomUpdates() {
batch(() => {
let inst: Effect | undefined;
while ((inst = domQueue.shift())) {
oldNotify.call(inst);
}
});
}
function notifyDomUpdates(this: Effect) {
if (domQueue.push(this) === 1) {
(options.requestAnimationFrame || deferDomUpdates)(flushDomUpdates);
}
}
export function useSignalEffect(cb: () => void | (() => void)) {

@@ -373,3 +432,7 @@ const callback = useRef(cb);

useEffect(() => {
return effect(() => callback.current());
return effect(function (this: Effect) {
if (!oldNotify) oldNotify = this._notify;
this._notify = notifyEffects;
return callback.current();
});
}, []);

@@ -376,0 +439,0 @@ }

@@ -7,2 +7,3 @@ import { Component } from "preact";

_start(): () => void;
_notify: () => void;
_callback(): void;

@@ -9,0 +10,0 @@ _dispose(): void;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc