UNPKG

g2o-reactive

Version:

Wrapper around signal-polyfill to support different module formats

55 lines (54 loc) 10.6 kB
System.register([],(function(e){"use strict";return{execute:function(){e({computed:function(e,r={}){return new A.Computed(e,r)},effect:function(e){let r;const o=new A.Computed((()=>{"function"==typeof r&&r(),r=e()}));return D.watch(o),o.get(),V((()=>{D.unwatch(o),"function"==typeof r&&r()}))},signal:function(e,r={}){return new A.State(e,r)},state:function(e,r={}){return new A.State(e,r)},untrack:function(e){return A.subtle.untrack(e)}});var r=Object.defineProperty,o=(e,o,t)=>(((e,o,t)=>{o in e?r(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t})(e,"symbol"!=typeof o?o+"":o,t),t),t=(e,r)=>{if(Object(r)!==r)throw TypeError('Cannot use the "in" operator on this value');return e.has(r)},n=(e,r,o)=>{if(r.has(e))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(e):r.set(e,o)},u=(e,r,o)=>(((e,r,o)=>{if(!r.has(e))throw TypeError("Cannot "+o)})(e,r,"access private method"),o) /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */;function i(e,r){return Object.is(e,r)} /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */let c=null,s=!1,d=1;const l=Symbol("SIGNAL");function a(e){const r=c;return c=e,r}const p={version:0,lastCleanEpoch:0,dirty:!1,producerNode:void 0,producerLastReadVersion:void 0,producerIndexOfThis:void 0,nextProducerIndex:0,liveConsumerNode:void 0,liveConsumerIndexOfThis:void 0,consumerAllowSignalWrites:!1,consumerIsAlwaysLive:!1,producerMustRecompute:()=>!1,producerRecomputeValue:()=>{},consumerMarkedDirty:()=>{},consumerOnSignalRead:()=>{}};function h(e){if(s)throw new Error(typeof ngDevMode<"u"&&ngDevMode?"Assertion error: signal read during notification phase":"");if(null===c)return;c.consumerOnSignalRead(e);const r=c.nextProducerIndex++;if(N(c),r<c.producerNode.length&&c.producerNode[r]!==e&&y(c)){g(c.producerNode[r],c.producerIndexOfThis[r])}c.producerNode[r]!==e&&(c.producerNode[r]=e,c.producerIndexOfThis[r]=y(c)?m(e,c,r):0),c.producerLastReadVersion[r]=e.version}function f(e){if((!y(e)||e.dirty)&&(e.dirty||e.lastCleanEpoch!==d)){if(!e.producerMustRecompute(e)&&!function(e){N(e);for(let r=0;r<e.producerNode.length;r++){const o=e.producerNode[r],t=e.producerLastReadVersion[r];if(t!==o.version||(f(o),t!==o.version))return!0}return!1}(e))return e.dirty=!1,void(e.lastCleanEpoch=d);e.producerRecomputeValue(e),e.dirty=!1,e.lastCleanEpoch=d}}function w(e){if(void 0===e.liveConsumerNode)return;const r=s;s=!0;try{for(const r of e.liveConsumerNode)r.dirty||v(r)}finally{s=r}}function v(e){var r;e.dirty=!0,w(e),null==(r=e.consumerMarkedDirty)||r.call(e.wrapper??e)}function m(e,r,o){var t;if(C(e),N(e),0===e.liveConsumerNode.length){null==(t=e.watched)||t.call(e.wrapper);for(let r=0;r<e.producerNode.length;r++)e.producerIndexOfThis[r]=m(e.producerNode[r],e,r)}return e.liveConsumerIndexOfThis.push(o),e.liveConsumerNode.push(r)-1}function g(e,r){var o;if(C(e),N(e),typeof ngDevMode<"u"&&ngDevMode&&r>=e.liveConsumerNode.length)throw new Error(`Assertion error: active consumer index ${r} is out of bounds of ${e.liveConsumerNode.length} consumers)`);if(1===e.liveConsumerNode.length){null==(o=e.unwatched)||o.call(e.wrapper);for(let r=0;r<e.producerNode.length;r++)g(e.producerNode[r],e.producerIndexOfThis[r])}const t=e.liveConsumerNode.length-1;if(e.liveConsumerNode[r]=e.liveConsumerNode[t],e.liveConsumerIndexOfThis[r]=e.liveConsumerIndexOfThis[t],e.liveConsumerNode.length--,e.liveConsumerIndexOfThis.length--,r<e.liveConsumerNode.length){const o=e.liveConsumerIndexOfThis[r],t=e.liveConsumerNode[r];N(t),t.producerIndexOfThis[o]=r}}function y(e){var r;return e.consumerIsAlwaysLive||((null==(r=null==e?void 0:e.liveConsumerNode)?void 0:r.length)??0)>0}function N(e){e.producerNode??(e.producerNode=[]),e.producerIndexOfThis??(e.producerIndexOfThis=[]),e.producerLastReadVersion??(e.producerLastReadVersion=[])}function C(e){e.liveConsumerNode??(e.liveConsumerNode=[]),e.liveConsumerIndexOfThis??(e.liveConsumerIndexOfThis=[]) /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */}function T(e){if(f(e),h(e),e.value===I)throw e.error;return e.value}const S=Symbol("UNSET"),x=Symbol("COMPUTING"),I=Symbol("ERRORED"),O={...p,value:S,dirty:!0,error:null,equal:i,producerMustRecompute:e=>e.value===S||e.value===x,producerRecomputeValue(e){if(e.value===x)throw new Error("Detected cycle in computations.");const r=e.value;e.value=x;const o=function(e){return e&&(e.nextProducerIndex=0),a(e)}(e);let t,n=!1;try{t=e.computation.call(e.wrapper),n=r!==S&&r!==I&&e.equal.call(e.wrapper,r,t)}catch(r){t=I,e.error=r}finally{!function(e,r){if(a(r),e&&void 0!==e.producerNode&&void 0!==e.producerIndexOfThis&&void 0!==e.producerLastReadVersion){if(y(e))for(let r=e.nextProducerIndex;r<e.producerNode.length;r++)g(e.producerNode[r],e.producerIndexOfThis[r]);for(;e.producerNode.length>e.nextProducerIndex;)e.producerNode.pop(),e.producerLastReadVersion.pop(),e.producerIndexOfThis.pop()}}(e,o)}n?e.value=r:(e.value=t,e.version++)}}; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */let b=function(){throw new Error};function E(){return h(this),this.value}function W(e,r){!1!==(null==c?void 0:c.consumerAllowSignalWrites)||b(),e.equal.call(e.wrapper,e.value,r)||(e.value=r,function(e){e.version++,d++,w(e) /** * @license * Copyright 2024 Bloomberg Finance L.P. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */}(e))}const R={...p,equal:i,value:void 0};const k=Symbol("node");let M,L,P;var A;function V(e){return{dispose:()=>{e()}}}(e=>{var r,i,d,f;r=k,i=new WeakSet,M=e=>t(i,e),e.State=class{constructor(t,u={}){n(this,i),o(this,r);const c= /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ function(e){const r=Object.create(R);r.value=e;const o=()=>(h(r),r.value);return o[l]=r,o}(t)[l];if(this[k]=c,c.wrapper=this,u){const r=u.equals;r&&(c.equal=r),c.watched=u[e.subtle.watched],c.unwatched=u[e.subtle.unwatched]}}get(){if(!M(this))throw new TypeError("Wrong receiver type for Signal.State.prototype.get");return E.call(this[k])}set(e){if(!M(this))throw new TypeError("Wrong receiver type for Signal.State.prototype.set");if(s)throw new Error("Writes to signals not permitted during Watcher callback");W(this[k],e)}};d=k,f=new WeakSet,L=e=>t(f,e),e.Computed=class{constructor(r,t){n(this,f),o(this,d);const u=function(e){const r=Object.create(O);r.computation=e;const o=()=>T(r);return o[l]=r,o}(r)[l];if(u.consumerAllowSignalWrites=!0,this[k]=u,u.wrapper=this,t){const r=t.equals;r&&(u.equal=r),u.watched=t[e.subtle.watched],u.unwatched=t[e.subtle.unwatched]}}get(){if(!L(this))throw new TypeError("Wrong receiver type for Signal.Computed.prototype.get");return T(this[k])}},(e=>{var r,i,s,d;e.untrack=function(e){let r,o=null;try{o=a(null),r=e()}finally{a(o)}return r},e.introspectSources=function(e){var r;if(!L(e)&&!P(e))throw new TypeError("Called introspectSources without a Computed or Watcher argument");return(null==(r=e[k].producerNode)?void 0:r.map((e=>e.wrapper)))??[]},e.introspectSinks=function(e){var r;if(!L(e)&&!M(e))throw new TypeError("Called introspectSinks without a Signal argument");return(null==(r=e[k].liveConsumerNode)?void 0:r.map((e=>e.wrapper)))??[]},e.hasSinks=function(e){if(!L(e)&&!M(e))throw new TypeError("Called hasSinks without a Signal argument");const r=e[k].liveConsumerNode;return!!r&&r.length>0},e.hasSources=function(e){if(!L(e)&&!P(e))throw new TypeError("Called hasSources without a Computed or Watcher argument");const r=e[k].producerNode;return!!r&&r.length>0};r=k,i=new WeakSet,s=new WeakSet,d=function(e){for(const r of e)if(!L(r)&&!M(r))throw new TypeError("Called watch/unwatch without a Computed or State argument")},P=e=>t(i,e),e.Watcher=class{constructor(e){n(this,i),n(this,s),o(this,r);let t=Object.create(p);t.wrapper=this,t.consumerMarkedDirty=e,t.consumerIsAlwaysLive=!0,t.consumerAllowSignalWrites=!1,t.producerNode=[],this[k]=t}watch(...e){if(!P(this))throw new TypeError("Called unwatch without Watcher receiver");u(this,s,d).call(this,e);const r=this[k];r.dirty=!1;const o=a(r);for(const r of e)h(r[k]);a(o)}unwatch(...e){if(!P(this))throw new TypeError("Called unwatch without Watcher receiver");u(this,s,d).call(this,e);const r=this[k];N(r);let o=[];for(let t=0;t<r.producerNode.length;t++)e.includes(r.producerNode[t].wrapper)&&(g(r.producerNode[t],r.producerIndexOfThis[t]),o.push(t));for(const e of o){const o=r.producerNode.length-1;if(r.producerNode[e]=r.producerNode[o],r.producerIndexOfThis[e]=r.producerIndexOfThis[o],r.producerNode.length--,r.producerIndexOfThis.length--,r.nextProducerIndex--,e<r.producerNode.length){const o=r.producerIndexOfThis[e],t=r.producerNode[e];C(t),t.liveConsumerIndexOfThis[o]=e}}}getPending(){if(!P(this))throw new TypeError("Called getPending without Watcher receiver");return this[k].producerNode.filter((e=>e.dirty)).map((e=>e.wrapper))}},e.currentComputed=function(){var e;return null==(e=c)?void 0:e.wrapper},e.watched=Symbol("watched"),e.unwatched=Symbol("unwatched")})(e.subtle||(e.subtle={}))})(A||(A={}));let q=!0;const D=new A.subtle.Watcher((()=>{q&&(q=!1,queueMicrotask(j))}));function j(){q=!0;for(const e of D.getPending())e.get();D.watch()}}}})); //# sourceMappingURL=index.min.js.map