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

3 lines
3.9 KiB
JavaScript

function i(){throw new Error("Cycle detected")}var t=1,h=2,o=4,r=8,n=32;function s(){if(!(u>1)){var i,t=!1;while(void 0!==e){var o=e;e=void 0;d++;while(void 0!==o){var n=o.o;o.o=void 0;o.f&=~h;if(!(o.f&r)&&y(o))try{o.c()}catch(h){if(!t){i=h;t=!0}}o=n}}d=0;u--;if(t)throw i}else u--}function f(i){if(u>0)return i();u++;try{return i()}finally{s()}}var v=void 0,e=void 0,u=0,d=0,c=0;function a(i){if(void 0!==v){var t=i.n;if(void 0===t||t.t!==v){v.s=t={i:0,S:i,p:void 0,n:v.s,t:v,e:void 0,x:void 0,r:t};i.n=t;if(v.f&n)i.S(t);return t}else if(-1===t.i){t.i=0;if(void 0!==t.p){t.p.n=t.n;if(void 0!==t.n)t.n.p=t.p;t.p=void 0;t.n=v.s;v.s.p=t;v.s=t}return t}}}function l(i){this.v=i;this.i=0;this.n=void 0;this.t=void 0}l.prototype.h=function(){return!0};l.prototype.S=function(i){if(this.t!==i&&void 0===i.e){i.x=this.t;if(void 0!==this.t)this.t.e=i;this.t=i}};l.prototype.U=function(i){var t=i.e,h=i.x;if(void 0!==t){t.x=h;i.e=void 0}if(void 0!==h){h.e=t;i.x=void 0}if(i===this.t)this.t=h};l.prototype.subscribe=function(i){var t=this;return S(function(){var h=t.value,o=this.f&n;this.f&=~n;try{i(h)}finally{this.f|=o}})};l.prototype.valueOf=function(){return this.value};l.prototype.toString=function(){return this.value+""};l.prototype.peek=function(){return this.v};Object.defineProperty(l.prototype,"value",{get:function(){var i=a(this);if(void 0!==i)i.i=this.i;return this.v},set:function(t){if(t!==this.v){if(d>100)i();this.v=t;this.i++;c++;u++;try{for(var h=this.t;void 0!==h;h=h.x)h.t.N()}finally{s()}}}});function w(i){return new l(i)}function y(i){for(var t=i.s;void 0!==t;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function _(i){for(var t=i.s;void 0!==t;t=t.n){var h=t.S.n;if(void 0!==h)t.r=h;t.S.n=t;t.i=-1}}function g(i){var t=i.s,h=void 0;while(void 0!==t){var o=t.n;if(-1===t.i){t.S.U(t);t.n=void 0}else{if(void 0!==h)h.p=t;t.p=void 0;t.n=h;h=t}t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=o}i.s=h}function p(i){l.call(this,void 0);this.x=i;this.s=void 0;this.g=c-1;this.f=o}(p.prototype=new l).h=function(){this.f&=~h;if(this.f&t)return!1;if((this.f&(o|n))===n)return!0;this.f&=~o;if(this.g===c)return!0;this.g=c;this.f|=t;if(this.i>0&&!y(this)){this.f&=~t;return!0}var i=v;try{_(this);v=this;var r=this.x();if(16&this.f||this.v!==r||0===this.i){this.v=r;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}v=i;g(this);this.f&=~t;return!0};p.prototype.S=function(i){if(void 0===this.t){this.f|=o|n;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}l.prototype.S.call(this,i)};p.prototype.U=function(i){l.prototype.U.call(this,i);if(void 0===this.t){this.f&=~n;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}};p.prototype.N=function(){if(!(this.f&h)){this.f|=o|h;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};p.prototype.peek=function(){if(!this.h())i();if(16&this.f)throw this.v;return this.v};Object.defineProperty(p.prototype,"value",{get:function(){if(this.f&t)i();var h=a(this);this.h();if(void 0!==h)h.i=this.i;if(16&this.f)throw this.v;return this.v}});function b(i){return new p(i)}function x(i){var h=i.u;i.u=void 0;if("function"==typeof h){u++;var o=v;v=void 0;try{h()}catch(h){i.f&=~t;i.f|=r;O(i);throw h}finally{v=o;s()}}}function O(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;x(i)}function j(i){if(v!==this)throw new Error("Out-of-order effect");g(this);v=i;this.f&=~t;if(this.f&r)O(this);s()}function E(i){this.x=i;this.u=void 0;this.s=void 0;this.o=void 0;this.f=n}E.prototype.c=function(){var i=this.S();try{if(!(this.f&r)&&void 0!==this.x)this.u=this.x()}finally{i()}};E.prototype.S=function(){if(this.f&t)i();this.f|=t;this.f&=~r;x(this);_(this);u++;var h=v;v=this;return j.bind(this,h)};E.prototype.N=function(){if(!(this.f&h)){this.f|=h;this.o=e;e=this}};E.prototype.d=function(){this.f|=r;if(!(this.f&t))O(this)};function S(i){var t=new E(i);t.c();return t.d.bind(t)}export{l as Signal,f as batch,b as computed,S as effect,w as signal};
//# sourceMappingURL=signals-core.module.js.map