Comparing version 1.2.6 to 1.2.67
@@ -59,3 +59,3 @@ var __extends = (this && this.__extends) || (function () { | ||
} | ||
var newSequence = this._buildNewSequence(this._innerSequence | ||
var newSequence = this._buildNewSequence(this.innerSequence | ||
.filter(function (event) { return !event.isOperationError(); }) | ||
@@ -65,9 +65,9 @@ .map(function (event) { return event.value; }), __spreadArray(__spreadArray([], operations), this._preProcessOperations)).filter(function (event) { return !event.isMustStop(); }); | ||
if (idxError > -1) { | ||
this._innerSequence = newSequence.slice(0, idxError); | ||
this.next.apply(this, this._innerSequence.map(function (event) { return event.value; })); | ||
this._innerSequence.push(newSequence[idxError]); | ||
this.innerSequence = newSequence.slice(0, idxError); | ||
this.next.apply(this, this.innerSequence.map(function (event) { return event.value; })); | ||
this.innerSequence.push(newSequence[idxError]); | ||
this._triggerExecution([newSequence[idxError]], this._subscribers); | ||
return this; | ||
} | ||
this._triggerExecution(this._innerSequence = newSequence, this._subscribers); | ||
this._triggerExecution(this.innerSequence = newSequence, this._subscribers); | ||
return this; | ||
@@ -83,4 +83,4 @@ }; | ||
} | ||
this._innerSequence = this._buildNewSequence(events, this._preProcessOperations); | ||
this._triggerExecution(this._innerSequence, this._subscribers); | ||
this.innerSequence = this._buildNewSequence(events, this._preProcessOperations); | ||
this._triggerExecution(this.innerSequence, this._subscribers); | ||
return this; | ||
@@ -87,0 +87,0 @@ }; |
@@ -9,2 +9,5 @@ import { Observable } from "./observable"; | ||
private operators; | ||
private _isClosed; | ||
protected get innerSequence(): OperationResult<T>[]; | ||
protected set innerSequence(sequence: OperationResult<T>[]); | ||
constructor(sourceObs$: Types.Observable<T>, ...operators: OperatorFunction<T, OperationResult<any>>[]); | ||
@@ -11,0 +14,0 @@ subscribe(subscriber: Subscriber<T> | OnNext<T>): Subscription; |
@@ -31,6 +31,7 @@ var __extends = (this && this.__extends) || (function () { | ||
_this.operators = []; | ||
_this._isClosed = false; | ||
_this.operators = operators; | ||
_this._isComplete = sourceObs$._isComplete; | ||
_this.sourceObs$._forks.push(_this); | ||
_this.sourceObs$.subscribe({ | ||
name: 'subscriber fork constructor', | ||
next: function (value) { | ||
@@ -65,2 +66,12 @@ _this._subscribers | ||
} | ||
Object.defineProperty(ObservableFork.prototype, "innerSequence", { | ||
get: function () { | ||
return this.sourceObs$.innerSequence; | ||
}, | ||
set: function (sequence) { | ||
this._innerSequence = sequence; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
ObservableFork.prototype.subscribe = function (subscriber) { | ||
@@ -76,3 +87,3 @@ var _this = this; | ||
var newSequence = []; | ||
var sourceSequence = this.sourceObs$._innerSequence; // FIXME ew | ||
var sourceSequence = this.sourceObs$.innerSequence; // FIXME ew | ||
for (var i = 0, l = sourceSequence.length; i < l; i++) { | ||
@@ -90,3 +101,8 @@ try { | ||
} | ||
this.executeSubscriber(_subscriber, newSequence); | ||
if (this._isClosed) { | ||
(_subscriber.complete && _subscriber.complete()); | ||
} | ||
else { | ||
this.executeSubscriber(_subscriber, newSequence); | ||
} | ||
return new Subscription(function () { | ||
@@ -97,2 +113,4 @@ return (_this._subscribers = _this._subscribers.filter(function (s) { return s !== subscriber; })); | ||
ObservableFork.prototype.close = function () { | ||
this._isClosed = true; | ||
this._forks.forEach(function (fork) { return fork.close(); }); | ||
this._subscribers.forEach(function (s) { return s.complete && s.complete(); }); | ||
@@ -99,0 +117,0 @@ this.unsubscribe(); |
import { OperationResult, OperatorFunction } from "../models/operator"; | ||
import { OnNext, Subscriber, Subscription } from "../models/subscription"; | ||
import { Types } from '../models/types'; | ||
import { ObservableFork, Types } from '../models/types'; | ||
export declare class Observable<T = never> implements Types.Observable<T> { | ||
@@ -9,2 +9,5 @@ protected _innerSequence: OperationResult<T>[]; | ||
protected _error: Error; | ||
protected _forks: ObservableFork<any>[]; | ||
protected get innerSequence(): OperationResult<T>[]; | ||
protected set innerSequence(sequence: OperationResult<T>[]); | ||
constructor(...initialSequence: T[]); | ||
@@ -11,0 +14,0 @@ pipe<U = any>(...operations: OperatorFunction<T, OperationResult<U>>[]): Observable<U>; |
@@ -17,4 +17,15 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
this._isComplete = true; | ||
this._innerSequence = initialSequence.map(function (value) { return new OperationResult(value); }); | ||
this._forks = []; | ||
this.innerSequence = initialSequence.map(function (value) { return new OperationResult(value); }); | ||
} | ||
Object.defineProperty(Observable.prototype, "innerSequence", { | ||
get: function () { | ||
return this._innerSequence; | ||
}, | ||
set: function (sequence) { | ||
this._innerSequence = sequence; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Observable.prototype.pipe = function () { | ||
@@ -27,3 +38,3 @@ var operations = []; | ||
var newSequence = []; | ||
var sourceSequence = this._innerSequence; | ||
var sourceSequence = this.innerSequence; | ||
for (var i = 0, l = sourceSequence.length; i < l && !sourceSequence[i].isMustStop(); i++) { | ||
@@ -41,3 +52,3 @@ try { | ||
} | ||
obs$._innerSequence = newSequence; | ||
obs$.innerSequence = newSequence; | ||
return obs$; | ||
@@ -54,3 +65,3 @@ }; | ||
this._subscribers.push(_subscriber); | ||
this.executeSubscriber(_subscriber, this._innerSequence); | ||
this.executeSubscriber(_subscriber, this.innerSequence); | ||
return new Subscription(function () { | ||
@@ -99,3 +110,3 @@ return (_this._subscribers = _this._subscribers.filter(function (s) { return s !== subscriber; })); | ||
case OperationResultFlag.UnwrapSwitch: | ||
res = new OperationResult((_a = res.value._innerSequence.pop()) === null || _a === void 0 ? void 0 : _a.value); | ||
res = new OperationResult((_a = res.value.innerSequence[res.value.innerSequence.length - 1]) === null || _a === void 0 ? void 0 : _a.value); | ||
break; | ||
@@ -102,0 +113,0 @@ default: |
@@ -32,6 +32,6 @@ var __extends = (this && this.__extends) || (function () { | ||
.then(function (res) { | ||
_this._innerSequence.push(new OperationResult(res)); | ||
_this.innerSequence.push(new OperationResult(res)); | ||
}) | ||
.catch(function (err) { | ||
_this._innerSequence.push(new OperationResult(void 0, OperationResultFlag.OperationError, err)); | ||
_this.innerSequence.push(new OperationResult(void 0, OperationResultFlag.OperationError, err)); | ||
}); | ||
@@ -56,3 +56,3 @@ return _this; | ||
this._subscribers.push(_subscriber); | ||
var handler = function () { return _this.executeSubscriber(_subscriber, _this._innerSequence); }; | ||
var handler = function () { return _this.executeSubscriber(_subscriber, _this.innerSequence); }; | ||
this.promise.then(handler); | ||
@@ -59,0 +59,0 @@ return new Subscription(function () { |
@@ -32,4 +32,4 @@ var __extends = (this && this.__extends) || (function () { | ||
} | ||
_this._innerSequence = [operationResult]; | ||
_this._subscribers.forEach(function (s) { return _this.executeSubscriber(s, _this._innerSequence); }); | ||
_this.innerSequence = [operationResult]; | ||
_this._subscribers.forEach(function (s) { return _this.executeSubscriber(s, _this.innerSequence); }); | ||
if (operationResult.isOperationError()) { | ||
@@ -52,3 +52,3 @@ throw operationResult.error; | ||
}; | ||
instance._innerSequence = []; | ||
instance.innerSequence = []; | ||
res.subscribe = instance.subscribe.bind(instance); | ||
@@ -55,0 +55,0 @@ res.pipe = instance.pipe.bind(instance); |
@@ -1,1 +0,1 @@ | ||
var t={d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r)},r={};t.d(r,{gC:()=>i,hX:()=>o,rM:()=>N,Dp:()=>O,iT:()=>T,dJ:()=>H,KJ:()=>u,UI:()=>a,Nl:()=>x,hL:()=>K,of:()=>E,IH:()=>c,d_:()=>P,wt:()=>p,qn:()=>V,bw:()=>f,C4:()=>s});var e,n=function(){function t(t,r,e){this._value=t,this._flag=r,this._error=e}return Object.defineProperty(t.prototype,"value",{get:function(){return this._value},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"flag",{get:function(){return this._flag},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this._error},enumerable:!1,configurable:!0}),t.prototype.isUnwrapSwitch=function(){return this._flag===e.UnwrapSwitch},t.prototype.isMustStop=function(){return this._flag===e.MustStop},t.prototype.isFilterNotMatched=function(){return this._flag===e.FilterNotMatched},t.prototype.isOperationError=function(){return this._flag===e.OperationError},t}();!function(t){t.UnwrapSwitch="UnwrapSwitch",t.MustStop="MustStop",t.FilterNotMatched="FilterNotMatched",t.OperationError="OperationError"}(e||(e={}));var o=function(t){return function(r){return new n(r,t(r)?void 0:e.FilterNotMatched)}},i=function(t){var r=!1;return function(i){return new n(i,(r=r||o(t)(i).isFilterNotMatched())?e.MustStop:void 0)}},u=function(t,r,e){return function(n){var i=o(t)(n),u=i.isFilterNotMatched()?null!=e?e:[]:r,c=u.shift();return c?u.reduce((function(t,r){return r(t.value)}),c(n)):i}},c=function(t){var r=!1;return function(o){return r?new n(o,e.MustStop):!t||t(o)?(r=!0,new n(o)):new n(o,e.FilterNotMatched)}},s=function(t){var r=!1;return function(i){return new n(i,(r=r||!o(t)(i).isFilterNotMatched())?e.MustStop:void 0)}},a=function(t){return function(r){return new n(t(r))}};function p(t){return function(r){return new n(t(r),e.UnwrapSwitch)}}var f=function(t){return function(r){return t(r),new n(r)}};function l(t){return"function"==typeof t}function h(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return t.filter((function(t){return l(t)}))}var b=function(){function t(t){this._unsubscribeCallback=t}return t.prototype.unsubscribe=function(){this._unsubscribeCallback&&this._unsubscribeCallback()},t}();function y(t){return!l(t)&&function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return r.some((function(r){return void 0!==t[r]&&null!==t[r]&&l(t[r])}))}(t,"next","error","complete")}function v(t,r,e){var n={next:t,error:r,complete:e};if(!y(n))throw new Error("Please provide functions for next, error and complete");return n}new b;var _,w=function(){function t(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];this._subscribers=[],this._isComplete=!0,this._innerSequence=t.map((function(t){return new n(t)}))}return t.prototype.pipe=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];for(var i=new t,u=[],c=this._innerSequence,s=0,a=c.length;s<a&&!c[s].isMustStop();s++)try{var p=this._executeOperations(c[s].value,r);p.isFilterNotMatched()||u.push(p)}catch(t){u.push(new n(c[s].value,e.OperationError,t)),s=a}return i._innerSequence=u,i},t.prototype.subscribe=function(t){var r=this;if(!l(t)&&!y(t))throw new Error("Please provide either a function or a Subscriber");var e=y(t)?t:v(t);return this._subscribers.push(e),this.executeSubscriber(e,this._innerSequence),new b((function(){return r._subscribers=r._subscribers.filter((function(r){return r!==t}))}))},t.prototype.executeSubscriber=function(t,r){for(var e=function(e,o){var i=r[e];return i.isOperationError()?(n._error=i.error,(t.error||function(){throw i.error})(i.error),"break"):i.isFilterNotMatched()?"continue":i.isMustStop()?"break":void(t.next&&t.next(i.value))},n=this,o=0,i=r.length;o<i&&"break"!==e(o);o++);this._isComplete&&t.complete&&t.complete()},t.prototype._computeValue=function(t){for(var r,o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];for(var u=new n(t),c=0;c<o.length;c++)switch((u=o[c](u.value)).flag){case e.FilterNotMatched:case e.MustStop:c=o.length;break;case e.UnwrapSwitch:u=new n(null===(r=u.value._innerSequence.pop())||void 0===r?void 0:r.value)}return u},t.prototype._executeOperations=function(t,r){return this._computeValue.apply(this,function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t}([t],h.apply(void 0,r)))},t}(),O=function(t){return new(w.bind.apply(w,function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t}([void 0],t)))},g=(_=function(t,r){return(_=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}_(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),d=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},S=function(t){function r(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var n=t.apply(this,r)||this;return n._preProcessOperations=[],n._isComplete=!1,n}return g(r,t),r.prototype.close=function(){return this._isComplete||(this._isComplete=!0,this._subscribers.filter((function(t){return t.complete})).forEach((function(t){t.complete()}))),this},r.prototype.compile=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(this._isComplete)return this;var e=this._buildNewSequence(this._innerSequence.filter((function(t){return!t.isOperationError()})).map((function(t){return t.value})),d(d([],t),this._preProcessOperations)).filter((function(t){return!t.isMustStop()})),n=e.findIndex((function(t){return t.isOperationError()}));return n>-1?(this._innerSequence=e.slice(0,n),this.next.apply(this,this._innerSequence.map((function(t){return t.value}))),this._innerSequence.push(e[n]),this._triggerExecution([e[n]],this._subscribers),this):(this._triggerExecution(this._innerSequence=e,this._subscribers),this)},r.prototype.next=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return this._isComplete||(this._innerSequence=this._buildNewSequence(t,this._preProcessOperations),this._triggerExecution(this._innerSequence,this._subscribers)),this},r.prototype._buildNewSequence=function(t,r){for(var o=[],i=0,u=t.length;i<u;i++)try{var c=this._executeOperations(t[i],r);if(c.isMustStop()){o.push(c);break}c.isFilterNotMatched()||o.push(c)}catch(r){this._error=r,o.push(new n(t[i],e.OperationError,r)),i=u}return o},r.prototype._triggerExecution=function(t,r){var e=this;r.forEach((function(r){return e.executeSubscriber(r,t)}))},r}(w),m=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},x=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new(S.bind.apply(S,m([void 0],t)))},j=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},E=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new(w.bind.apply(w,j([void 0],t)))};function P(){for(var t,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var n=new S;return(t=n._preProcessOperations).push.apply(t,r),n}var M=function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),q=function(t){function r(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=t.call(this)||this;return o.sourceObs$=r,o.subscriptions=[],o.operators=[],o.operators=e,o._isComplete=r._isComplete,o.sourceObs$.subscribe({name:"subscriber fork constructor",next:function(t){o._subscribers.filter((function(t){return t.next})).forEach((function(r){var n=o._executeOperations(t,e);if(!n.isFilterNotMatched()&&!n.isMustStop())return r.next(n.value);n.isMustStop()&&o.close()}))},error:function(t){o._error=t,o._subscribers.filter((function(t){return t.error})).forEach((function(r){return r.error(t)}))},complete:function(){o._isComplete=!0,o.unsubscribe(),o._subscribers.filter((function(t){return t.complete})).forEach((function(t){return t.complete()}))}}),o}return M(r,t),r.prototype.subscribe=function(t){var r=this;if(!l(t)&&!y(t))throw new Error("Please provide either a function or a Subscriber");var o=y(t)?t:v(t);this._subscribers.push(o);for(var i=[],u=this.sourceObs$._innerSequence,c=0,s=u.length;c<s;c++)try{if(u[c].isOperationError())throw u[c].error;i.push(this._executeOperations(u[c].value,this.operators))}catch(t){i.push(new n(u[c].value,e.OperationError,t)),c=s}return this.executeSubscriber(o,i),new b((function(){return r._subscribers=r._subscribers.filter((function(r){return r!==t}))}))},r.prototype.close=function(){this._subscribers.forEach((function(t){return t.complete&&t.complete()})),this.unsubscribe()},r.prototype.unsubscribe=function(){this.subscriptions.forEach((function(t){return t.unsubscribe()}))},r}(w),C=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},N=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];var n=new(q.bind.apply(q,C([void 0,t],r)));return n},F=function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),k=function(t){function r(r){var o=t.call(this)||this;return o.proxy=Object.assign(new Proxy(r,{apply:function(t,r,i){var u,c;try{c=new n(u=t.apply(r,i))}catch(t){c=new n(u,e.OperationError,t)}if(o._innerSequence=[c],o._subscribers.forEach((function(t){return o.executeSubscriber(t,o._innerSequence)})),c.isOperationError())throw c.error;return u}})),o}return F(r,t),r.create=function(t){var e=new r(t),n=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.proxy.apply(e,t)};return e._innerSequence=[],n.subscribe=e.subscribe.bind(e),n.pipe=e.pipe.bind(e),n.asObservable=function(){return e},n},r}(w),T=function(t){return k.create(t)},I=function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),U=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},A=function(t){function r(r){var o=t.call(this)||this;return o.promise=r.then((function(t){o._innerSequence.push(new n(t))})).catch((function(t){o._innerSequence.push(new n(void 0,e.OperationError,t))})),o}return I(r,t),r.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return N.apply(void 0,U([this],t))},r.prototype.subscribe=function(t){var r=this;if(!l(t)&&!y(t))throw new Error("Please provide either a function or a Subscriber");var e=y(t)?t:v(t);return this._subscribers.push(e),this.promise.then((function(){return r.executeSubscriber(e,r._innerSequence)})),new b((function(){return r._subscribers=r._subscribers.filter((function(r){return r!==t}))}))},r}(w),J=function(){return(J=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},L=function(){return(L=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},D=function(){return(D=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},$=function(){return($=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},H={get:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,J(J({},n),{method:"GET"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))},post:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,L(L({},n),{method:"POST"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))},put:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,D(D({},n),{method:"PUT"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))},delete:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,$($({},n),{method:"DELETE"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))}},K=function(t){var r=0;return function(o){return++r===t?new n(o):new n(o,r<t?e.FilterNotMatched:e.MustStop)}},V=function(t){var r=0;return function(o){return++r>t?new n(o,e.MustStop):new n(o)}},X=r.gC,G=r.hX,z=r.rM,B=r.Dp,Q=r.iT,R=r.dJ,W=r.KJ,Y=r.UI,Z=r.Nl,tt=r.hL,rt=r.of,et=r.IH,nt=r.d_,ot=r.wt,it=r.qn,ut=r.bw,ct=r.C4;export{X as asLongAs,G as filter,z as fork,B as from,Q as fromFunction,R as http,W as ifElse,Y as map,Z as mutable,tt as nth,rt as of,et as once,nt as preProcess,ot as switchMap,it as take,ut as tap,ct as until}; | ||
var t={d:(r,e)=>{for(var n in e)t.o(e,n)&&!t.o(r,n)&&Object.defineProperty(r,n,{enumerable:!0,get:e[n]})},o:(t,r)=>Object.prototype.hasOwnProperty.call(t,r)},r={};t.d(r,{gC:()=>i,hX:()=>o,rM:()=>N,Dp:()=>_,iT:()=>T,dJ:()=>H,KJ:()=>u,UI:()=>p,Nl:()=>x,hL:()=>K,of:()=>E,IH:()=>c,d_:()=>P,wt:()=>f,qn:()=>V,bw:()=>a,C4:()=>s});var e,n=function(){function t(t,r,e){this._value=t,this._flag=r,this._error=e}return Object.defineProperty(t.prototype,"value",{get:function(){return this._value},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"flag",{get:function(){return this._flag},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this._error},enumerable:!1,configurable:!0}),t.prototype.isUnwrapSwitch=function(){return this._flag===e.UnwrapSwitch},t.prototype.isMustStop=function(){return this._flag===e.MustStop},t.prototype.isFilterNotMatched=function(){return this._flag===e.FilterNotMatched},t.prototype.isOperationError=function(){return this._flag===e.OperationError},t}();!function(t){t.UnwrapSwitch="UnwrapSwitch",t.MustStop="MustStop",t.FilterNotMatched="FilterNotMatched",t.OperationError="OperationError"}(e||(e={}));var o=function(t){return function(r){return new n(r,t(r)?void 0:e.FilterNotMatched)}},i=function(t){var r=!1;return function(i){return new n(i,(r=r||o(t)(i).isFilterNotMatched())?e.MustStop:void 0)}},u=function(t,r,e){return function(n){var i=o(t)(n),u=i.isFilterNotMatched()?null!=e?e:[]:r,c=u.shift();return c?u.reduce((function(t,r){return r(t.value)}),c(n)):i}},c=function(t){var r=!1;return function(o){return r?new n(o,e.MustStop):!t||t(o)?(r=!0,new n(o)):new n(o,e.FilterNotMatched)}},s=function(t){var r=!1;return function(i){return new n(i,(r=r||!o(t)(i).isFilterNotMatched())?e.MustStop:void 0)}},p=function(t){return function(r){return new n(t(r))}};function f(t){return function(r){return new n(t(r),e.UnwrapSwitch)}}var a=function(t){return function(r){return t(r),new n(r)}};function l(t){return"function"==typeof t}function h(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return t.filter((function(t){return l(t)}))}var b=function(){function t(t){this._unsubscribeCallback=t}return t.prototype.unsubscribe=function(){this._unsubscribeCallback&&this._unsubscribeCallback()},t}();function y(t){return!l(t)&&function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];return r.some((function(r){return void 0!==t[r]&&null!==t[r]&&l(t[r])}))}(t,"next","error","complete")}function v(t,r,e){var n={next:t,error:r,complete:e};if(!y(n))throw new Error("Please provide functions for next, error and complete");return n}new b;var w,O=function(){function t(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];this._subscribers=[],this._isComplete=!0,this._forks=[],this.innerSequence=t.map((function(t){return new n(t)}))}return Object.defineProperty(t.prototype,"innerSequence",{get:function(){return this._innerSequence},set:function(t){this._innerSequence=t},enumerable:!1,configurable:!0}),t.prototype.pipe=function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];for(var i=new t,u=[],c=this.innerSequence,s=0,p=c.length;s<p&&!c[s].isMustStop();s++)try{var f=this._executeOperations(c[s].value,r);f.isFilterNotMatched()||u.push(f)}catch(t){u.push(new n(c[s].value,e.OperationError,t)),s=p}return i.innerSequence=u,i},t.prototype.subscribe=function(t){var r=this;if(!l(t)&&!y(t))throw new Error("Please provide either a function or a Subscriber");var e=y(t)?t:v(t);return this._subscribers.push(e),this.executeSubscriber(e,this.innerSequence),new b((function(){return r._subscribers=r._subscribers.filter((function(r){return r!==t}))}))},t.prototype.executeSubscriber=function(t,r){for(var e=function(e,o){var i=r[e];return i.isOperationError()?(n._error=i.error,(t.error||function(){throw i.error})(i.error),"break"):i.isFilterNotMatched()?"continue":i.isMustStop()?"break":void(t.next&&t.next(i.value))},n=this,o=0,i=r.length;o<i&&"break"!==e(o);o++);this._isComplete&&t.complete&&t.complete()},t.prototype._computeValue=function(t){for(var r,o=[],i=1;i<arguments.length;i++)o[i-1]=arguments[i];for(var u=new n(t),c=0;c<o.length;c++)switch((u=o[c](u.value)).flag){case e.FilterNotMatched:case e.MustStop:c=o.length;break;case e.UnwrapSwitch:u=new n(null===(r=u.value.innerSequence[u.value.innerSequence.length-1])||void 0===r?void 0:r.value)}return u},t.prototype._executeOperations=function(t,r){return this._computeValue.apply(this,function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t}([t],h.apply(void 0,r)))},t}(),_=function(t){return new(O.bind.apply(O,function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t}([void 0],t)))},g=(w=function(t,r){return(w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(t,r)},function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function e(){this.constructor=t}w(t,r),t.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}),d=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},S=function(t){function r(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var n=t.apply(this,r)||this;return n._preProcessOperations=[],n._isComplete=!1,n}return g(r,t),r.prototype.close=function(){return this._isComplete||(this._isComplete=!0,this._subscribers.filter((function(t){return t.complete})).forEach((function(t){t.complete()}))),this},r.prototype.compile=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];if(this._isComplete)return this;var e=this._buildNewSequence(this.innerSequence.filter((function(t){return!t.isOperationError()})).map((function(t){return t.value})),d(d([],t),this._preProcessOperations)).filter((function(t){return!t.isMustStop()})),n=e.findIndex((function(t){return t.isOperationError()}));return n>-1?(this.innerSequence=e.slice(0,n),this.next.apply(this,this.innerSequence.map((function(t){return t.value}))),this.innerSequence.push(e[n]),this._triggerExecution([e[n]],this._subscribers),this):(this._triggerExecution(this.innerSequence=e,this._subscribers),this)},r.prototype.next=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return this._isComplete||(this.innerSequence=this._buildNewSequence(t,this._preProcessOperations),this._triggerExecution(this.innerSequence,this._subscribers)),this},r.prototype._buildNewSequence=function(t,r){for(var o=[],i=0,u=t.length;i<u;i++)try{var c=this._executeOperations(t[i],r);if(c.isMustStop()){o.push(c);break}c.isFilterNotMatched()||o.push(c)}catch(r){this._error=r,o.push(new n(t[i],e.OperationError,r)),i=u}return o},r.prototype._triggerExecution=function(t,r){var e=this;r.forEach((function(r){return e.executeSubscriber(r,t)}))},r}(O),m=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},x=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new(S.bind.apply(S,m([void 0],t)))},j=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},E=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return new(O.bind.apply(O,j([void 0],t)))};function P(){for(var t,r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];var n=new S;return(t=n._preProcessOperations).push.apply(t,r),n}var M=function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),q=function(t){function r(r){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var o=t.call(this)||this;return o.sourceObs$=r,o.subscriptions=[],o.operators=[],o._isClosed=!1,o.operators=e,o._isComplete=r._isComplete,o.sourceObs$._forks.push(o),o.sourceObs$.subscribe({next:function(t){o._subscribers.filter((function(t){return t.next})).forEach((function(r){var n=o._executeOperations(t,e);if(!n.isFilterNotMatched()&&!n.isMustStop())return r.next(n.value);n.isMustStop()&&o.close()}))},error:function(t){o._error=t,o._subscribers.filter((function(t){return t.error})).forEach((function(r){return r.error(t)}))},complete:function(){o._isComplete=!0,o.unsubscribe(),o._subscribers.filter((function(t){return t.complete})).forEach((function(t){return t.complete()}))}}),o}return M(r,t),Object.defineProperty(r.prototype,"innerSequence",{get:function(){return this.sourceObs$.innerSequence},set:function(t){this._innerSequence=t},enumerable:!1,configurable:!0}),r.prototype.subscribe=function(t){var r=this;if(!l(t)&&!y(t))throw new Error("Please provide either a function or a Subscriber");var o=y(t)?t:v(t);this._subscribers.push(o);for(var i=[],u=this.sourceObs$.innerSequence,c=0,s=u.length;c<s;c++)try{if(u[c].isOperationError())throw u[c].error;i.push(this._executeOperations(u[c].value,this.operators))}catch(t){i.push(new n(u[c].value,e.OperationError,t)),c=s}return this._isClosed?o.complete&&o.complete():this.executeSubscriber(o,i),new b((function(){return r._subscribers=r._subscribers.filter((function(r){return r!==t}))}))},r.prototype.close=function(){this._isClosed=!0,this._forks.forEach((function(t){return t.close()})),this._subscribers.forEach((function(t){return t.complete&&t.complete()})),this.unsubscribe()},r.prototype.unsubscribe=function(){this.subscriptions.forEach((function(t){return t.unsubscribe()}))},r}(O),C=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},N=function(t){for(var r=[],e=1;e<arguments.length;e++)r[e-1]=arguments[e];var n=new(q.bind.apply(q,C([void 0,t],r)));return n},k=function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),F=function(t){function r(r){var o=t.call(this)||this;return o.proxy=Object.assign(new Proxy(r,{apply:function(t,r,i){var u,c;try{c=new n(u=t.apply(r,i))}catch(t){c=new n(u,e.OperationError,t)}if(o.innerSequence=[c],o._subscribers.forEach((function(t){return o.executeSubscriber(t,o.innerSequence)})),c.isOperationError())throw c.error;return u}})),o}return k(r,t),r.create=function(t){var e=new r(t),n=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return e.proxy.apply(e,t)};return e.innerSequence=[],n.subscribe=e.subscribe.bind(e),n.pipe=e.pipe.bind(e),n.asObservable=function(){return e},n},r}(O),T=function(t){return F.create(t)},I=function(){var t=function(r,e){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,r){t.__proto__=r}||function(t,r){for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(t[e]=r[e])})(r,e)};return function(r,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=r}t(r,e),r.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),U=function(t,r){for(var e=0,n=r.length,o=t.length;e<n;e++,o++)t[o]=r[e];return t},A=function(t){function r(r){var o=t.call(this)||this;return o.promise=r.then((function(t){o.innerSequence.push(new n(t))})).catch((function(t){o.innerSequence.push(new n(void 0,e.OperationError,t))})),o}return I(r,t),r.prototype.pipe=function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return N.apply(void 0,U([this],t))},r.prototype.subscribe=function(t){var r=this;if(!l(t)&&!y(t))throw new Error("Please provide either a function or a Subscriber");var e=y(t)?t:v(t);return this._subscribers.push(e),this.promise.then((function(){return r.executeSubscriber(e,r.innerSequence)})),new b((function(){return r._subscribers=r._subscribers.filter((function(r){return r!==t}))}))},r}(O),$=function(){return($=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},J=function(){return(J=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},L=function(){return(L=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},D=function(){return(D=Object.assign||function(t){for(var r,e=1,n=arguments.length;e<n;e++)for(var o in r=arguments[e])Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o]);return t}).apply(this,arguments)},H={get:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,$($({},n),{method:"GET"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))},post:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,J(J({},n),{method:"POST"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))},put:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,L(L({},n),{method:"PUT"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))},delete:function(t,r){void 0===r&&(r={type:"json"});var e=r.type,n=function(t,r){var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&r.indexOf(n)<0&&(e[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)r.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(e[n[o]]=t[n[o]])}return e}(r,["type"]);return new A(new Promise((function(r,o){fetch(t,D(D({},n),{method:"DELETE"})).then((function(t){if(!t.ok)throw Error(t.statusText);return t})).then((function(t){return r("text"===e?t.text():"blob"===e?t.blob():t.json())})).catch((function(t){return o(t)}))})))}},K=function(t){var r=0;return function(o){return++r===t?new n(o):new n(o,r<t?e.FilterNotMatched:e.MustStop)}},V=function(t){var r=0;return function(o){return++r>t?new n(o,e.MustStop):new n(o)}},X=r.gC,G=r.hX,z=r.rM,B=r.Dp,Q=r.iT,R=r.dJ,W=r.KJ,Y=r.UI,Z=r.Nl,tt=r.hL,rt=r.of,et=r.IH,nt=r.d_,ot=r.wt,it=r.qn,ut=r.bw,ct=r.C4;export{X as asLongAs,G as filter,z as fork,B as from,Q as fromFunction,R as http,W as ifElse,Y as map,Z as mutable,tt as nth,rt as of,et as once,nt as preProcess,ot as switchMap,it as take,ut as tap,ct as until}; |
{ | ||
"name": "fleuvejs", | ||
"version": "1.2.6", | ||
"version": "1.2.67", | ||
"description": "A simple JavaScript Library for Observables", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -31,3 +31,3 @@ # FleuveJS | ||
```js | ||
import {of, map, mutable} from 'https://unpkg.com/fleuvejs@latest/bundle/fleuve.bundle.js'; | ||
import {of, map, mutable} from 'https://unpkg.com/fleuvejs@latest/bundle/observable.bundle.js'; | ||
``` | ||
@@ -34,0 +34,0 @@ |
@@ -115,6 +115,6 @@ import { OperatorFunction, OperationResult } from "../models/operator"; | ||
const obs$ = new MutableObservable<number>(); | ||
expect((obs$ as any)._innerSequence).toEqual([]); | ||
expect((obs$ as any).innerSequence).toEqual([]); | ||
obs$.next(12); | ||
expect( | ||
(obs$ as any)._innerSequence.map( | ||
(obs$ as any).innerSequence.map( | ||
(item: OperationResult<number>) => item.value | ||
@@ -125,3 +125,3 @@ ) | ||
expect( | ||
(obs$ as any)._innerSequence.map( | ||
(obs$ as any).innerSequence.map( | ||
(item: OperationResult<number>) => item.value | ||
@@ -128,0 +128,0 @@ ) |
@@ -46,3 +46,3 @@ import { | ||
const newSequence = this._buildNewSequence( | ||
this._innerSequence | ||
this.innerSequence | ||
.filter((event) => !event.isOperationError()) | ||
@@ -55,6 +55,6 @@ .map((event) => event.value), | ||
if (idxError > -1) { | ||
this._innerSequence = newSequence.slice(0, idxError); | ||
this.next(...this._innerSequence.map((event) => event.value)); | ||
this.innerSequence = newSequence.slice(0, idxError); | ||
this.next(...this.innerSequence.map((event) => event.value)); | ||
this._innerSequence.push(newSequence[idxError]); | ||
this.innerSequence.push(newSequence[idxError]); | ||
this._triggerExecution([newSequence[idxError]], this._subscribers); | ||
@@ -64,3 +64,3 @@ return this; | ||
this._triggerExecution(this._innerSequence = newSequence, this._subscribers); | ||
this._triggerExecution(this.innerSequence = newSequence, this._subscribers); | ||
@@ -75,7 +75,7 @@ return this; | ||
this._innerSequence = this._buildNewSequence( | ||
this.innerSequence = this._buildNewSequence( | ||
events, | ||
this._preProcessOperations | ||
); | ||
this._triggerExecution(this._innerSequence, this._subscribers); | ||
this._triggerExecution(this.innerSequence, this._subscribers); | ||
return this; | ||
@@ -82,0 +82,0 @@ } |
@@ -25,3 +25,12 @@ import { Observable } from "./observable"; | ||
private operators: OperatorFunction<T, OperationResult<any>>[] = []; | ||
private _isClosed: boolean = false; | ||
protected get innerSequence(): OperationResult<T>[] { | ||
return (this.sourceObs$ as any).innerSequence; | ||
} | ||
protected set innerSequence(sequence: OperationResult<T>[]) { | ||
this._innerSequence = sequence; | ||
} | ||
constructor( | ||
@@ -34,5 +43,5 @@ private sourceObs$: Types.Observable<T>, | ||
this._isComplete = (sourceObs$ as any)._isComplete; | ||
(this.sourceObs$ as any)._forks.push(this); | ||
this.sourceObs$.subscribe({ | ||
name: 'subscriber fork constructor', | ||
next: (value) => { | ||
@@ -81,3 +90,3 @@ this._subscribers | ||
const newSequence: OperationResult<T>[] = []; | ||
const sourceSequence = (this.sourceObs$ as any)._innerSequence as OperationResult<T>[]; // FIXME ew | ||
const sourceSequence = (this.sourceObs$ as any).innerSequence as OperationResult<T>[]; // FIXME ew | ||
@@ -104,4 +113,9 @@ for (let i = 0, l = sourceSequence.length; i < l; i++) { | ||
this.executeSubscriber(_subscriber, newSequence); | ||
if (this._isClosed) { | ||
(_subscriber.complete && _subscriber.complete()); | ||
} else { | ||
this.executeSubscriber(_subscriber, newSequence); | ||
} | ||
return new Subscription( | ||
@@ -116,2 +130,4 @@ () => | ||
close() { | ||
this._isClosed = true; | ||
this._forks.forEach((fork) => fork.close()); | ||
this._subscribers.forEach((s) => s.complete && s.complete()); | ||
@@ -118,0 +134,0 @@ this.unsubscribe(); |
@@ -9,3 +9,3 @@ import { subscriberOf, OnNext, Subscriber } from "../models/subscription"; | ||
const obs$ = new Observable(); | ||
expect((obs$ as any)._innerSequence).toEqual([]); | ||
expect((obs$ as any).innerSequence).toEqual([]); | ||
obs$.subscribe({ | ||
@@ -80,3 +80,3 @@ next: (value) => | ||
const pipedobs$ = obs$.pipe(map((value: number) => value * 2)); | ||
expect((pipedobs$ as any)._innerSequence).toEqual([]); | ||
expect((pipedobs$ as any).innerSequence).toEqual([]); | ||
pipedobs$.subscribe(() => { | ||
@@ -119,3 +119,3 @@ fail("Should not go there, Observable should not have been started"); | ||
const filteredobs$ = obs$.pipe(filter((value: number) => value < 10)); | ||
expect((filteredobs$ as any)._innerSequence).toEqual([]); | ||
expect((filteredobs$ as any).innerSequence).toEqual([]); | ||
filteredobs$.subscribe(() => { | ||
@@ -122,0 +122,0 @@ fail("Should not go there, Observable should not have been started"); |
@@ -15,7 +15,7 @@ import { filterNonFunctions, isFunction } from "../helpers/function.helper"; | ||
import {Types} from '../models/types'; | ||
import {ObservableFork, Types} from '../models/types'; | ||
export class Observable<T = never> implements Types.Observable<T> { | ||
protected _innerSequence: OperationResult<T>[]; | ||
protected _innerSequence!: OperationResult<T>[]; | ||
protected _subscribers: Subscriber<T>[] = []; | ||
@@ -25,4 +25,14 @@ protected _isComplete: boolean = true; | ||
protected _forks: ObservableFork<any>[] = []; | ||
protected get innerSequence() { | ||
return this._innerSequence; | ||
} | ||
protected set innerSequence(sequence: OperationResult<T>[]) { | ||
this._innerSequence = sequence; | ||
} | ||
constructor(...initialSequence: T[]) { | ||
this._innerSequence = initialSequence.map( | ||
this.innerSequence = initialSequence.map( | ||
(value) => new OperationResult(value) | ||
@@ -38,3 +48,3 @@ ); | ||
const newSequence: OperationResult<U>[] = []; | ||
const sourceSequence = this._innerSequence; | ||
const sourceSequence = this.innerSequence; | ||
for (let i = 0, l = sourceSequence.length; i < l && !sourceSequence[i].isMustStop(); i++ ) { | ||
@@ -56,3 +66,3 @@ try { | ||
obs$._innerSequence = newSequence; | ||
obs$.innerSequence = newSequence; | ||
return obs$; | ||
@@ -70,3 +80,3 @@ } | ||
this._subscribers.push(_subscriber); | ||
this.executeSubscriber(_subscriber, this._innerSequence); | ||
this.executeSubscriber(_subscriber, this.innerSequence); | ||
@@ -119,3 +129,3 @@ return new Subscription( | ||
case OperationResultFlag.UnwrapSwitch: | ||
res = new OperationResult(res.value._innerSequence.pop()?.value); | ||
res = new OperationResult(res.value.innerSequence[res.value.innerSequence.length - 1]?.value); | ||
break; | ||
@@ -122,0 +132,0 @@ default: |
@@ -28,6 +28,6 @@ import { isFunction } from "../helpers/function.helper"; | ||
.then((res: T) => { | ||
this._innerSequence.push(new OperationResult(res)); | ||
this.innerSequence.push(new OperationResult(res)); | ||
}) | ||
.catch((err: Error) => { | ||
this._innerSequence.push( | ||
this.innerSequence.push( | ||
new OperationResult( | ||
@@ -58,3 +58,3 @@ void 0 as any, | ||
const handler = () => this.executeSubscriber(_subscriber, this._innerSequence); | ||
const handler = () => this.executeSubscriber(_subscriber, this.innerSequence); | ||
@@ -61,0 +61,0 @@ this.promise.then(handler); |
import { map } from "../../transform/map"; | ||
import { switchMap } from "../../transform/switch-map"; | ||
import { fork } from "./fork"; | ||
import { mutable } from "./mutable"; | ||
import {of} from './of'; | ||
import { of } from "./of"; | ||
describe('fork', () => { | ||
it('will succeed', () => expect(true).toBe(true)); | ||
describe("fork", () => { | ||
it("will succeed", () => expect(true).toBe(true)); | ||
it('should create an observable fork from an Observable', () => { | ||
const obs$ = fork(of(12, 13), map(x => x * 2)); | ||
const spy = jest.fn(); | ||
obs$.subscribe({complete: () => spy()}); | ||
expect(spy).toHaveBeenCalled(); | ||
it("should create an observable fork from an Observable", () => { | ||
const obs$ = fork( | ||
of(12, 13), | ||
map((x) => x * 2) | ||
); | ||
const spy = jest.fn(); | ||
obs$.subscribe({ complete: () => spy() }); | ||
expect(spy).toHaveBeenCalled(); | ||
}); | ||
it("should create an observable fork from a MutableObservable", () => { | ||
const obs$ = fork( | ||
mutable(12, 13), | ||
map((x) => x * 2) | ||
); | ||
const completeSpy = jest.fn(); | ||
const nextSpy = jest.fn(); | ||
obs$.subscribe({ next: (x) => nextSpy(x), complete: () => completeSpy() }); | ||
expect(completeSpy).not.toHaveBeenCalled(); | ||
expect(nextSpy).toBeCalledTimes(2); | ||
}); | ||
it("should replace an observable by another with the switchMap operator", () => { | ||
const obs$ = fork( | ||
mutable(12, 13), | ||
switchMap(() => mutable("toto")) | ||
); | ||
const completeSpy = jest.fn(); | ||
const nextSpy = jest.fn(); | ||
obs$.subscribe({ next: (x) => nextSpy(x), complete: () => completeSpy() }); | ||
expect(completeSpy).not.toHaveBeenCalled(); | ||
expect(nextSpy).toHaveBeenCalledWith("toto"); | ||
}); | ||
describe("should take a mutable observable, and replace it by a fork observable", () => { | ||
const filterState$ = mutable<{ | ||
fromDate: Date | null; | ||
toDate: Date | null; | ||
}>({ | ||
fromDate: null, | ||
toDate: null, | ||
}); | ||
it('should create an observable fork from a MutableObservable', () => { | ||
const obs$ = fork(mutable(12, 13), map(x => x * 2)); | ||
const completeSpy = jest.fn(); | ||
const nextSpy = jest.fn(); | ||
obs$.subscribe({next: (x) => nextSpy(x), complete: () => completeSpy()}); | ||
expect(completeSpy).not.toHaveBeenCalled(); | ||
expect(nextSpy).toBeCalledTimes(2); | ||
const budgetState$ = mutable<{ expenses: number[]; incomes: number[] }>({ | ||
expenses: [], | ||
incomes: [], | ||
}); | ||
}); | ||
it("fork the budgetState$ and receive its sequence", () => { | ||
const completeSpy = jest.fn(); | ||
const nextSpy = jest.fn(); | ||
const forkBudget$ = fork<{ expenses: number[]; incomes: number[] }>( | ||
budgetState$ | ||
); | ||
const budgetSub = forkBudget$.subscribe({ | ||
next: nextSpy, | ||
complete: completeSpy, | ||
}); | ||
expect(completeSpy).not.toHaveBeenCalled(); | ||
expect(nextSpy).toHaveBeenCalledWith({ expenses: [], incomes: [] }); | ||
budgetSub.unsubscribe(); | ||
}); | ||
it("should fork the filterState$ and receive the budgetState$ sequence", () => { | ||
const completeSpy = jest.fn(); | ||
const nextSpy = jest.fn(); | ||
const fork$ = fork( | ||
filterState$, | ||
switchMap(() => budgetState$) | ||
); | ||
const forkSub = fork$.subscribe({ | ||
next: (state) => { | ||
nextSpy(state); | ||
}, | ||
complete: () => completeSpy(), | ||
}); | ||
budgetState$.compile( | ||
map((state) => ({ | ||
...state, | ||
expenses: [120], | ||
incomes: [140], | ||
})) | ||
); | ||
filterState$.compile( | ||
map(() => ({ | ||
fromDate: new Date(), | ||
toDate: null, | ||
})) | ||
); | ||
expect(nextSpy).toHaveBeenCalledWith({ expenses: [120], incomes: [140] }); | ||
forkSub.unsubscribe(); | ||
}); | ||
it("should fork the filterState$ and receive the budgetState$ sequence again", () => { | ||
const completeSpy = jest.fn(); | ||
const nextSpy = jest.fn(); | ||
const forkBudget$ = fork<{ expenses: number[]; incomes: number[] }>( | ||
budgetState$ | ||
); | ||
budgetState$.compile( | ||
map((state) => ({ | ||
...state, | ||
expenses: [], | ||
incomes: [], | ||
})) | ||
); | ||
const fork$ = fork( | ||
filterState$, | ||
switchMap(() => forkBudget$) | ||
); | ||
fork$.subscribe({ | ||
next: (state) => { | ||
nextSpy(state); | ||
}, | ||
complete: () => completeSpy(), | ||
}); | ||
expect(completeSpy).not.toHaveBeenCalled(); | ||
expect(nextSpy).toHaveBeenCalledWith({ expenses: [], incomes: [] }); | ||
budgetState$.compile( | ||
map(() => ({ | ||
expenses: [120], | ||
incomes: [140], | ||
})) | ||
); | ||
filterState$.compile( | ||
map(() => ({ | ||
fromDate: new Date(), | ||
toDate: null, | ||
})) | ||
); | ||
expect(nextSpy).toHaveBeenCalledWith({ expenses: [120], incomes: [140] }); | ||
}); | ||
}); | ||
}); |
@@ -24,4 +24,4 @@ import { OperationResult, OperationResultFlag, Types } from "../../../models"; | ||
this._innerSequence = [operationResult]; | ||
this._subscribers.forEach((s) => this.executeSubscriber(s, this._innerSequence)); | ||
this.innerSequence = [operationResult]; | ||
this._subscribers.forEach((s) => this.executeSubscriber(s, this.innerSequence)); | ||
@@ -41,3 +41,3 @@ if (operationResult.isOperationError()) { | ||
instance._innerSequence = []; | ||
instance.innerSequence = []; | ||
res.subscribe = instance.subscribe.bind(instance); | ||
@@ -44,0 +44,0 @@ res.pipe = instance.pipe.bind(instance); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
187816
3829