nedux
Version:
the next redux state management
16 lines (13 loc) • 13.1 kB
JavaScript
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).Nedux={})}(this,(function(r){"use strict";function t(r,t,e){return t in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function e(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function n(r){for(var n=1;arguments.length>n;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){t(r,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(o,t))}))}return r}
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
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
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */var o=function(r,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,t){r.__proto__=t}||function(r,t){for(var e in t)t.hasOwnProperty(e)&&(r[e]=t[e])})(r,t)};function i(r,t){function e(){this.constructor=r}o(r,t),r.prototype=null===t?Object.create(t):(e.prototype=t.prototype,new e)}function s(r){return"function"==typeof r}var u=!1,c={Promise:void 0,set useDeprecatedSynchronousErrorHandling(r){if(r);u=r},get useDeprecatedSynchronousErrorHandling(){return u}};function h(r){setTimeout((function(){throw r}),0)}var a={closed:!0,next:function(r){},error:function(r){if(c.useDeprecatedSynchronousErrorHandling)throw r;h(r)},complete:function(){}},p=function(){return Array.isArray||function(r){return r&&"number"==typeof r.length}}();var f=function(){function r(r){return Error.call(this),this.message=r?r.length+" errors occurred during unsubscription:\n"+r.map((function(r,t){return t+1+") "+r})).join("\n "):"",this.name="UnsubscriptionError",this.errors=r,this}return r.prototype=Object.create(Error.prototype),r}(),b=function(){function r(r){this.closed=!1,this._parentOrParents=null,this._subscriptions=null,r&&(this._unsubscribe=r)}return r.prototype.unsubscribe=function(){var t;if(!this.closed){var e,n=this._parentOrParents,o=this._unsubscribe,i=this._subscriptions;if(this.closed=!0,this._parentOrParents=null,this._subscriptions=null,n instanceof r)n.remove(this);else if(null!==n)for(var u=0;n.length>u;++u){n[u].remove(this)}if(s(o))try{o.call(this)}catch(r){t=r instanceof f?l(r.errors):[r]}if(p(i)){u=-1;for(var c=i.length;++u<c;){var h=i[u];if(null!==(e=h)&&"object"==typeof e)try{h.unsubscribe()}catch(r){t=t||[],r instanceof f?t=t.concat(l(r.errors)):t.push(r)}}}if(t)throw new f(t)}},r.prototype.add=function(t){var e=t;if(!t)return r.EMPTY;switch(typeof t){case"function":e=new r(t);case"object":if(e===this||e.closed||"function"!=typeof e.unsubscribe)return e;if(this.closed)return e.unsubscribe(),e;if(!(e instanceof r)){var n=e;(e=new r)._subscriptions=[n]}break;default:throw Error("unrecognized teardown "+t+" added to Subscription.")}var o=e._parentOrParents;if(null===o)e._parentOrParents=this;else if(o instanceof r){if(o===this)return e;e._parentOrParents=[o,this]}else{if(-1!==o.indexOf(this))return e;o.push(this)}var i=this._subscriptions;return null===i?this._subscriptions=[e]:i.push(e),e},r.prototype.remove=function(r){var t=this._subscriptions;if(t){var e=t.indexOf(r);-1!==e&&t.splice(e,1)}},r.EMPTY=function(r){return r.closed=!0,r}(new r),r}();function l(r){return r.reduce((function(r,t){return r.concat(t instanceof f?t.errors:t)}),[])}var y=function(){return"function"==typeof Symbol?Symbol("rxSubscriber"):"@@rxSubscriber_"+Math.random()}(),d=function(r){function t(e,n,o){var i=r.call(this)||this;switch(i.syncErrorValue=null,i.syncErrorThrown=!1,i.syncErrorThrowable=!1,i.isStopped=!1,arguments.length){case 0:i.destination=a;break;case 1:if(!e){i.destination=a;break}if("object"==typeof e){e instanceof t?(i.syncErrorThrowable=e.syncErrorThrowable,i.destination=e,e.add(i)):(i.syncErrorThrowable=!0,i.destination=new _(i,e));break}default:i.syncErrorThrowable=!0,i.destination=new _(i,e,n,o)}return i}return i(t,r),t.prototype[y]=function(){return this},t.create=function(r,e,n){var o=new t(r,e,n);return o.syncErrorThrowable=!1,o},t.prototype.next=function(r){this.isStopped||this._next(r)},t.prototype.error=function(r){this.isStopped||(this.isStopped=!0,this._error(r))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this))},t.prototype._next=function(r){this.destination.next(r)},t.prototype._error=function(r){this.destination.error(r),this.unsubscribe()},t.prototype._complete=function(){this.destination.complete(),this.unsubscribe()},t.prototype._unsubscribeAndRecycle=function(){var r=this._parentOrParents;return this._parentOrParents=null,this.unsubscribe(),this.closed=!1,this.isStopped=!1,this._parentOrParents=r,this},t}(b),_=function(r){function t(t,e,n,o){var i,u=r.call(this)||this;u._parentSubscriber=t;var c=u;return s(e)?i=e:e&&(i=e.next,n=e.error,o=e.complete,e!==a&&(s((c=Object.create(e)).unsubscribe)&&u.add(c.unsubscribe.bind(c)),c.unsubscribe=u.unsubscribe.bind(u))),u._context=c,u._next=i,u._error=n,u._complete=o,u}return i(t,r),t.prototype.next=function(r){if(!this.isStopped&&this._next){var t=this._parentSubscriber;c.useDeprecatedSynchronousErrorHandling&&t.syncErrorThrowable?this.__tryOrSetError(t,this._next,r)&&this.unsubscribe():this.__tryOrUnsub(this._next,r)}},t.prototype.error=function(r){if(!this.isStopped){var t=this._parentSubscriber,e=c.useDeprecatedSynchronousErrorHandling;if(this._error)e&&t.syncErrorThrowable?(this.__tryOrSetError(t,this._error,r),this.unsubscribe()):(this.__tryOrUnsub(this._error,r),this.unsubscribe());else if(t.syncErrorThrowable)e?(t.syncErrorValue=r,t.syncErrorThrown=!0):h(r),this.unsubscribe();else{if(this.unsubscribe(),e)throw r;h(r)}}},t.prototype.complete=function(){var r=this;if(!this.isStopped){var t=this._parentSubscriber;if(this._complete){var e=function(){return r._complete.call(r._context)};c.useDeprecatedSynchronousErrorHandling&&t.syncErrorThrowable?(this.__tryOrSetError(t,e),this.unsubscribe()):(this.__tryOrUnsub(e),this.unsubscribe())}else this.unsubscribe()}},t.prototype.__tryOrUnsub=function(r,t){try{r.call(this._context,t)}catch(r){if(this.unsubscribe(),c.useDeprecatedSynchronousErrorHandling)throw r;h(r)}},t.prototype.__tryOrSetError=function(r,t,e){if(!c.useDeprecatedSynchronousErrorHandling)throw Error("bad call");try{t.call(this._context,e)}catch(t){return c.useDeprecatedSynchronousErrorHandling?(r.syncErrorValue=t,r.syncErrorThrown=!0,!0):(h(t),!0)}return!1},t.prototype._unsubscribe=function(){var r=this._parentSubscriber;this._context=null,this._parentSubscriber=null,r.unsubscribe()},t}(d);var v=function(){return"function"==typeof Symbol&&Symbol.observable||"@@observable"}();function w(){}function E(r){return r?1===r.length?r[0]:function(t){return r.reduce((function(r,t){return t(r)}),t)}:w}var S=function(){function r(r){this._isScalar=!1,r&&(this._subscribe=r)}return r.prototype.lift=function(t){var e=new r;return e.source=this,e.operator=t,e},r.prototype.subscribe=function(r,t,e){var n=this.operator,o=function(r,t,e){if(r){if(r instanceof d)return r;if(r[y])return r[y]()}return r||t||e?new d(r,t,e):new d(a)}(r,t,e);if(o.add(n?n.call(o,this.source):this.source||c.useDeprecatedSynchronousErrorHandling&&!o.syncErrorThrowable?this._subscribe(o):this._trySubscribe(o)),c.useDeprecatedSynchronousErrorHandling&&o.syncErrorThrowable&&(o.syncErrorThrowable=!1,o.syncErrorThrown))throw o.syncErrorValue;return o},r.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(t){c.useDeprecatedSynchronousErrorHandling&&(r.syncErrorThrown=!0,r.syncErrorValue=t),!function(r){for(;r;){var t=r.destination;if(r.closed||r.isStopped)return!1;r=t&&t instanceof d?t:null}return!0}(r)?console.warn(t):r.error(t)}},r.prototype.forEach=function(r,t){var e=this;return new(t=O(t))((function(t,n){var o;o=e.subscribe((function(t){try{r(t)}catch(r){n(r),o&&o.unsubscribe()}}),n,t)}))},r.prototype._subscribe=function(r){var t=this.source;return t&&t.subscribe(r)},r.prototype[v]=function(){return this},r.prototype.pipe=function(){for(var r=[],t=0;arguments.length>t;t++)r[t]=arguments[t];return 0===r.length?this:E(r)(this)},r.prototype.toPromise=function(r){var t=this;return new(r=O(r))((function(r,e){var n;t.subscribe((function(r){return n=r}),(function(r){return e(r)}),(function(){return r(n)}))}))},r.create=function(t){return new r(t)},r}();function O(r){if(r||(r=Promise),!r)throw Error("no Promise impl found");return r}var g=function(){function r(){return Error.call(this),this.message="object unsubscribed",this.name="ObjectUnsubscribedError",this}return r.prototype=Object.create(Error.prototype),r}(),m=function(r){function t(t,e){var n=r.call(this)||this;return n.subject=t,n.subscriber=e,n.closed=!1,n}return i(t,r),t.prototype.unsubscribe=function(){if(!this.closed){this.closed=!0;var r=this.subject,t=r.observers;if(this.subject=null,t&&0!==t.length&&!r.isStopped&&!r.closed){var e=t.indexOf(this.subscriber);-1!==e&&t.splice(e,1)}}},t}(b),x=function(r){function t(t){var e=r.call(this,t)||this;return e.destination=t,e}return i(t,r),t}(d),j=function(r){function t(){var t=r.call(this)||this;return t.observers=[],t.closed=!1,t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return i(t,r),t.prototype[y]=function(){return new x(this)},t.prototype.lift=function(r){var t=new P(this,this);return t.operator=r,t},t.prototype.next=function(r){if(this.closed)throw new g;if(!this.isStopped)for(var t=this.observers,e=t.length,n=t.slice(),o=0;e>o;o++)n[o].next(r)},t.prototype.error=function(r){if(this.closed)throw new g;this.hasError=!0,this.thrownError=r,this.isStopped=!0;for(var t=this.observers,e=t.length,n=t.slice(),o=0;e>o;o++)n[o].error(r);this.observers.length=0},t.prototype.complete=function(){if(this.closed)throw new g;this.isStopped=!0;for(var r=this.observers,t=r.length,e=r.slice(),n=0;t>n;n++)e[n].complete();this.observers.length=0},t.prototype.unsubscribe=function(){this.isStopped=!0,this.closed=!0,this.observers=null},t.prototype._trySubscribe=function(t){if(this.closed)throw new g;return r.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(r){if(this.closed)throw new g;return this.hasError?(r.error(this.thrownError),b.EMPTY):this.isStopped?(r.complete(),b.EMPTY):(this.observers.push(r),new m(this,r))},t.prototype.asObservable=function(){var r=new S;return r.source=this,r},t.create=function(r,t){return new P(r,t)},t}(S),P=function(r){function t(t,e){var n=r.call(this)||this;return n.destination=t,n.source=e,n}return i(t,r),t.prototype.next=function(r){var t=this.destination;t&&t.next&&t.next(r)},t.prototype.error=function(r){var t=this.destination;t&&t.error&&this.destination.error(r)},t.prototype.complete=function(){var r=this.destination;r&&r.complete&&this.destination.complete()},t.prototype._subscribe=function(r){return this.source?this.source.subscribe(r):b.EMPTY},t}(j),T=function(r){function t(t){var e=r.call(this)||this;return e._value=t,e}return i(t,r),Object.defineProperty(t.prototype,"value",{get:function(){return this.getValue()},enumerable:!0,configurable:!0}),t.prototype._subscribe=function(t){var e=r.prototype._subscribe.call(this,t);return e&&!e.closed&&t.next(this._value),e},t.prototype.getValue=function(){if(this.hasError)throw this.thrownError;if(this.closed)throw new g;return this._value},t.prototype.next=function(t){r.prototype.next.call(this,this._value=t)},t}(j);r.createStore=function(r,t){void 0===t&&(t=[]);var e=Object.keys(r).reduce((function(t,e){var o,i=new T(r[e]);return n({},t,((o={})[e]=i,o))}),{}),o=function(r){return e[r].getValue()},i={get:o,set:function(r,t){e[r].next("function"==typeof t?t(o(r)):t)},subscribe:function(r,t,o){var i=(void 0===o?{}:o).withInitialValue,s=void 0!==i&&i,u=!1,c=function(r){var e=function(r){return"function"==typeof t?{next:function(e){return t(e,r)}}:t}(r);return n({},e,{next:s?e.next:function(r){u?e.next&&e.next(r):u=!0}})};return""===r?Object.keys(e).map((function(r){return e[r].subscribe(c(r))})):e[r].subscribe(c(r))}};return t.forEach((function(r){return r(i)})),i},Object.defineProperty(r,"__esModule",{value:!0})}));