rx-tiny-flux 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.idea/aws.xml ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="accountSettings">
4
+ <option name="activeProfile" value="profile:default" />
5
+ <option name="activeRegion" value="us-east-1" />
6
+ <option name="recentlyUsedProfiles">
7
+ <list>
8
+ <option value="profile:default" />
9
+ </list>
10
+ </option>
11
+ <option name="recentlyUsedRegions">
12
+ <list>
13
+ <option value="us-east-1" />
14
+ </list>
15
+ </option>
16
+ </component>
17
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/rx-store.iml" filepath="$PROJECT_DIR$/.idea/rx-store.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$/../rx-tiny-flux">
5
+ <excludeFolder url="file://$MODULE_DIR$/../rx-tiny-flux/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/../rx-tiny-flux/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/../rx-tiny-flux/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
@@ -0,0 +1 @@
1
+ var t=function(n,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])},t(n,r)};function n(n,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=n}t(n,r),n.prototype=null===r?Object.create(r):(e.prototype=r.prototype,new e)}function r(t,n,r,e){return new(r||(r=Promise))(function(o,i){function u(t){try{s(e.next(t))}catch(t){i(t)}}function c(t){try{s(e.throw(t))}catch(t){i(t)}}function s(t){var n;t.done?o(t.value):(n=t.value,n instanceof r?n:new r(function(t){t(n)})).then(u,c)}s((e=e.apply(t,n||[])).next())})}function e(t,n){var r,e,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return u.next=c(0),u.throw=c(1),u.return=c(2),"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function c(c){return function(s){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;u&&(u=0,c[0]&&(i=0)),i;)try{if(r=1,e&&(o=2&c[0]?e.return:c[0]?e.throw||((o=e.return)&&o.call(e),0):e.next)&&!(o=o.call(e,c[1])).done)return o;switch(e=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return i.label++,{value:c[1],done:!1};case 5:i.label++,e=c[1],c=[0];continue;case 7:c=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){i=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){i.label=c[1];break}if(6===c[0]&&i.label<o[1]){i.label=o[1],o=c;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(c);break}o[2]&&i.ops.pop(),i.trys.pop();continue}c=n.call(t,i)}catch(t){c=[6,t],e=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}function o(t){var n="function"==typeof Symbol&&Symbol.iterator,r=n&&t[n],e=0;if(r)return r.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&e>=t.length&&(t=void 0),{value:t&&t[e++],done:!t}}};throw new TypeError(n?"Object is not iterable.":"Symbol.iterator is not defined.")}function i(t,n){var r="function"==typeof Symbol&&t[Symbol.iterator];if(!r)return t;var e,o,i=r.call(t),u=[];try{for(;(void 0===n||n-- >0)&&!(e=i.next()).done;)u.push(e.value)}catch(t){o={error:t}}finally{try{e&&!e.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return u}function u(t,n,r){if(r||2===arguments.length)for(var e,o=0,i=n.length;o<i;o++)!e&&o in n||(e||(e=Array.prototype.slice.call(n,0,o)),e[o]=n[o]);return t.concat(e||Array.prototype.slice.call(n))}function c(t){return this instanceof c?(this.v=t,this):new c(t)}function s(t,n,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,o=r.apply(t,n||[]),i=[];return e=Object.create(("function"==typeof AsyncIterator?AsyncIterator:Object).prototype),u("next"),u("throw"),u("return",function(t){return function(n){return Promise.resolve(n).then(t,a)}}),e[Symbol.asyncIterator]=function(){return this},e;function u(t,n){o[t]&&(e[t]=function(n){return new Promise(function(r,e){i.push([t,n,r,e])>1||s(t,n)})},n&&(e[t]=n(e[t])))}function s(t,n){try{(r=o[t](n)).value instanceof c?Promise.resolve(r.value.v).then(l,a):f(i[0][2],r)}catch(t){f(i[0][3],t)}var r}function l(t){s("next",t)}function a(t){s("throw",t)}function f(t,n){t(n),i.shift(),i.length&&s(i[0][0],i[0][1])}}function l(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n,r=t[Symbol.asyncIterator];return r?r.call(t):(t=o(t),n={},e("next"),e("throw"),e("return"),n[Symbol.asyncIterator]=function(){return this},n);function e(r){n[r]=t[r]&&function(n){return new Promise(function(e,o){(function(t,n,r,e){Promise.resolve(e).then(function(n){t({value:n,done:r})},n)})(e,o,(n=t[r](n)).done,n.value)})}}}function a(t){return"function"==typeof t}function f(t){var n=t(function(t){Error.call(t),t.stack=(new Error).stack});return n.prototype=Object.create(Error.prototype),n.prototype.constructor=n,n}"function"==typeof SuppressedError&&SuppressedError;var h=f(function(t){return function(n){t(this),this.message=n?n.length+" errors occurred during unsubscription:\n"+n.map(function(t,n){return n+1+") "+t.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=n}});function p(t,n){if(t){var r=t.indexOf(n);0<=r&&t.splice(r,1)}}var d=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var n;return t.prototype.unsubscribe=function(){var t,n,r,e,c;if(!this.closed){this.closed=!0;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var l=o(s),f=l.next();!f.done;f=l.next()){f.value.remove(this)}}catch(n){t={error:n}}finally{try{f&&!f.done&&(n=l.return)&&n.call(l)}finally{if(t)throw t.error}}else s.remove(this);var p=this.initialTeardown;if(a(p))try{p()}catch(t){c=t instanceof h?t.errors:[t]}var d=this._finalizers;if(d){this._finalizers=null;try{for(var v=o(d),b=v.next();!b.done;b=v.next()){var w=b.value;try{y(w)}catch(t){c=null!=c?c:[],t instanceof h?c=u(u([],i(c)),i(t.errors)):c.push(t)}}}catch(t){r={error:t}}finally{try{b&&!b.done&&(e=v.return)&&e.call(v)}finally{if(r)throw r.error}}}if(c)throw new h(c)}},t.prototype.add=function(n){var r;if(n&&n!==this)if(this.closed)y(n);else{if(n instanceof t){if(n.closed||n._hasParent(this))return;n._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(n)}},t.prototype._hasParent=function(t){var n=this._parentage;return n===t||Array.isArray(n)&&n.includes(t)},t.prototype._addParent=function(t){var n=this._parentage;this._parentage=Array.isArray(n)?(n.push(t),n):n?[n,t]:t},t.prototype._removeParent=function(t){var n=this._parentage;n===t?this._parentage=null:Array.isArray(n)&&p(n,t)},t.prototype.remove=function(n){var r=this._finalizers;r&&p(r,n),n instanceof t&&n._removeParent(this)},t.EMPTY=((n=new t).closed=!0,n),t}(),v=d.EMPTY;function b(t){return t instanceof d||t&&"closed"in t&&a(t.remove)&&a(t.add)&&a(t.unsubscribe)}function y(t){a(t)?t():t.unsubscribe()}var w={Promise:void 0},m=function(t,n){for(var r=[],e=2;e<arguments.length;e++)r[e-2]=arguments[e];return setTimeout.apply(void 0,u([t,n],i(r)))};function _(t){m(function(){throw t})}function x(){}function g(t){t()}var S=function(t){function r(n){var r=t.call(this)||this;return r.isStopped=!1,n?(r.destination=n,b(n)&&n.add(r)):r.destination=A,r}return n(r,t),r.create=function(t,n,r){return new E(t,n,r)},r.prototype.next=function(t){this.isStopped||this._next(t)},r.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},r.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(t){this.destination.next(t)},r.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r}(d),O=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var n=this.partialObserver;if(n.next)try{n.next(t)}catch(t){I(t)}},t.prototype.error=function(t){var n=this.partialObserver;if(n.error)try{n.error(t)}catch(t){I(t)}else I(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){I(t)}},t}(),E=function(t){function r(n,r,e){var o,i=t.call(this)||this;return o=a(n)||!n?{next:null!=n?n:void 0,error:null!=r?r:void 0,complete:null!=e?e:void 0}:n,i.destination=new O(o),i}return n(r,t),r}(S);function I(t){_(t)}var A={closed:!0,next:x,error:function(t){throw t},complete:x},P="function"==typeof Symbol&&Symbol.observable||"@@observable";function T(t){return t}var C=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(n){var r=new t;return r.source=this,r.operator=n,r},t.prototype.subscribe=function(t,n,r){var e,o=this,i=(e=t)&&e instanceof S||function(t){return t&&a(t.next)&&a(t.error)&&a(t.complete)}(e)&&b(e)?t:new E(t,n,r);return g(function(){var t=o,n=t.operator,r=t.source;i.add(n?n.call(i,r):r?o._subscribe(i):o._trySubscribe(i))}),i},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(n){t.error(n)}},t.prototype.forEach=function(t,n){var r=this;return new(n=j(n))(function(n,e){var o=new E({next:function(n){try{t(n)}catch(t){e(t),o.unsubscribe()}},error:e,complete:n});r.subscribe(o)})},t.prototype._subscribe=function(t){var n;return null===(n=this.source)||void 0===n?void 0:n.subscribe(t)},t.prototype[P]=function(){return this},t.prototype.pipe=function(){for(var t,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return(0===(t=n).length?T:1===t.length?t[0]:function(n){return t.reduce(function(t,n){return n(t)},n)})(this)},t.prototype.toPromise=function(t){var n=this;return new(t=j(t))(function(t,r){var e;n.subscribe(function(t){return e=t},function(t){return r(t)},function(){return t(e)})})},t.create=function(n){return new t(n)},t}();function j(t){var n;return null!==(n=null!=t?t:w.Promise)&&void 0!==n?n:Promise}function k(t){return function(n){if(function(t){return a(null==t?void 0:t.lift)}(n))return n.lift(function(n){try{return t(n,this)}catch(t){this.error(t)}});throw new TypeError("Unable to lift unknown Observable type")}}function z(t,n,r,e,o){return new F(t,n,r,e,o)}var F=function(t){function r(n,r,e,o,i,u){var c=t.call(this,n)||this;return c.onFinalize=i,c.shouldUnsubscribe=u,c._next=r?function(t){try{r(t)}catch(t){n.error(t)}}:t.prototype._next,c._error=o?function(t){try{o(t)}catch(t){n.error(t)}finally{this.unsubscribe()}}:t.prototype._error,c._complete=e?function(){try{e()}catch(t){n.error(t)}finally{this.unsubscribe()}}:t.prototype._complete,c}return n(r,t),r.prototype.unsubscribe=function(){var n;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var r=this.closed;t.prototype.unsubscribe.call(this),!r&&(null===(n=this.onFinalize)||void 0===n||n.call(this))}},r}(S),$=f(function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}}),N=function(t){function r(){var n=t.call(this)||this;return n.closed=!1,n.currentObservers=null,n.observers=[],n.isStopped=!1,n.hasError=!1,n.thrownError=null,n}return n(r,t),r.prototype.lift=function(t){var n=new R(this,this);return n.operator=t,n},r.prototype._throwIfClosed=function(){if(this.closed)throw new $},r.prototype.next=function(t){var n=this;g(function(){var r,e;if(n._throwIfClosed(),!n.isStopped){n.currentObservers||(n.currentObservers=Array.from(n.observers));try{for(var i=o(n.currentObservers),u=i.next();!u.done;u=i.next()){u.value.next(t)}}catch(t){r={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(r)throw r.error}}}})},r.prototype.error=function(t){var n=this;g(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=t;for(var r=n.observers;r.length;)r.shift().error(t)}})},r.prototype.complete=function(){var t=this;g(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var n=t.observers;n.length;)n.shift().complete()}})},r.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(r.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),r.prototype._trySubscribe=function(n){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,n)},r.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},r.prototype._innerSubscribe=function(t){var n=this,r=this,e=r.hasError,o=r.isStopped,i=r.observers;return e||o?v:(this.currentObservers=null,i.push(t),new d(function(){n.currentObservers=null,p(i,t)}))},r.prototype._checkFinalizedStatuses=function(t){var n=this,r=n.hasError,e=n.thrownError,o=n.isStopped;r?t.error(e):o&&t.complete()},r.prototype.asObservable=function(){var t=new C;return t.source=this,t},r.create=function(t,n){return new R(t,n)},r}(C),R=function(t){function r(n,r){var e=t.call(this)||this;return e.destination=n,e.source=r,e}return n(r,t),r.prototype.next=function(t){var n,r;null===(r=null===(n=this.destination)||void 0===n?void 0:n.next)||void 0===r||r.call(n,t)},r.prototype.error=function(t){var n,r;null===(r=null===(n=this.destination)||void 0===n?void 0:n.error)||void 0===r||r.call(n,t)},r.prototype.complete=function(){var t,n;null===(n=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===n||n.call(t)},r.prototype._subscribe=function(t){var n,r;return null!==(r=null===(n=this.source)||void 0===n?void 0:n.subscribe(t))&&void 0!==r?r:v},r}(N),J=function(t){function r(n){var r=t.call(this)||this;return r._value=n,r}return n(r,t),Object.defineProperty(r.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),r.prototype._subscribe=function(n){var r=t.prototype._subscribe.call(this,n);return!r.closed&&n.next(this._value),r},r.prototype.getValue=function(){var t=this,n=t.hasError,r=t.thrownError,e=t._value;if(n)throw r;return this._throwIfClosed(),e},r.prototype.next=function(n){t.prototype.next.call(this,this._value=n)},r}(N),U={now:function(){return(U.delegate||Date).now()},delegate:void 0},W=function(t){function r(n,r,e){void 0===n&&(n=1/0),void 0===r&&(r=1/0),void 0===e&&(e=U);var o=t.call(this)||this;return o._bufferSize=n,o._windowTime=r,o._timestampProvider=e,o._buffer=[],o._infiniteTimeWindow=!0,o._infiniteTimeWindow=r===1/0,o._bufferSize=Math.max(1,n),o._windowTime=Math.max(1,r),o}return n(r,t),r.prototype.next=function(n){var r=this,e=r.isStopped,o=r._buffer,i=r._infiniteTimeWindow,u=r._timestampProvider,c=r._windowTime;e||(o.push(n),!i&&o.push(u.now()+c)),this._trimBuffer(),t.prototype.next.call(this,n)},r.prototype._subscribe=function(t){this._throwIfClosed(),this._trimBuffer();for(var n=this._innerSubscribe(t),r=this._infiniteTimeWindow,e=this._buffer.slice(),o=0;o<e.length&&!t.closed;o+=r?1:2)t.next(e[o]);return this._checkFinalizedStatuses(t),n},r.prototype._trimBuffer=function(){var t=this,n=t._bufferSize,r=t._timestampProvider,e=t._buffer,o=t._infiniteTimeWindow,i=(o?1:2)*n;if(n<1/0&&i<e.length&&e.splice(0,e.length-i),!o){for(var u=r.now(),c=0,s=1;s<e.length&&e[s]<=u;s+=2)c=s;c&&e.splice(0,c+1)}},r}(N),M=function(t){function r(n,r){return t.call(this)||this}return n(r,t),r.prototype.schedule=function(t,n){return this},r}(d),Y=function(t,n){for(var r=[],e=2;e<arguments.length;e++)r[e-2]=arguments[e];return setInterval.apply(void 0,u([t,n],i(r)))},B=function(t){return clearInterval(t)},D=function(t){function r(n,r){var e=t.call(this,n,r)||this;return e.scheduler=n,e.work=r,e.pending=!1,e}return n(r,t),r.prototype.schedule=function(t,n){var r;if(void 0===n&&(n=0),this.closed)return this;this.state=t;var e=this.id,o=this.scheduler;return null!=e&&(this.id=this.recycleAsyncId(o,e,n)),this.pending=!0,this.delay=n,this.id=null!==(r=this.id)&&void 0!==r?r:this.requestAsyncId(o,this.id,n),this},r.prototype.requestAsyncId=function(t,n,r){return void 0===r&&(r=0),Y(t.flush.bind(t,this),r)},r.prototype.recycleAsyncId=function(t,n,r){if(void 0===r&&(r=0),null!=r&&this.delay===r&&!1===this.pending)return n;null!=n&&B(n)},r.prototype.execute=function(t,n){if(this.closed)return new Error("executing a cancelled action");this.pending=!1;var r=this._execute(t,n);if(r)return r;!1===this.pending&&null!=this.id&&(this.id=this.recycleAsyncId(this.scheduler,this.id,null))},r.prototype._execute=function(t,n){var r,e=!1;try{this.work(t)}catch(t){e=!0,r=t||new Error("Scheduled action threw falsy error")}if(e)return this.unsubscribe(),r},r.prototype.unsubscribe=function(){if(!this.closed){var n=this.id,r=this.scheduler,e=r.actions;this.work=this.state=this.scheduler=null,this.pending=!1,p(e,this),null!=n&&(this.id=this.recycleAsyncId(r,n,null)),this.delay=null,t.prototype.unsubscribe.call(this)}},r}(M),V=function(){function t(n,r){void 0===r&&(r=t.now),this.schedulerActionCtor=n,this.now=r}return t.prototype.schedule=function(t,n,r){return void 0===n&&(n=0),new this.schedulerActionCtor(this,t).schedule(r,n)},t.now=U.now,t}(),q=new(function(t){function r(n,r){void 0===r&&(r=V.now);var e=t.call(this,n,r)||this;return e.actions=[],e._active=!1,e}return n(r,t),r.prototype.flush=function(t){var n=this.actions;if(this._active)n.push(t);else{var r;this._active=!0;do{if(r=t.execute(t.state,t.delay))break}while(t=n.shift());if(this._active=!1,r){for(;t=n.shift();)t.unsubscribe();throw r}}},r}(V))(D),Z=q,G=new C(function(t){return t.complete()});function K(t){return t&&a(t.schedule)}function L(t){return t[t.length-1]}function H(t){return K(L(t))?t.pop():void 0}var Q=function(t){return t&&"number"==typeof t.length&&"function"!=typeof t};function X(t){return a(null==t?void 0:t.then)}function tt(t){return a(t[P])}function nt(t){return Symbol.asyncIterator&&a(null==t?void 0:t[Symbol.asyncIterator])}function rt(t){return new TypeError("You provided "+(null!==t&&"object"==typeof t?"an invalid object":"'"+t+"'")+" where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.")}var et="function"==typeof Symbol&&Symbol.iterator?Symbol.iterator:"@@iterator";function ot(t){return a(null==t?void 0:t[et])}function it(t){return s(this,arguments,function(){var n,r,o;return e(this,function(e){switch(e.label){case 0:n=t.getReader(),e.label=1;case 1:e.trys.push([1,,9,10]),e.label=2;case 2:return[4,c(n.read())];case 3:return r=e.sent(),o=r.value,r.done?[4,c(void 0)]:[3,5];case 4:return[2,e.sent()];case 5:return[4,c(o)];case 6:return[4,e.sent()];case 7:return e.sent(),[3,2];case 8:return[3,10];case 9:return n.releaseLock(),[7];case 10:return[2]}})})}function ut(t){return a(null==t?void 0:t.getReader)}function ct(t){if(t instanceof C)return t;if(null!=t){if(tt(t))return i=t,new C(function(t){var n=i[P]();if(a(n.subscribe))return n.subscribe(t);throw new TypeError("Provided object does not correctly implement Symbol.observable")});if(Q(t))return e=t,new C(function(t){for(var n=0;n<e.length&&!t.closed;n++)t.next(e[n]);t.complete()});if(X(t))return r=t,new C(function(t){r.then(function(n){t.closed||(t.next(n),t.complete())},function(n){return t.error(n)}).then(null,_)});if(nt(t))return st(t);if(ot(t))return n=t,new C(function(t){var r,e;try{for(var i=o(n),u=i.next();!u.done;u=i.next()){var c=u.value;if(t.next(c),t.closed)return}}catch(t){r={error:t}}finally{try{u&&!u.done&&(e=i.return)&&e.call(i)}finally{if(r)throw r.error}}t.complete()});if(ut(t))return st(it(t))}var n,r,e,i;throw rt(t)}function st(t){return new C(function(n){(function(t,n){var o,i,u,c;return r(this,void 0,void 0,function(){var r,s;return e(this,function(e){switch(e.label){case 0:e.trys.push([0,5,6,11]),o=l(t),e.label=1;case 1:return[4,o.next()];case 2:if((i=e.sent()).done)return[3,4];if(r=i.value,n.next(r),n.closed)return[2];e.label=3;case 3:return[3,1];case 4:return[3,11];case 5:return s=e.sent(),u={error:s},[3,11];case 6:return e.trys.push([6,,9,10]),i&&!i.done&&(c=o.return)?[4,c.call(o)]:[3,8];case 7:e.sent(),e.label=8;case 8:return[3,10];case 9:if(u)throw u.error;return[7];case 10:return[7];case 11:return n.complete(),[2]}})})})(t,n).catch(function(t){return n.error(t)})})}function lt(t,n,r,e,o){void 0===e&&(e=0),void 0===o&&(o=!1);var i=n.schedule(function(){r(),o?t.add(this.schedule(null,e)):this.unsubscribe()},e);if(t.add(i),!o)return i}function at(t,n){return void 0===n&&(n=0),k(function(r,e){r.subscribe(z(e,function(r){return lt(e,t,function(){return e.next(r)},n)},function(){return lt(e,t,function(){return e.complete()},n)},function(r){return lt(e,t,function(){return e.error(r)},n)}))})}function ft(t,n){return void 0===n&&(n=0),k(function(r,e){e.add(t.schedule(function(){return r.subscribe(e)},n))})}function ht(t,n){if(!t)throw new Error("Iterable cannot be null");return new C(function(r){lt(r,n,function(){var e=t[Symbol.asyncIterator]();lt(r,n,function(){e.next().then(function(t){t.done?r.complete():r.next(t.value)})},0,!0)})})}function pt(t,n){if(null!=t){if(tt(t))return function(t,n){return ct(t).pipe(ft(n),at(n))}(t,n);if(Q(t))return function(t,n){return new C(function(r){var e=0;return n.schedule(function(){e===t.length?r.complete():(r.next(t[e++]),r.closed||this.schedule())})})}(t,n);if(X(t))return function(t,n){return ct(t).pipe(ft(n),at(n))}(t,n);if(nt(t))return ht(t,n);if(ot(t))return function(t,n){return new C(function(r){var e;return lt(r,n,function(){e=t[et](),lt(r,n,function(){var t,n,o;try{n=(t=e.next()).value,o=t.done}catch(t){return void r.error(t)}o?r.complete():r.next(n)},0,!0)}),function(){return a(null==e?void 0:e.return)&&e.return()}})}(t,n);if(ut(t))return function(t,n){return ht(it(t),n)}(t,n)}throw rt(t)}function dt(t,n){return n?pt(t,n):ct(t)}function vt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return dt(t,H(t))}function bt(t,n){return k(function(r,e){var o=0;r.subscribe(z(e,function(r){e.next(t.call(n,r,o++))}))})}function yt(t,n,r){return void 0===r&&(r=1/0),a(n)?yt(function(r,e){return bt(function(t,o){return n(r,t,e,o)})(ct(t(r,e)))},r):("number"==typeof n&&(r=n),k(function(n,e){return function(t,n,r,e,o,i,u){var c=[],s=0,l=0,a=!1,f=function(){!a||c.length||s||n.complete()},h=function(t){s++;var o=!1;ct(r(t,l++)).subscribe(z(n,function(t){n.next(t)},function(){o=!0},void 0,function(){if(o)try{s--;for(var t=function(){var t=c.shift();u||h(t)};c.length&&s<e;)t();f()}catch(t){n.error(t)}}))};return t.subscribe(z(n,function(t){return s<e?h(t):c.push(t)},function(){a=!0,f()})),function(){}}(n,e,t,r)}))}function wt(t){return void 0===t&&(t=1/0),yt(T,t)}function mt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return wt(1)(dt(t,H(t)))}function _t(t){return new C(function(n){ct(t()).subscribe(n)})}function xt(t,n,r){void 0===t&&(t=0),void 0===r&&(r=Z);var e=-1;return null!=n&&(K(n)?r=n:e=n),new C(function(n){var o,i=(o=t)instanceof Date&&!isNaN(o)?+t-r.now():t;i<0&&(i=0);var u=0;return r.schedule(function(){n.closed||(n.next(u++),0<=e?this.schedule(void 0,e):n.complete())},i)})}function gt(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=H(t),e=function(t,n){return"number"==typeof L(t)?t.pop():n}(t,1/0),o=t;return o.length?1===o.length?ct(o[0]):wt(e)(dt(o,r)):G}function St(t,n){return k(function(r,e){var o=0;r.subscribe(z(e,function(r){return t.call(n,r,o++)&&e.next(r)}))})}function Ot(t){return k(function(n,r){var e,o=null,i=!1;o=n.subscribe(z(r,void 0,void 0,function(u){e=ct(t(u,Ot(t)(n))),o?(o.unsubscribe(),o=null,e.subscribe(r)):i=!0})),i&&(o.unsubscribe(),o=null,e.subscribe(r))})}function Et(t,n){return a(n)?yt(t,n,1):yt(t,1)}function It(t,n){return yt(function(n,r){return ct(t(n,r)).pipe((e=1)<=0?function(){return G}:k(function(t,n){var r=0;t.subscribe(z(n,function(t){++r<=e&&(n.next(t),e<=r&&n.complete())}))}),function(t){return bt(function(){return t})}(n));var e})}function At(t,n){void 0===n&&(n=q);var r=xt(t,n);return It(function(){return r})}function Pt(t,n){return t===n}function Tt(t,n){return n?function(r){return r.pipe(Tt(function(r,e){return ct(t(r,e)).pipe(bt(function(t,o){return n(r,t,e,o)}))}))}:k(function(n,r){var e=0,o=null,i=!1;n.subscribe(z(r,function(n){o||(o=z(r,void 0,function(){o=null,i&&r.complete()}),ct(t(n,e++)).subscribe(o))},function(){i=!0,!o&&r.complete()}))})}function Ct(t,n){return k(function(t,n,r,e,o){return function(e,i){var u=r,c=n,s=0;e.subscribe(z(i,function(n){var r=s++;c=u?t(c,n,r):(u=!0,n),i.next(c)},o))}}(t,n,arguments.length>=2))}function jt(t,n){for(var r=[],e=2;e<arguments.length;e++)r[e-2]=arguments[e];if(!0!==n){if(!1!==n){var o=new E({next:function(){o.unsubscribe(),t()}});return ct(n.apply(void 0,u([],i(r)))).subscribe(o)}}else t()}function kt(t,n,r){var e;return e=t,function(t){void 0===t&&(t={});var n=t.connector,r=void 0===n?function(){return new N}:n,e=t.resetOnError,o=void 0===e||e,i=t.resetOnComplete,u=void 0===i||i,c=t.resetOnRefCountZero,s=void 0===c||c;return function(t){var n,e,i,c=0,l=!1,a=!1,f=function(){null==e||e.unsubscribe(),e=void 0},h=function(){f(),n=i=void 0,l=a=!1},p=function(){var t=n;h(),null==t||t.unsubscribe()};return k(function(t,d){c++,a||l||f();var v=i=null!=i?i:r();d.add(function(){0!==--c||a||l||(e=jt(p,s))}),v.subscribe(d),!n&&c>0&&(n=new E({next:function(t){return v.next(t)},error:function(t){a=!0,f(),e=jt(h,o,t),v.error(t)},complete:function(){l=!0,f(),e=jt(h,u),v.complete()}}),ct(t).subscribe(n))})(t)}}({connector:function(){return new W(e,n,r)},resetOnError:!0,resetOnComplete:!1,resetOnRefCountZero:!1})}function zt(t,n){return k(function(r,e){var o=null,i=0,u=!1,c=function(){return u&&!o&&e.complete()};r.subscribe(z(e,function(r){null==o||o.unsubscribe();var u=0,s=i++;ct(t(r,s)).subscribe(o=z(e,function(t){return e.next(n?n(r,t,s,u++):t)},function(){o=null,c()}))},function(){u=!0,c()}))})}function Ft(t,n,r){var e=a(t)||n||r?{next:t,error:n,complete:r}:t;return e?k(function(t,n){var r;null===(r=e.subscribe)||void 0===r||r.call(e);var o=!0;t.subscribe(z(n,function(t){var r;null===(r=e.next)||void 0===r||r.call(e,t),n.next(t)},function(){var t;o=!1,null===(t=e.complete)||void 0===t||t.call(e),n.complete()},function(t){var r;o=!1,null===(r=e.error)||void 0===r||r.call(e,t),n.error(t)},function(){var t,n;o&&(null===(t=e.unsubscribe)||void 0===t||t.call(e)),null===(n=e.finalize)||void 0===n||n.call(e)}))}):T}class $t{_state$;_actions$=new N;_reducers=[];constructor(t={}){const n="function"==typeof structuredClone?structuredClone(t):JSON.parse(JSON.stringify(t));this._state$=new J(n);const r=this._actions$.pipe(Ft(t=>console.log("Action Dispatched:",t))).pipe(Ct((t,n)=>{const r=JSON.parse(JSON.stringify(t));return this._reducers.forEach(({path:t,reducerFn:e})=>{const o=r[t],i=e(o,n);void 0!==i&&o!==i&&(r[t]=i)}),r},n),function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=H(t);return k(function(n,e){(r?mt(t,n,r):mt(t,n)).subscribe(e)})}(t),kt(1));r.subscribe(this._state$)}registerReducers(...t){this._reducers.push(...t);const n=this._state$.getValue(),r=JSON.parse(JSON.stringify(n));t.forEach(({path:t,initialState:n})=>{void 0===r[t]&&(r[t]=n)}),this._state$.next(r)}registerEffects(...t){gt(...t.map(t=>t(this._actions$))).subscribe(t=>this.dispatch(t))}dispatch(t){this._actions$.next(t)}select(t){return this._state$.pipe(bt(n=>t(n)),(void 0===r&&(r=T),n=null!=n?n:Pt,k(function(t,e){var o,i=!0;t.subscribe(z(e,function(t){var u=r(t);!i&&n(o,u)||(i=!1,o=u,e.next(t))}))})));var n,r}}function Nt(t){const n=n=>({type:t,payload:n});return n.type=t,n}function Rt(){}function Jt(...t){const n=t.pop(),r=t,e=r.includes(Rt);if(e&&r.length>1)throw new Error("The `anyAction` token cannot be mixed with other action creators in a single `on` handler.");return{types:r.map(t=>t.type),reducerFn:n,isCatchAll:e}}function Ut(t,n,...r){if(!t||"string"!=typeof t)throw new Error("Reducer featureKey must be a non-empty string.");const e=r.filter(t=>!t.isCatchAll),o=r.find(t=>t.isCatchAll);return{path:t,initialState:n,reducerFn:(t=n,r)=>{for(const n of e)if(n.types.includes(r.type))return n.reducerFn(t,r);return o?o.reducerFn(t,r):t}}}function Wt(...t){const n=t.map(t=>t.type);return St(t=>n.includes(t.type))}function Mt(t){if("function"!=typeof t)throw new Error("Effect must be a function.");return t}function Yt(t,n){return r=>{const e=r[t];return n?n(e):e}}function Bt(...t){const n=t.pop(),r=t;if("function"!=typeof n)throw new Error("The last argument to createSelector must be a projection function.");return t=>{const e=r.map(n=>n(t));return n(...e)}}export{$t as Store,Rt as anyAction,Ot as catchError,Et as concatMap,Nt as createAction,Mt as createEffect,Yt as createFeatureSelector,Ut as createReducer,Bt as createSelector,_t as defer,At as delay,Tt as exhaustMap,St as filter,dt as from,bt as map,yt as mergeMap,vt as of,Wt as ofType,Jt as on,zt as switchMap,Ft as tap};
@@ -59,4 +59,4 @@ function storePlugin(instance, store) {
59
59
  };
