redux-saga-watch-actions
Version:
Easily create watchers to map actions to sagas
2 lines (1 loc) • 8.36 kB
JavaScript
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("redux-saga/effects")):"function"==typeof define&&define.amd?define(["exports","redux-saga/effects"],r):r((t=t||self).ReduxSagaWatchActions={},t.ReduxSaga.effects)}(this,function(t,r){"use strict";function e(t){return function(t){if(Array.isArray(t)){for(var r=0,e=Array(t.length);t.length>r;r++)e[r]=t[r];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}var n=function(t,r){return t(r={exports:{}},r.exports),r.exports}(function(t){var r=function(t){var r,e=Object.prototype,n=e.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,r,e,n){var o=Object.create((r&&r.prototype instanceof v?r:v).prototype),i=new A(n||[]);return o._invoke=function(t,r,e){var n=s;return function(o,i){if(n===l)throw Error("Generator is already running");if(n===p){if("throw"===o)throw i;return S()}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var c=k(a,e);if(c){if(c===y)continue;return c}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if(n===s)throw n=p,e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n=l;var u=f(t,r,e);if("normal"===u.type){if(n=e.done?p:h,u.arg===y)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n=p,e.method="throw",e.arg=u.arg)}}}(t,e,i),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var s="suspendedStart",h="suspendedYield",l="executing",p="completed",y={};function v(){}function d(){}function g(){}var m={};m[i]=function(){return this};var w=Object.getPrototypeOf,x=w&&w(w(O([])));x&&x!==e&&n.call(x,i)&&(m=x);var L=g.prototype=v.prototype=Object.create(m);function b(t){["next","throw","return"].forEach(function(r){t[r]=function(t){return this._invoke(r,t)}})}function E(t){var r;this._invoke=function(e,o){function i(){return new Promise(function(r,i){!function r(e,o,i,a){var c=f(t[e],t,o);if("throw"!==c.type){var u=c.arg,s=u.value;return s&&"object"==typeof s&&n.call(s,"__await")?Promise.resolve(s.__await).then(function(t){r("next",t,i,a)},function(t){r("throw",t,i,a)}):Promise.resolve(s).then(function(t){u.value=t,i(u)},function(t){return r("throw",t,i,a)})}a(c.arg)}(e,o,r,i)})}return r=r?r.then(i,i):i()}}function k(t,e){var n=t.iterator[e.method];if(n===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=r,k(t,e),"throw"===e.method))return y;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=f(n,t.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,y;var i=o.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=r),e.delegate=null,y):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function _(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function j(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function O(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function e(){for(;++o<t.length;)if(n.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=r,e.done=!0,e};return a.next=a}}return{next:S}}function S(){return{value:r,done:!0}}return d.prototype=L.constructor=g,g.constructor=d,g[c]=d.displayName="GeneratorFunction",t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===d||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,c in t||(t[c]="GeneratorFunction")),t.prototype=Object.create(L),t},t.awrap=function(t){return{__await:t}},b(E.prototype),E.prototype[a]=function(){return this},t.AsyncIterator=E,t.async=function(r,e,n,o){var i=new E(u(r,e,n,o));return t.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},b(L),L[c]="Generator",L[i]=function(){return this},L.toString=function(){return"[object Generator]"},t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=r,this.done=!1,this.delegate=null,this.method="next",this.arg=r,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=r)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function o(n,o){return c.type="throw",c.arg=t,e.next=n,o&&(e.method="next",e.arg=r),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(this.prev>=a.tryLoc){var u=n.call(a,"catchLoc"),f=n.call(a,"finallyLoc");if(u&&f){if(a.catchLoc>this.prev)return o(a.catchLoc,!0);if(a.finallyLoc>this.prev)return o(a.finallyLoc)}else if(u){if(a.catchLoc>this.prev)return o(a.catchLoc,!0)}else{if(!f)throw Error("try statement without catch or finally");if(a.finallyLoc>this.prev)return o(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(this.prev>=o.tryLoc&&n.call(o,"finallyLoc")&&o.finallyLoc>this.prev){var i=o;break}}!i||"break"!==t&&"continue"!==t||i.tryLoc>r||r>i.finallyLoc||(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),j(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;j(e)}return o}}throw Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:O(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=r),y}},t}(t.exports);try{regeneratorRuntime=r}catch(t){Function("r","regeneratorRuntime = r")(r)}}),o=function(t,e){return n.mark(function o(){var i,a,c,u=arguments;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:for(a=Array(i=u.length),c=0;i>c;c++)a[c]=u[c];return n.next=3,r.takeEvery.apply(void 0,[t,e].concat(a));case 3:case"end":return n.stop()}},o)})};t.combineSagas=function(){for(var t=arguments.length,e=Array(t),o=0;t>o;o++)e[o]=arguments[o];return n.mark(function t(){var o,i,a,c=arguments;return n.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:for(i=Array(o=c.length),a=0;o>a;a++)i[a]=c[a];return t.next=3,r.all(e.map(function(t){return r.fork.apply(void 0,[t].concat(i))}));case 3:case"end":return t.stop()}},t)})},t.createWatcher=o,t.watchActions=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return n.mark(function e(){var i,a,c,u=arguments;return n.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:for(a=Array(i=u.length),c=0;i>c;c++)a[c]=u[c];return e.next=3,r.all(Object.keys(t).map(function(r){return o(r,t[r]).apply(void 0,a)}));case 3:case"end":return e.stop()}},e)})},t.watchNextAction=function(t,o){return n.mark(function i(){var a,c,u,f,s=arguments;return n.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,r.take(t);case 2:if(a=n.sent,"function"!=typeof o){n.next=7;break}for(u=Array(c=s.length),f=0;c>f;f++)u[f]=s[f];return n.next=7,r.fork.apply(void 0,[o].concat(e(u.concat(a))));case 7:case"end":return n.stop()}},i)})},Object.defineProperty(t,"__esModule",{value:!0})});