UNPKG

@compute.ts/core

Version:

Core package for libraries creation

1 lines 2.58 kB
"use strict";var __values=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return{value:(t=t&&n>=t.length?void 0:t)&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},__read=this&&this.__read||function(t,e){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var n,i,a=r.call(t),o=[];try{for(;(void 0===e||0<e--)&&!(n=a.next()).done;)o.push(n.value)}catch(t){i={error:t}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o},__spread=this&&this.__spread||function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(__read(arguments[e]));return t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ComputeApiNode=void 0;var rxjs_1=require("rxjs"),ComputeApiNode=function(){function t(t,e,r){var n,i;this.children=t=void 0===t?[]:t,this.evalFn=e,this.value=r,this.valueChanges$=new rxjs_1.Subject,this.notValid$=new rxjs_1.Subject,this.isDirty=!0,this.parents=[];try{for(var a=__values(t),o=a.next();!o.done;o=a.next())o.value.addParents(this)}catch(t){n={error:t}}finally{try{o&&!o.done&&(i=a.return)&&i.call(a)}finally{if(n)throw n.error}}this.currentValue=r}return t.prototype.affect=function(t){t!==this.currentValue&&(this.valueChanges$.next(t),this.currentValue=t,this.propagateDirty())},t.prototype.addParents=function(t){this.parents.push(t)},t.prototype.propagateDirty=function(){var t,e;if(!0!==this.isDirty){this.notValid$.next(),this.isDirty=!0;try{for(var r=__values(this.parents),n=r.next();!n.done;n=r.next())n.value.propagateDirty()}catch(e){t={error:e}}finally{try{n&&!n.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}}},t.prototype.eval=function(){var t;if(0===this.children.length)return this.isDirty=!1,this.currentValue;if(!1===this.isDirty)return this.currentValue;var e=[];try{for(var r=__values(this.children),n=r.next();!n.done;n=r.next()){var i=n.value;e.push(i.eval())}}catch(t){a={error:t}}finally{try{n&&!n.done&&(t=r.return)&&t.call(r)}finally{if(a)throw a.error}}var a=this.evalFn.apply(this,__spread(e));return a!==this.currentValue&&(this.valueChanges$.next(a),this.currentValue=a),this.isDirty=!1,this.currentValue},Object.defineProperty(t.prototype,"valueChanges",{get:function(){return this.valueChanges$},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"notValid",{get:function(){return this.notValid$},enumerable:!1,configurable:!0}),t}();exports.ComputeApiNode=ComputeApiNode;