60
60
  }
61
61
 
62
- export { storePlugin };
62
+ export { storePlugin };
@@ -0,0 +1 @@
1
+ function s(s,i){return i?{dispatch:i.dispatch.bind(i),subscribe(s,t){this._subscriptions||(this._subscriptions=[]);const r=i.select(s).subscribe(t);return this._subscriptions.push(r),r},onDestroy(){this._subscriptions&&this._subscriptions.length>0&&(this._subscriptions.forEach(s=>s.unsubscribe()),this._subscriptions=[])}}:(console.error("[rx-tiny-flux] StorePlugin Error: Store instance was not provided on .use()"),{})}export{s as storePlugin};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rx-tiny-flux",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A lightweight, minimalist state management library for pure JavaScript projects, inspired by NgRx and Redux, and built with RxJS.",
5
5
  "author": "Bernardo Baumblatt <baumblatt@gmail.com>",
6
6
  "license": "MIT",
@@ -1,132 +0,0 @@
1
- import {
2
- Store,
3
- createAction,
4
- createReducer,
5
- createEffect,
6
- on,
7
- anyAction,
8
- createFeatureSelector,
9
- createSelector,
10
- ofType,
11
- concatMap,
12
- from,
13
- map,
14
- } from '../dist/rx-tiny-flux.esm.js'; // Pointing to the built file for a realistic test
15
-
16
- // 1. ESTADO INICIAL
17
- // The Store can start with an empty state.
18
- const initialState = {};
19
-
20
- // 2. AÇÕES
21
- // We create "messages" that describe events in the application.
22
- const increment = createAction('[Counter] Increment');
23
- const decrement = createAction('[Counter] Decrement');
24
- const incrementAsync = createAction('[Counter] Increment Async');
25
- const incrementSuccess = createAction('[Counter] Increment Success');
26
-
27
- // 3. REDUTORES
28
- // Pure functions that calculate the new state based on the previous state and an action.
29
-
30
- // This reducer manages the 'counter' slice of the state.
31
- const counterReducer = createReducer(
32
- 'counter',
33
- { value: 0, lastUpdate: null }, // 1. Initial state for this slice.
34
- on(increment, incrementSuccess, (state) => ({
35
- ...state,
36
- value: state.value + 1,
37
- lastUpdate: new Date().toISOString(),
38
- })),
39
- on(decrement, (state) => ({
40
- ...state,
41
- value: state.value - 1,
42
- lastUpdate: new Date().toISOString(),
43
- }))
44
- );
45
-
46
- // This reducer manages the 'log' slice. It reacts to ANY action.
47
- const logReducer = createReducer(
48
- 'log',
49
- [], // Initial state for this slice
50
- // Using the `anyAction` token to create a handler that catches all actions.
51
- on(anyAction, (state, action) => [...state, `Action: ${action.type} at ${new Date().toISOString()}`])
52
- );
53
-
54
- // 4. EFEITOS
55
- // Handle side effects, such as asynchronous calls.
56
-
57
- // Let's create a function that simulates an API call returning a Promise.
58
- const fakeApiCall = () => {
59
- console.log('-> [Effect] Starting fake API call...');
60
- return new Promise((resolve) => {
61
- setTimeout(() => {
62
- console.log('<- [Effect] Fake API call finished.');
63
- resolve({ success: true }); // The API returns a success object
64
- }, 1000);
65
- });
66
- };
67
-
68
- const incrementAsyncEffect = createEffect((actions$) =>
69
- actions$.pipe(
70
- ofType(incrementAsync), // Listens only for the 'incrementAsync' action
71
- // Use concatMap to handle the async operation. It waits for the inner Observable to complete.
72
- concatMap(() => from(fakeApiCall()).pipe( // `from` converts the Promise into an Observable
73
- map(() => incrementSuccess()) // On success, map the result to a new action
74
- ))
75
- )
76
- );
77
-
78
- // 5. SELETORES
79
- // Functions to extract specific pieces of state.
80
-
81
- // 5.1. We use `createFeatureSelector` to get a top-level slice of the state.
82
- const selectCounterSlice = createFeatureSelector('counter');
83
-
84
- // 5.2. We use `createSelector` to compose and extract more granular data from the slice.
85
- const selectCounterValue = createSelector(
86
- selectCounterSlice,
87
- (counter) => counter?.value // Added 'optional chaining' for safety
88
- );
89
-
90
- const selectLastUpdate = createSelector(
91
- selectCounterSlice,
92
- (counter) => counter?.lastUpdate
93
- );
94
-
95
- // 6. STORE SETUP
96
- const store = new Store(initialState);
97
- store.registerReducers(counterReducer, logReducer);
98
- store.registerEffects(incrementAsyncEffect);
99
-
100
- // 7. USING THE STORE
101
- // We subscribe to the selector to observe changes in the counter's value.
102
- // It's crucial to capture the subscription object so we can unsubscribe later.
103
- const counterSubscription = store.select(selectCounterValue).subscribe((value) => {
104
- console.log(`Counter value is now: ${value}`);
105
- });
106
-
107
- // Let's also subscribe to the log to see all actions
108
- const logSubscription = store.select((state) => state.log).subscribe((log) => {
109
- console.log('--- Action Log ---');
110
- console.log(log.join('\n'));
111
- });
112
-
113
- // 8. DISPATCHING ACTIONS
114
- console.log('Dispatching actions...');
115
- store.dispatch(increment());
116
- store.dispatch(increment());
117
- store.dispatch(incrementAsync()); // Will trigger the effect and update the counter after 1s.
118
-
119
- // 9. CLEANUP (Unsubscribing)
120
- // In a real application (like a component in a UI framework or a long-running service),
121
- // you must unsubscribe from subscriptions to prevent memory leaks when they are no longer needed.
122
- // In this simple script, the process would exit anyway, but we demonstrate the practice here
123
- // by unsubscribing after a few seconds.
124
- setTimeout(() => {
125
- console.log('\n--- Cleaning up subscriptions ---');
126
- counterSubscription.unsubscribe();
127
- logSubscription.unsubscribe();
128
- console.log('Subscriptions cleaned up. Further state changes will not be logged to the console.');
129
-
130
- // This action will still be processed by the store, but our subscriptions won't react to it.
131
- store.dispatch(increment());
132
- }, 2000);
package/rollup.config.js DELETED
@@ -1,43 +0,0 @@
1
- import { nodeResolve } from '@rollup/plugin-node-resolve';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import terser from '@rollup/plugin-terser';
4
- import json from '@rollup/plugin-json';
5
-
6
- export default [
7
- // Main library bundle
8
- {
9
- input: 'src/index.js',
10
- output: [
11
- {
12
- file: 'dist/rx-tiny-flux.esm.js',
13
- format: 'es',
14
- sourcemap: false,
15
- },
16
- {
17
- file: 'dist/rx-tiny-flux.esm.min.js',
18
- format: 'es',
19
- sourcemap: false,
20
- plugins: [terser()],
21
- },
22
- ],
23
- plugins: [json(), nodeResolve(), commonjs()],
24
- },
25
- // Third entry point for ZeppOS plugin
26
- {
27
- input: 'src/zeppos.js',
28
- output: [
29
- {
30
- file: 'dist/zeppos.esm.js',
31
- format: 'es',
32
- sourcemap: false,
33
- },
34
- {
35
- file: 'dist/zeppos.esm.min.js',
36
- format: 'es',
37
- sourcemap: false,
38
- plugins: [terser()],
39
- },
40
- ],
41
- plugins: [json(), nodeResolve(), commonjs()],
42
- },
43
- ];
package/src/actions.js DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * @typedef {Object} Action
3
- * @property {string} type - The action type, a unique string describing it.
4
- * @property {any} [payload] - The data associated with the action.
5
- */
6
-
7
- /**
8
- * Factory function to create an action.
9
- * @param {string} type - The action type.
10
- * @returns {function(any=): Action} A function that creates the action with an optional payload.
11
- */
12
- export function createAction(type) {
13
- const actionCreator = (payload) => ({ type, payload });
14
- actionCreator.type = type; // Attaches the type directly to the function for easy access
15
- return actionCreator;
16
- }
package/src/effects.js DELETED
@@ -1,33 +0,0 @@
1
- import { filter } from 'rxjs';
2
-
3
- /**
4
- * @typedef {import('./actions').Action} Action
5
- * @typedef {import('rxjs').Observable<Action>} ActionStream
6
- */
7
-
8
- /**
9
- * Custom RxJS operator to filter actions by type.
10
- * @param {...(function(any=): Action)} actionCreators - The action creators whose types will be used for filtering.
11
- * @returns {import('rxjs').OperatorFunction<Action, Action>}
12
- */
13
- export function ofType(...actionCreators) {
14
- // Extracts the 'type' string from each action creator passed as an argument.
15
- const allowedTypes = actionCreators.map(creator => creator.type);
16
-
17
- return filter(action => allowedTypes.includes(action.type));
18
- }
19
-
20
- /**
21
- * Factory function to create an effect.
22
- * An effect is a function that receives the stream of all actions
23
- * and returns a new stream of actions to be dispatched.
24
- *
25
- * @param {function(ActionStream): ActionStream} effectFn
26
- * @returns {function(ActionStream): ActionStream} The effect function.
27
- */
28
- export function createEffect(effectFn) {
29
- if (typeof effectFn !== 'function') {
30
- throw new Error('Effect must be a function.');
31
- }
32
- return effectFn;
33
- }
package/src/index.js DELETED
@@ -1,8 +0,0 @@
1
- export { Store } from './store.js';
2
- export { createAction } from './actions.js';
3
- export { createReducer, on, anyAction } from './reducers.js';
4
- export { createEffect, ofType } from './effects.js';
5
- export { createSelector, createFeatureSelector } from './selectors.js';
6
-
7
- // Re-export RxJS operators from the main entry point
8
- export * from './rxjs.js';
package/src/reducers.js DELETED
@@ -1,67 +0,0 @@
1
- /**
2
- * @typedef {import('./actions').Action} Action
3
- */
4
-
5
- /**
6
- * A token to be used with `on` to catch any action.
7
- */
8
- export function anyAction() {}
9
-
10
- /**
11
- * Associates one or more action creators with a reducer function.
12
- * @param {...(function|function(any, Action): any)} args - A list of action creators, followed by the reducer function.
13
- * @returns {{ types: string[], reducerFn: function(any, Action): any }}
14
- */
15
- export function on(...args) {
16
- // The last argument is the reducer function.
17
- const reducerFn = args.pop();
18
- // All previous arguments are the action creators.
19
- const actionCreators = args;
20
-
21
- // Checks if the `anyAction` token was used.
22
- const isCatchAll = actionCreators.includes(anyAction);
23
- if (isCatchAll && actionCreators.length > 1) {
24
- throw new Error('The `anyAction` token cannot be mixed with other action creators in a single `on` handler.');
25
- }
26
-
27
- const types = actionCreators.map(creator => creator.type);
28
- return { types, reducerFn, isCatchAll };
29
- }
30
-
31
- /**
32
- * Factory function to create a reducer.
33
- * A reducer is associated with a key that defines which top-level property of the state it manages.
34
- *
35
- * @param {string} featureKey - The key for the state slice this reducer manages.
36
- * @param {any} initialState - The initial state for this state slice.
37
- * @param {...{ types: string[], reducerFn: function(any, Action): any }} ons - A list of handlers created with the `on` function.
38
- * @returns {{path: string, initialState: any, reducerFn: function(any, Action): any}} The reducer object.
39
- */
40
- export function createReducer(featureKey, initialState, ...ons) {
41
- if (!featureKey || typeof featureKey !== 'string') {
42
- throw new Error('Reducer featureKey must be a non-empty string.');
43
- }
44
-
45
- // Separates specific handlers from generic (catch-all) ones.
46
- const specificHandlers = ons.filter(o => !o.isCatchAll);
47
- const catchAllHandler = ons.find(o => o.isCatchAll);
48
-
49
- const reducerFn = (state = initialState, action) => {
50
- // First, try to find a specific 'on' handler for the action.
51
- for (const handler of specificHandlers) {
52
- if (handler.types.includes(action.type)) {
53
- return handler.reducerFn(state, action);
54
- }
55
- }
56
-
57
- // If no specific handler matches, execute the 'any' handler, if it exists.
58
- if (catchAllHandler) {
59
- return catchAllHandler.reducerFn(state, action);
60
- }
61
-
62
- // If nothing matches, return the state unchanged.
63
- return state;
64
- };
65
-
66
- return { path: featureKey, initialState, reducerFn };
67
- }
package/src/rxjs.js DELETED
@@ -1,20 +0,0 @@
1
- // This file acts as a secondary entry point for re-exporting
2
- // a curated set of RxJS functionalities. This allows consumers
3
- // of the library to import them via `rx-tiny-flux/rxjs`.
4
-
5
- export {
6
- // Operators
7
- map,
8
- concatMap,
9
- switchMap,
10
- exhaustMap,
11
- mergeMap,
12
- delay,
13
- filter,
14
- tap,
15
- catchError,
16
- // Creation Functions
17
- defer,
18
- from,
19
- of,
20
- } from 'rxjs';
package/src/selectors.js DELETED
@@ -1,39 +0,0 @@
1
- /**
2
- * Creates a selector function that extracts a top-level state slice (feature) using a key.
3
- * It is analogous to NgRx's `createFeatureSelector`.
4
- *
5
- * @param {string} featureKey - The key for the top-level feature in the state object.
6
- * @param {function(any): any} [projectionFn] - An optional function to transform the selected value.
7
- * @returns {function(object): any} A function that receives the complete state and returns the selected part.
8
- */
9
- export function createFeatureSelector(featureKey, projectionFn) {
10
- return (state) => {
11
- const selectedValue = state[featureKey];
12
- // If a projection function was provided, apply it to the value. Otherwise, return the value directly.
13
- return projectionFn ? projectionFn(selectedValue) : selectedValue;
14
- };
15
- }
16
-
17
- /**
18
- * Creates a selector function that can compose multiple selectors, whose results
19
- * are passed as arguments to a final projection function.
20
- * It is analogous to NgRx's `createSelector`.
21
- *
22
- * @param {...Function} args - A list of input selector functions, followed by a projection function.
23
- * @returns {function(object): any} The final composed selector function.
24
- */
25
- export function createSelector(...args) {
26
- // The last argument is always the projection function.
27
- const projectionFn = args.pop();
28
- // All previous arguments are the input selectors.
29
- const inputSelectors = args;
30
-
31
- if (typeof projectionFn !== 'function') {
32
- throw new Error('The last argument to createSelector must be a projection function.');
33
- }
34
-
35
- return (state) => {
36
- const inputs = inputSelectors.map(selector => selector(state));
37
- return projectionFn(...inputs);
38
- }
39
- }
package/src/store.js DELETED
@@ -1,125 +0,0 @@
1
- import { BehaviorSubject, Subject, merge } from 'rxjs';
2
- import { scan, shareReplay, startWith, tap, distinctUntilChanged, map } from 'rxjs/operators';
3
-
4
- /**
5
- * @typedef {import('./actions').Action} Action
6
- */
7
-
8
- export class Store {
9
- /**
10
- * @private
11
- * @type {BehaviorSubject<object>}
12
- */
13
- _state$;
14
-
15
- /**
16
- * @private
17
- * @type {Subject<Action>}
18
- */
19
- _actions$ = new Subject();
20
-
21
- /**
22
- * @private
23
- * @type {Array<{path: string, initialState: any, reducerFn: function(any, Action): any}>}
24
- */
25
- _reducers = [];
26
-
27
- /**
28
- * @param {object} initialState - The initial state of the application.
29
- */
30
- constructor(initialState = {}) {
31
- // The initial state is now deep-cloned to prevent external mutations.
32
- // `structuredClone` is modern and ideal, but `JSON.parse` is a safe fallback.
33
- const initialStoreState = typeof structuredClone === 'function' ? structuredClone(initialState) : JSON.parse(JSON.stringify(initialState));
34
- this._state$ = new BehaviorSubject(initialStoreState);
35
-
36
- const dispatcher$ = this._actions$.pipe(
37
- // Optional: log for debugging
38
- tap((action) => console.log('Action Dispatched:', action))
39
- );
40
-
41
- const state$ = dispatcher$.pipe(
42
- scan((currentState, action) => {
43
- // Clones the state to ensure immutability.
44
- // For larger apps, a library like `lodash.cloneDeep` would be more robust.
45
- const nextState = JSON.parse(JSON.stringify(currentState));
46
-
47
- this._reducers.forEach(({ path: featureKey, reducerFn }) => {
48
- // Gets the current state slice.
49
- const stateSlice = nextState[featureKey];
50
-
51
- // Executes the reducer to get the new slice.
52
- const nextStateSlice = reducerFn(stateSlice, action);
53
-
54
- // If the reducer returned a new value (not undefined) and it's different from the previous one,
55
- // apply the change to the state object.
56
- if (nextStateSlice !== undefined && stateSlice !== nextStateSlice) {
57
- // Directly assign the new slice to the corresponding key in the state.
58
- nextState[featureKey] = nextStateSlice;
59
- }
60
- });
61
-
62
- return nextState;
63
- }, initialStoreState),
64
- startWith(initialState),
65
- // Ensures new subscribers receive the last emitted state and shares the execution.
66
- shareReplay(1)
67
- );
68
-
69
- // Connects the calculated state stream back to our main BehaviorSubject.
70
- state$.subscribe(this._state$);
71
- }
72
-
73
- /**
74
- * Registers reducers in the store.
75
- * @param {...{path: string, initialState: any, reducerFn: function(any, Action): any}} reducers
76
- */
77
- registerReducers(...reducers) {
78
- this._reducers.push(...reducers);
79
-
80
- // Builds the initial state from the registered reducers
81
- const currentState = this._state$.getValue();
82
- const nextState = JSON.parse(JSON.stringify(currentState));
83
-
84
- reducers.forEach(({ path: featureKey, initialState }) => {
85
- // If the state slice has not been defined yet, apply the reducer's initial state.
86
- if (nextState[featureKey] === undefined) {
87
- nextState[featureKey] = initialState;
88
- }
89
- });
90
-
91
- // Emits the new constructed state
92
- this._state$.next(nextState);
93
- }
94
-
95
- /**
96
- * Registers effects in the store.
97
- * @param {...function(import('rxjs').Observable<Action>): import('rxjs').Observable<Action>} effects
98
- */
99
- registerEffects(...effects) {
100
- const effectStreams = effects.map((effect) => effect(this._actions$));
101
- // Merges all action streams returned by the effects and dispatches them back into the store.
102
- merge(...effectStreams).subscribe((action) => this.dispatch(action));
103
- }
104
-
105
- /**
106
- * Dispatches an action to the store, initiating the state update cycle.
107
- * @param {Action} action
108
- */
109
- dispatch(action) {
110
- this._actions$.next(action);
111
- }
112
-
113
- /**
114
- * Selects a slice of the state and returns it as an Observable.
115
- * @param {function(object): any} selectorFn - The selector function.
116
- * @returns {import('rxjs').Observable<any>}
117
- */
118
- select(selectorFn) {
119
- return this._state$.pipe(
120
- map(state => selectorFn(state)),
121
- // Emits only when the selected value has actually changed.
122
- distinctUntilChanged()
123
- );
124
- }
125
- }
package/src/utils.js DELETED
@@ -1,25 +0,0 @@
1
- import jsonpath from 'jsonpath';
2
-
3
- /**
4
- * Sets a value in an object using a jsonpath expression,
5
- * creating the nested path if it doesn't exist.
6
- * This function modifies the input object.
7
- *
8
- * @param {object} obj The object to be modified.
9
- * @param {string} path The jsonpath expression.
10
- * @param {any} value The value to be set.
11
- */
12
- export function setValueByPath(obj, path, value) {
13
- // Tries to set the value. If the path doesn't exist, the `value` function with 3 arguments returns undefined.
14
- if (jsonpath.value(obj, path, value) === undefined) {
15
- const pathComponents = jsonpath.parse(path);
16
- // Removes the last component to get the "parent" path.
17
- pathComponents.pop();
18
- const parentPath = jsonpath.stringify(pathComponents);
19
-
20
- // Recursively calls the function to ensure the parent path exists,
21
- // setting it as an empty object before trying to set the final value.
22
- setValueByPath(obj, parentPath, {});
23
- jsonpath.value(obj, path, value);
24
- }
25
- }