Notes/static/js/lib/signals/signals.js
2023-06-15 07:24:23 +02:00

3 lines
3.0 KiB
JavaScript

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