Notes/static/js/lib/signals/signals-core.min.js

3 lines
4.0 KiB
JavaScript
Raw Normal View History

2023-06-15 07:24:23 +02:00
!function(i,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((i||self).preactSignalsCore={})}(this,function(i){function t(){throw new Error("Cycle detected")}var o=1,n=2,h=4,s=8,r=32;function f(){if(!(u>1)){var i,t=!1;while(void 0!==v){var o=v;v=void 0;d++;while(void 0!==o){var h=o.o;o.o=void 0;o.f&=~n;if(!(o.f&s)&&y(o))try{o.c()}catch(o){if(!t){i=o;t=!0}}o=h}}d=0;u--;if(t)throw i}else u--}var e=void 0,v=void 0,u=0,d=0,c=0;function a(i){if(void 0!==e){var t=i.n;if(void 0===t||t.t!==e){e.s=t={i:0,S:i,p:void 0,n:e.s,t:e,e:void 0,x:void 0,r:t};i.n=t;if(e.f&r)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=e.s;e.s.p=t;e.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,o=i.x;if(void 0!==t){t.x=o;i.e=void 0}if(void 0!==o){o.e=t;i.x=void 0}if(i===this.t)this.t=o};l.prototype.subscribe=function(i){var t=this;return j(function(){var o=t.value,n=this.f&r;this.f&=~r;try{i(o)}finally{this.f|=n}})};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(i){if(i!==this.v){if(d>100)t();this.v=i;this.i++;c++;u++;try{for(var o=this.t;void 0!==o;o=o.x)o.t.N()}finally{f()}}}});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 w(i){for(var t=i.s;void 0!==t;t=t.n){var o=t.S.n;if(void 0!==o)t.r=o;t.S.n=t;t.i=-1}}function p(i){var t=i.s,o=void 0;while(void 0!==t){var n=t.n;if(-1===t.i){t.S.U(t);t.n=void 0}else{if(void 0!==o)o.p=t;t.p=void 0;t.n=o;o=t}t.S.n=t.r;if(void 0!==t.r)t.r=void 0;t=n}i.s=o}function _(i){l.call(this,void 0);this.x=i;this.s=void 0;this.g=c-1;this.f=h}(_.prototype=new l).h=function(){this.f&=~n;if(this.f&o)return!1;if((this.f&(h|r))===r)return!0;this.f&=~h;if(this.g===c)return!0;this.g=c;this.f|=o;if(this.i>0&&!y(this)){this.f&=~o;return!0}var i=e;try{w(this);e=this;var t=this.x();if(16&this.f||this.v!==t||0===this.i){this.v=t;this.f&=-17;this.i++}}catch(i){this.v=i;this.f|=16;this.i++}e=i;p(this);this.f&=~o;return!0};_.prototype.S=function(i){if(void 0===this.t){this.f|=h|r;for(var t=this.s;void 0!==t;t=t.n)t.S.S(t)}l.prototype.S.call(this,i)};_.prototype.U=function(i){l.prototype.U.call(this,i);if(void 0===this.t){this.f&=~r;for(var t=this.s;void 0!==t;t=t.n)t.S.U(t)}};_.prototype.N=function(){if(!(this.f&n)){this.f|=h|n;for(var i=this.t;void 0!==i;i=i.x)i.t.N()}};_.prototype.peek=function(){if(!this.h())t();if(16&this.f)throw this.v;return this.v};Object.defineProperty(_.prototype,"value",{get:function(){if(this.f&o)t();var i=a(this);this.h();if(void 0!==i)i.i=this.i;if(16&this.f)throw this.v;return this.v}});function g(i){var t=i.u;i.u=void 0;if("function"==typeof t){u++;var n=e;e=void 0;try{t()}catch(t){i.f&=~o;i.f|=s;b(i);throw t}finally{e=n;f()}}}function b(i){for(var t=i.s;void 0!==t;t=t.n)t.S.U(t);i.x=void 0;i.s=void 0;g(i)}function x(i){if(e!==this)throw new Error("Out-of-order effect");p(this);e=i;this.f&=~o;if(this.f&s)b(this);f()}function T(i){this.x=i;this.u=void 0;this.s=void 0;this.o=void 0;this.f=r}T.prototype.c=function(){var i=this.S();try{if(!(this.f&s)&&void 0!==this.x)this.u=this.x()}finally{i()}};T.prototype.S=function(){if(this.f&o)t();this.f|=o;this.f&=~s;g(this);w(this);u++;var i=e;e=this;return x.bind(this,i)};T.prototype.N=function(){if(!(this.f&n)){this.f|=n;this.o=v;v=this}};T.prototype.d=function(){this.f|=s;if(!(this.f&o))b(this)};function j(i){var t=new T(i);t.c();return t.d.bind(t)}i.Signal=l;i.batch=function(i){if(u>0)return i();u++;try{return i()}finally{f()}};i.computed=function(i){return new _(i)};i.effect=j;i.signal=function(i){return new l(i)}});
//# sourceMappingURL=signals-core.min.js.map