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

3 lines
2.5 KiB
JavaScript

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