redux-saga
Advanced tools
Comparing version 0.11.0 to 0.11.1
@@ -321,2 +321,5 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
}; | ||
var kReturn = function kReturn(value) { | ||
return { value: value, done: true }; | ||
}; | ||
function makeIterator(next) { | ||
@@ -326,3 +329,3 @@ var thro = arguments.length <= 1 || arguments[1] === undefined ? kThrow : arguments[1]; | ||
var iterator = { name: name, next: next, throw: thro }; | ||
var iterator = { name: name, next: next, throw: thro, return: kReturn }; | ||
if (typeof Symbol !== 'undefined') { | ||
@@ -510,2 +513,6 @@ iterator[Symbol.iterator] = function () { | ||
if (!_utils.is.func(unsubscribe)) { | ||
throw new Error('in eventChannel: subscribe should return a function to unsubscribe'); | ||
} | ||
return { | ||
@@ -797,17 +804,19 @@ take: chan.take, | ||
/** | ||
TODO: Need to make a more optimized implementation: e.g. Ring buffers, linked lists with Node Object pooling... | ||
**/ | ||
function arrBuffer() { | ||
var limit = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0]; | ||
function ringBuffer() { | ||
var limit = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0]; | ||
var overflowAction = arguments[1]; | ||
var arr = []; | ||
var arr = new Array(limit); | ||
var length = 0; | ||
var pushIndex = 0; | ||
var popIndex = 0; | ||
return { | ||
isEmpty: function isEmpty() { | ||
return !arr.length; | ||
return length == 0; | ||
}, | ||
put: function put(it) { | ||
if (arr.length < limit) { | ||
arr.push(it); | ||
if (length < limit) { | ||
arr[pushIndex] = it; | ||
pushIndex = (pushIndex + 1) % limit; | ||
length++; | ||
} else { | ||
@@ -818,4 +827,5 @@ switch (overflowAction) { | ||
case ON_OVERFLOW_SLIDE: | ||
arr.shift(); | ||
arr.push(it); | ||
arr[pushIndex] = it; | ||
pushIndex = (pushIndex + 1) % limit; | ||
popIndex = pushIndex; | ||
break; | ||
@@ -828,3 +838,9 @@ default: | ||
take: function take() { | ||
return arr.shift(); | ||
if (length != 0) { | ||
var it = arr[popIndex]; | ||
arr[popIndex] = null; | ||
length--; | ||
popIndex = (popIndex + 1) % limit; | ||
return it; | ||
} | ||
} | ||
@@ -839,9 +855,9 @@ }; | ||
fixed: function fixed(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_THROW); | ||
return ringBuffer(limit, ON_OVERFLOW_THROW); | ||
}, | ||
dropping: function dropping(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_DROP); | ||
return ringBuffer(limit, ON_OVERFLOW_DROP); | ||
}, | ||
sliding: function sliding(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_SLIDE); | ||
return ringBuffer(limit, ON_OVERFLOW_SLIDE); | ||
} | ||
@@ -946,2 +962,7 @@ }; | ||
function abort(err) { | ||
cancelAll(); | ||
cb(err, true); | ||
} | ||
function addTask(task) { | ||
@@ -957,4 +978,3 @@ tasks.push(task); | ||
if (isErr) { | ||
cancelAll(); | ||
cb(res, true); | ||
abort(res); | ||
} else { | ||
@@ -988,2 +1008,3 @@ if (task === mainTask) { | ||
cancelAll: cancelAll, | ||
abort: abort, | ||
getTasks: function getTasks() { | ||
@@ -1230,3 +1251,3 @@ return tasks; | ||
var data = void 0; | ||
return( | ||
return ( | ||
// Non declarative effect | ||
@@ -1345,11 +1366,7 @@ _utils.is.promise(effect) ? resolvePromise(effect, currCb) : _utils.is.iterator(effect) ? resolveIterator(effect, effectId, name, currCb) | ||
// catch synchronous failures; see #152 | ||
// catch synchronous failures; see #152 and #441 | ||
try { | ||
result = fn.apply(context, args); | ||
} catch (err) { | ||
if (!detached) { | ||
return cb(err); | ||
} else { | ||
error = err; | ||
} | ||
error = err; | ||
} | ||
@@ -1362,4 +1379,4 @@ | ||
// simple effect: wrap in a generator | ||
// do not bubble up synchronous failures for detached forks, instead create a failed task. See #152 | ||
// do not bubble up synchronous failures for detached forks | ||
// instead create a failed task. See #152 and #441 | ||
else { | ||
@@ -1387,10 +1404,14 @@ _iterator = error ? (0, _utils.makeIterator)(function () { | ||
var task = proc(_iterator, subscribe, dispatch, getState, options, effectId, fn.name, detached ? null : _utils.noop); | ||
if (!detached) { | ||
if (detached) { | ||
cb(task); | ||
} else { | ||
if (_iterator._isRunning) { | ||
taskQueue.addTask(task); | ||
cb(task); | ||
} else if (_iterator._error) { | ||
return cb(_iterator._error, true); | ||
taskQueue.abort(_iterator._error); | ||
} else { | ||
cb(task); | ||
} | ||
} | ||
cb(task); | ||
_asap2.default.flush(); | ||
@@ -1397,0 +1418,0 @@ // Fork effects are non cancellables |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ReduxSaga=e():n.ReduxSaga=e()}(this,function(){return function(n){function e(r){if(t[r])return t[r].exports;var u=t[r]={exports:{},id:r,loaded:!1};return n[r].call(u.exports,u,u.exports,e),u.loaded=!0,u.exports}var t={};return e.m=n,e.c=t,e.p="",e(0)}([function(n,e,t){"use strict";function r(n){if(n&&n.__esModule)return n;var e={};if(null!=n)for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e.default=n,e}function u(n){return n&&n.__esModule?n:{"default":n}}Object.defineProperty(e,"__esModule",{value:!0}),e.utils=e.effects=e.CANCEL=e.delay=e.takeLatest=e.takeEvery=e.buffers=e.channel=e.eventChannel=e.END=e.runSaga=void 0;var o=t(9);Object.defineProperty(e,"runSaga",{enumerable:!0,get:function(){return o.runSaga}});var a=t(2);Object.defineProperty(e,"END",{enumerable:!0,get:function(){return a.END}}),Object.defineProperty(e,"eventChannel",{enumerable:!0,get:function(){return a.eventChannel}}),Object.defineProperty(e,"channel",{enumerable:!0,get:function(){return a.channel}});var i=t(4);Object.defineProperty(e,"buffers",{enumerable:!0,get:function(){return i.buffers}});var c=t(10);Object.defineProperty(e,"takeEvery",{enumerable:!0,get:function(){return c.takeEvery}}),Object.defineProperty(e,"takeLatest",{enumerable:!0,get:function(){return c.takeLatest}});var f=t(1);Object.defineProperty(e,"delay",{enumerable:!0,get:function(){return f.delay}}),Object.defineProperty(e,"CANCEL",{enumerable:!0,get:function(){return f.CANCEL}});var l=t(8),s=u(l),d=t(6),p=r(d),v=t(11),g=r(v);e.default=s.default,e.effects=p,e.utils=g},function(n,e){"use strict";function t(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function r(n,e,t){if(!e(n))throw s("error","uncaught at check",t),new Error(t)}function u(n,e){var t=n.indexOf(e);t>=0&&n.splice(t,1)}function o(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=d({},n),t=new Promise(function(n,t){e.resolve=n,e.reject=t});return e.promise=t,e}function a(n){for(var e=[],t=0;n>t;t++)e.push(o());return e}function i(n){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1],t=void 0,r=new Promise(function(r){t=setTimeout(function(){return r(e)},n)});return r[h]=function(){return clearTimeout(t)},r}function c(){var n,e=!0,r=void 0,u=void 0;return n={},t(n,g,!0),t(n,"isRunning",function(){return e}),t(n,"result",function(){return r}),t(n,"error",function(){return u}),t(n,"setRunning",function(n){return e=n}),t(n,"setResult",function(n){return r=n}),t(n,"setError",function(n){return u=n}),n}function f(){var n=arguments.length<=0||void 0===arguments[0]?0:arguments[0];return function(){return++n}}function l(n){var e=arguments.length<=1||void 0===arguments[1]?m:arguments[1],t=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r={name:t,next:n,"throw":e};return"undefined"!=typeof Symbol&&(r[Symbol.iterator]=function(){return r}),r}function s(n,e,t){"undefined"==typeof window?console.log("redux-saga "+n+": "+e+"\n"+(t&&t.stack||t)):console[n].call(console,e,t)}Object.defineProperty(e,"__esModule",{value:!0});var d=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n};e.check=r,e.remove=u,e.deferred=o,e.arrayOfDeffered=a,e.delay=i,e.createMockTask=c,e.autoInc=f,e.makeIterator=l,e.log=s;var v=e.sym=function(n){return"@@redux-saga/"+n},g=e.TASK=v("TASK"),h=(e.MATCH=v("MATCH"),e.CANCEL=v("cancelPromise")),y=e.konst=function(n){return function(){return n}},b=(e.kTrue=y(!0),e.kFalse=y(!1),e.noop=function(){},e.ident=function(n){return n},e.is={undef:function(n){return null===n||void 0===n},notUndef:function(n){return null!==n&&void 0!==n},func:function(n){return"function"==typeof n},number:function(n){return"number"==typeof n},array:Array.isArray,promise:function(n){return n&&b.func(n.then)},iterator:function(n){return n&&b.func(n.next)&&b.func(n.throw)},task:function(n){return n&&n[g]},take:function(n){return n&&b.func(n.take)},put:function(n){return n&&b.func(n.put)},observable:function(n){return n&&b.func(n.subscribe)},buffer:function(n){return n&&b.func(n.isEmpty)&&b.func(n.take)&&b.func(n.put)},pattern:function(n){return n&&("string"==typeof n||"symbol"===("undefined"==typeof n?"undefined":p(n))||b.func(n)||b.array(n))}}),m=function(n){throw n};e.internalErr=function(n){return new Error("\n redux-saga: Error checking hooks detected an inconsisten state. This is likely a bug\n in redux-saga code and not yours. Thanks for reporting this in the project's github repo.\n Error: "+n+"\n")}},function(n,e,t){"use strict";function r(){function n(n){return t.push(n),function(){return(0,a.remove)(t,n)}}function e(n){for(var e=t.slice(),r=0,u=e.length;u>r;r++)e[r](n)}var t=[];return{subscribe:n,emit:e}}function u(n){function e(){if(o&&c.length)throw(0,a.internalErr)("Cannot have a closed channel with pending takers");if(c.length&&!n.isEmpty())throw(0,a.internalErr)("Cannot have pending takers with non empty buffer")}function t(t){if(e(),(0,a.check)(t,a.is.notUndef,d),!o)if(c.length)for(var r=0;r<c.length;r++){var u=c[r];if(!u[a.MATCH]||u[a.MATCH](t))return c.splice(r,1),u(t)}else n.put(t)}function r(t,r){e(),(0,a.check)(t,a.is.func,"channel.take's callback must be a function"),arguments.length>1&&((0,a.check)(r,a.is.func,"channel.take's matcher argument must be a function"),t[a.MATCH]=r),o&&n.isEmpty()?t(f):n.isEmpty()?(c.push(t),t.cancel=function(){return(0,a.remove)(c,t)}):t(n.take())}function u(){if(e(),!o&&(o=!0,c.length)){var n=c;c=[];for(var t=0,r=n.length;r>t;t++)n[t](f);c=[]}}var o=!1,c=[];return arguments.length>0?(0,a.check)(n,a.is.buffer,s):n=i.buffers.fixed(),{take:r,put:t,close:u,get __takers__(){return c},get __closed__(){return o}}}function o(n){var e=arguments.length<=1||void 0===arguments[1]?i.buffers.none():arguments[1],t=arguments[2];arguments.length>2&&(0,a.check)(t,a.is.func,"Invalid match function passed to eventChannel");var r=u(e),o=n(function(n){l(n)?r.close():t&&!t(n)||r.put(n)});return{take:r.take,close:function(){r.__closed__||(r.close(),o())}}}Object.defineProperty(e,"__esModule",{value:!0}),e.UNDEFINED_INPUT_ERROR=e.INVALID_BUFFER=e.isEnd=e.END=void 0,e.emitter=r,e.channel=u,e.eventChannel=o;var a=t(1),i=t(4),c="@@redux-saga/CHANNEL_END",f=e.END={type:c},l=e.isEnd=function(n){return n&&n.type===c},s=e.INVALID_BUFFER="invalid buffer passed to channel factory function",d=e.UNDEFINED_INPUT_ERROR="Saga was provided with an undefined action"},function(n,e,t){"use strict";function r(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function u(n,e){if(arguments.length>=2)(0,k.check)(n,k.is.notUndef,"take(channel, pattern): channel is undefined"),(0,k.check)(n,k.is.take,"take(channel, pattern): argument "+String(n)+" is not a valid channel (channel argument must have a take method)"),(0,k.check)(e,k.is.notUndef,"take(channel, pattern): pattern is undefined"),(0,k.check)(e,k.is.pattern,"take(channel, pattern): argument "+String(e)+" is not a valid pattern (pattern must be String | Function: a => boolean | Array<String>)");else if(1===arguments.length)if((0,k.check)(n,k.is.notUndef,"take(patternOrChannel): undefined argument"),k.is.take(n))e="*";else{if(!k.is.pattern(n))throw new Error("take(patternOrChannel): argument "+String(n)+" is not valid channel or a valid pattern");e=n,n=null}else e="*";return U(_,{channel:n,pattern:e})}function o(){var n=u.apply(void 0,arguments);return n[_].maybe=!0,n}function a(n,e){return arguments.length>1?((0,k.check)(n,k.is.notUndef,"put(channel, action): argument channel is undefined"),(0,k.check)(n,k.is.put,"put(channel, action): argument "+n+" is not a valid channel (channel argument must have a put method)"),(0,k.check)(e,k.is.notUndef,"put(channel, action): argument action is undefined")):((0,k.check)(n,k.is.notUndef,"put(action): argument action is undefined"),e=n,n=null),U(j,{channel:n,action:e})}function i(n){return U(O,n)}function c(n,e,t){(0,k.check)(e,k.is.notUndef,n+": argument fn is undefined");var r=null;if(k.is.array(e)){var u=e,o=m(u,2);r=o[0],e=o[1]}else if(e.fn){var a=e;r=a.context,e=a.fn}return(0,k.check)(e,k.is.func,n+": argument "+e+" is not a function"),{context:r,fn:e,args:t}}function f(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return U(A,c("call",n,t))}function l(n,e){var t=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return U(A,c("apply",{context:n,fn:e},t))}function s(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return U(C,c("cps",n,t))}function d(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return U(w,c("fork",n,t))}function p(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];var u=d.apply(void 0,[n].concat(t));return u[w].detached=!0,u}function v(n){if((0,k.check)(n,k.is.notUndef,"join(task): argument task is undefined"),!x(n))throw new Error("join(task): argument "+n+" is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)");return U(P,n)}function g(n){if((0,k.check)(n,k.is.notUndef,"cancel(task): argument task is undefined"),!x(n))throw new Error("cancel(task): argument "+n+" is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)");return U(S,n)}function h(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return 0===arguments.length?n=k.ident:((0,k.check)(h,k.is.notUndef,"select(selector,[...]): argument selector is undefined"),(0,k.check)(n,k.is.func,"select(selector,[...]): argument "+n+" is not a function")),U(T,{selector:n,args:t})}function y(n,e){return(0,k.check)(n,k.is.notUndef,"actionChannel(pattern,...): argument pattern is undefined"),arguments.length>1&&((0,k.check)(e,k.is.notUndef,"actionChannel(pattern, buffer): argument buffer is undefined"),(0,k.check)(e,k.is.notUndef,"actionChannel(pattern, buffer): argument "+e+" is not a valid buffer")),U(N,{pattern:n,buffer:e})}function b(){return U(R,{})}Object.defineProperty(e,"__esModule",{value:!0}),e.asEffect=void 0;var m=function(){function n(n,e){var t=[],r=!0,u=!1,o=void 0;try{for(var a,i=n[Symbol.iterator]();!(r=(a=i.next()).done)&&(t.push(a.value),!e||t.length!==e);r=!0);}catch(c){u=!0,o=c}finally{try{!r&&i.return&&i.return()}finally{if(u)throw o}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return n(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.take=u,e.takem=o,e.put=a,e.race=i,e.call=f,e.apply=l,e.cps=s,e.fork=d,e.spawn=p,e.join=v,e.cancel=g,e.select=h,e.actionChannel=y,e.cancelled=b;var k=t(1),E=(0,k.sym)("IO"),_="TAKE",j="PUT",O="RACE",A="CALL",C="CPS",w="FORK",P="JOIN",S="CANCEL",T="SELECT",N="ACTION_CHANNEL",R="CANCELLED",U=function(n,e){var t;return t={},r(t,E,!0),r(t,n,e),t};a.sync=function(){var n=a.apply(void 0,arguments);return n[j].sync=!0,n};var x=function(n){return n[k.TASK]};e.asEffect={take:function(n){return n&&n[E]&&n[_]},put:function(n){return n&&n[E]&&n[j]},race:function(n){return n&&n[E]&&n[O]},call:function(n){return n&&n[E]&&n[A]},cps:function(n){return n&&n[E]&&n[C]},fork:function(n){return n&&n[E]&&n[w]},join:function(n){return n&&n[E]&&n[P]},cancel:function(n){return n&&n[E]&&n[S]},select:function(n){return n&&n[E]&&n[T]},actionChannel:function(n){return n&&n[E]&&n[N]},cancelled:function(n){return n&&n[E]&&n[R]}}},function(n,e,t){"use strict";function r(){var n=arguments.length<=0||void 0===arguments[0]?1/0:arguments[0],e=arguments[1],t=[];return{isEmpty:function(){return!t.length},put:function(r){if(t.length<n)t.push(r);else switch(e){case a:throw new Error(o);case c:t.shift(),t.push(r)}},take:function(){return t.shift()}}}Object.defineProperty(e,"__esModule",{value:!0}),e.buffers=e.BUFFER_OVERFLOW=void 0;var u=t(1),o=e.BUFFER_OVERFLOW="Channel's Buffer overflow!",a=1,i=2,c=3,f={isEmpty:u.kTrue,put:u.noop,take:u.noop};e.buffers={none:function(){return f},fixed:function(n){return r(n,a)},dropping:function(n){return r(n,i)},sliding:function(n){return r(n,c)}}},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n,e){for(var t in e){var r=e[t];r.configurable=r.enumerable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,t,r)}return n}function o(n){if(Array.isArray(n)){for(var e=0,t=Array(n.length);e<n.length;e++)t[e]=n[e];return t}return Array.from(n)}function a(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function i(n){return("*"===n?E.wildcard:l.is.array(n)?E.array:l.is.func(n)?E.predicate:E.default)(n)}function c(n,e,t){function r(n){o.push(n),n.cont=function(r,c){i||((0,l.remove)(o,n),n.cont=l.noop,c?(u(),t(r,!0)):(n===e&&(a=r),o.length||(i=!0,t(a))))}}function u(){i||(i=!0,o.forEach(function(n){n.cont=l.noop,n.cancel()}),o=[])}var o=[],a=void 0,i=!1;return r(e),{addTask:r,cancelAll:u,getTasks:function(){return o},taskNames:function(){return o.map(function(n){return n.name})}}}function f(n){function e(){Q.isRunning&&!Q.isCancelled&&(Q.isCancelled=!0,r(k))}function t(){n._isRunning&&!n._isCancelled&&(n._isCancelled=!0,X.cancelAll(),s(k))}function r(e,t){if(!Q.isRunning)throw new Error("Trying to resume an already finished generator");try{var u=void 0;t?u=n.throw(e):e===k?(Q.isCancelled=!0,r.cancel(),u=l.is.func(n.return)?n.return(k):{done:!0,value:k}):u=e===m?l.is.func(n.return)?n.return():{done:!0}:n.next(e),u.done?(Q.isMainRunning=!1,Q.cont&&Q.cont(u.value)):E(u.value,H,"",r)}catch(o){Q.isCancelled&&W("error","uncaught at "+K,o.message),Q.isMainRunning=!1,Q.cont(o,!0)}}function s(e,t){n._isRunning=!1,J.close(),t?(e instanceof Error&&(e.sagaStack="at "+K+" \n "+(e.sagaStack||e.stack)),z.cont||W("error","uncaught",e.sagaStack||e.stack),n._error=e,n._isAborted=!0,n._deferredEnd&&n._deferredEnd.reject(e)):(e===k&&h&&W("info",K+" has been cancelled",""),n._result=e,n._deferredEnd&&n._deferredEnd.resolve(e)),z.cont&&z.cont(e,t),z.joiners.forEach(function(n){return n.cb(e,t)}),z.joiners=null}function E(n,e){function t(n,e){a||(a=!0,u.cancel=l.noop,V&&(e?V.effectRejected(o,n):V.effectResolved(o,n)),u(n,e))}var r=arguments.length<=2||void 0===arguments[2]?"":arguments[2],u=arguments[3],o=b();V&&V.effectTriggered({effectId:o,parentEffectId:e,label:r,effect:n});var a=void 0;t.cancel=l.noop,u.cancel=function(){if(!a){a=!0;try{t.cancel()}catch(n){W("error","uncaught at "+K,n.message)}t.cancel=l.noop,V&&V.effectCancelled(o)}};var i=void 0;return l.is.promise(n)?_(n,t):l.is.iterator(n)?j(n,o,K,t):l.is.array(n)?N(n,o,t):l.is.notUndef(i=p.asEffect.take(n))?O(i,t):l.is.notUndef(i=p.asEffect.put(n))?A(i,t):l.is.notUndef(i=p.asEffect.race(n))?R(i,o,t):l.is.notUndef(i=p.asEffect.call(n))?C(i,o,t):l.is.notUndef(i=p.asEffect.cps(n))?w(i,t):l.is.notUndef(i=p.asEffect.fork(n))?P(i,o,t):l.is.notUndef(i=p.asEffect.join(n))?S(i,t):l.is.notUndef(i=p.asEffect.cancel(n))?T(i,t):l.is.notUndef(i=p.asEffect.select(n))?U(i,t):l.is.notUndef(i=p.asEffect.actionChannel(n))?x(i,t):l.is.notUndef(i=p.asEffect.cancelled(n))?M(i,t):t(n)}function _(n,e){var t=n[l.CANCEL];"function"==typeof t&&(e.cancel=t),n.then(e,function(n){return e(n,!0)})}function j(n,e,t,r){f(n,I,D,F,q,e,t,r)}function O(n,e){var t=n.channel,r=n.pattern,u=n.maybe;t=t||J;var o=function(n){return n instanceof Error?e(n,!0):e((0,v.isEnd)(n)&&!u?m:n)};try{t.take(o,i(r))}catch(a){return e(a,!0)}e.cancel=o.cancel}function A(n,e){var t=n.channel,r=n.action,u=n.sync;(0,d.default)(function(){var n=void 0;try{n=(t?t.put:D)(r)}catch(o){return e(o,!0)}return u&&l.is.promise(n)?void _(n,e):e(n)})}function C(n,e,t){var r=n.context,u=n.fn,o=n.args,a=void 0;try{a=u.apply(r,o)}catch(i){return t(i,!0)}return l.is.promise(a)?_(a,t):l.is.iterator(a)?j(a,e,u.name,t):t(a)}function w(n,e){var t=n.context,r=n.fn,u=n.args;try{r.apply(t,u.concat(function(n,t){return l.is.undef(n)?e(t):e(n,!0)}))}catch(o){return e(o,!0)}}function P(n,e,t){var r=n.context,u=n.fn,o=n.args,a=n.detached,i=void 0,c=void 0,s=void 0;try{i=u.apply(r,o)}catch(p){if(!a)return t(p);c=p}s=l.is.iterator(i)?i:c?(0,l.makeIterator)(function(){throw c}):(0,l.makeIterator)(function(){var n=void 0,e={done:!1,value:i},t=function(n){return{done:!0,value:n}};return function(r){return n?t(r):(n=!0,e)}}()),d.default.suspend();var v=f(s,I,D,F,q,e,u.name,a?null:l.noop);if(!a)if(s._isRunning)X.addTask(v);else if(s._error)return t(s._error,!0);t(v),d.default.flush()}function S(n,e){n.isRunning()?!function(){var t={task:z,cb:e};e.cancel=function(){return(0,l.remove)(n.joiners,t)},n.joiners.push(t)}():n.isAborted()?e(n.error(),!0):e(n.result())}function T(n,e){n.isRunning()&&n.cancel(),e()}function N(n,e,t){function r(){u===a.length&&(o=!0,t(a))}if(!n.length)return t([]);var u=0,o=void 0,a=Array(n.length),i=n.map(function(n,e){var i=function(n,i){o||(i||(0,v.isEnd)(n)||n===m||n===k?(t.cancel(),t(n,i)):(a[e]=n,u++,r()))};return i.cancel=l.noop,i});t.cancel=function(){o||(o=!0,i.forEach(function(n){return n.cancel()}))},n.forEach(function(n,t){return E(n,e,t,i[t])})}function R(n,e,t){var r=void 0,u=Object.keys(n),o={};u.forEach(function(n){var e=function(e,u){r||(u?(t.cancel(),t(e,!0)):(0,v.isEnd)(e)||e===m||e===k||(t.cancel(),r=!0,t(a({},n,e))))};e.cancel=l.noop,o[n]=e}),t.cancel=function(){r||(r=!0,u.forEach(function(n){return o[n].cancel()}))},u.forEach(function(t){return E(n[t],e,t,o[t])})}function U(n,e){var t=n.selector,r=n.args;try{var u=t.apply(void 0,[F()].concat(o(r)));e(u)}catch(a){e(a,!0)}}function x(n,e){var t=n.pattern,r=n.buffer,u=i(t);u.pattern=t,e((0,v.eventChannel)(I,r||g.buffers.fixed(),u))}function M(n,e){e(!!Q.isCancelled)}function L(n,e,r,o){var i,c,f;return r._deferredEnd=null,c={},a(c,l.TASK,!0),a(c,"id",n),a(c,"name",e),i="done",f={},f[i]=f[i]||{},f[i].get=function(){if(r._deferredEnd)return r._deferredEnd.promise;var n=(0,l.deferred)();return r._deferredEnd=n,r._isRunning||(r._error?n.reject(r._error):n.resolve(r._result)),n.promise},a(c,"cont",o),a(c,"joiners",[]),a(c,"cancel",t),a(c,"isRunning",function(){return r._isRunning}),a(c,"isCancelled",function(){return r._isCancelled}),a(c,"isAborted",function(){return r._isAborted}),a(c,"result",function(){return r._result}),a(c,"error",function(){return r._error}),u(c,f),c}var I=arguments.length<=1||void 0===arguments[1]?function(){return l.noop}:arguments[1],D=arguments.length<=2||void 0===arguments[2]?l.noop:arguments[2],F=arguments.length<=3||void 0===arguments[3]?l.noop:arguments[3],q=arguments.length<=4||void 0===arguments[4]?{}:arguments[4],H=arguments.length<=5||void 0===arguments[5]?0:arguments[5],K=arguments.length<=6||void 0===arguments[6]?"anonymous":arguments[6],B=arguments[7];(0,l.check)(n,l.is.iterator,y);var V=q.sagaMonitor,G=q.logger,W=G||l.log,J=(0,v.eventChannel)(I);r.cancel=l.noop;var z=L(H,K,n,B),Q={name:K,cancel:e,isRunning:!0},X=c(K,Q,s);return B&&(B.cancel=t),n._isRunning=!0,r(),z}Object.defineProperty(e,"__esModule",{value:!0}),e.TASK_CANCEL=e.CHANNEL_END=e.NOT_ITERATOR_ERROR=void 0,e.default=f;var l=t(1),s=t(7),d=r(s),p=t(3),v=t(2),g=t(4),h=!1,y=e.NOT_ITERATOR_ERROR="proc first argument (Saga function result) must be an iterator",b=(0,l.autoInc)(),m=e.CHANNEL_END={toString:function(){return"@@redux-saga/CHANNEL_END"}},k=e.TASK_CANCEL={toString:function(){return"@@redux-saga/TASK_CANCEL"}},E={wildcard:function(){return l.kTrue},"default":function(n){return function(e){return e.type===n}},array:function(n){return function(e){return n.some(function(n){return n===e.type})}},predicate:function(n){return function(e){return n(e)}}}},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=t(3);Object.defineProperty(e,"take",{enumerable:!0,get:function(){return r.take}}),Object.defineProperty(e,"takem",{enumerable:!0,get:function(){return r.takem}}),Object.defineProperty(e,"put",{enumerable:!0,get:function(){return r.put}}),Object.defineProperty(e,"race",{enumerable:!0,get:function(){return r.race}}),Object.defineProperty(e,"call",{enumerable:!0,get:function(){return r.call}}),Object.defineProperty(e,"apply",{enumerable:!0,get:function(){return r.apply}}),Object.defineProperty(e,"cps",{enumerable:!0,get:function(){return r.cps}}),Object.defineProperty(e,"fork",{enumerable:!0,get:function(){return r.fork}}),Object.defineProperty(e,"spawn",{enumerable:!0,get:function(){return r.spawn}}),Object.defineProperty(e,"join",{enumerable:!0,get:function(){return r.join}}),Object.defineProperty(e,"cancel",{enumerable:!0,get:function(){return r.cancel}}),Object.defineProperty(e,"select",{enumerable:!0,get:function(){return r.select}}),Object.defineProperty(e,"actionChannel",{enumerable:!0,get:function(){return r.actionChannel}}),Object.defineProperty(e,"cancelled",{enumerable:!0,get:function(){return r.cancelled}})},function(n,e){"use strict";function t(n){u?r.push(n):(u=!0,r.push(n),t.flush())}Object.defineProperty(e,"__esModule",{value:!0}),e.default=t;var r=[],u=!1;t.suspend=function(){return u=!0},t.flush=function(){for(var n=void 0;n=r.shift();)n();u=!1}},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(){function n(n){function r(n){for(var t=arguments.length,r=Array(t>1?t-1:0),c=1;t>c;c++)r[c-1]=arguments[c];return(0,i.default)(n.apply(void 0,r),a.subscribe,o,u,e,0,n.name)}var u=n.getState,o=n.dispatch;t=r;var a=(0,c.emitter)();return function(n){return function(e){var t=n(e);return a.emit(e),t}}}var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=void 0;if(o.is.func(e))throw new Error("Saga middleware no longer accept Generator functions. Use sagaMiddleware.run instead");if(e.logger&&!o.is.func(e.logger))throw new Error("`options.logger` passed to the Saga middleware is not a function!");return n.run=function(n){for(var e=arguments.length,r=Array(e>1?e-1:0),u=1;e>u;u++)r[u-1]=arguments[u];return(0,o.check)(t,o.is.notUndef,"Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware"),(0,o.check)(n,o.is.func,"sagaMiddleware.run(saga, ...args): saga argument must be a Generator function!"),t.apply(void 0,[n].concat(r))},n}Object.defineProperty(e,"__esModule",{value:!0}),e.default=u;var o=t(1),a=t(5),i=r(a),c=t(2)},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n,e){var t=e.subscribe,r=e.dispatch,u=e.getState,a=e.sagaMonitor,c=e.logger;return(0,o.check)(n,o.is.iterator,"runSaga must be called on an iterator"),(0,i.default)(n,t,r,u,{sagaMonitor:a,logger:c})}Object.defineProperty(e,"__esModule",{value:!0}),e.runSaga=u;var o=t(1),a=t(5),i=r(a)},function(n,e,t){"use strict";function r(n,e){function t(e,t){if(o===d)return s;if(t)throw o=d,t;u&&u(e);var r=n[o](),a=i(r,3),c=a[0],f=a[1],l=a[2];return o=c,u=l,o===d?s:f}var r=arguments.length<=2||void 0===arguments[2]?"iterator":arguments[2],u=void 0,o=e;return(0,f.makeIterator)(t,function(n){return t(null,n)},r)}function u(n){return Array.isArray(n)?String(n.map(function(n){return String(n)})):String(n)}function o(n,e){for(var t=arguments.length,o=Array(t>2?t-2:0),a=2;t>a;a++)o[a-2]=arguments[a];var i={done:!1,value:(0,l.take)(n)},f=function(n){return{done:!1,value:l.fork.apply(void 0,[e].concat(o,[n]))}},s=void 0,p=function(n){return s=n};return r({q1:function(){return["q2",i,p]},q2:function(){return s===c.END?[d]:["q1",f(s)]}},"q1","takeEvery("+u(n)+", "+e.name+")")}function a(n,e){for(var t=arguments.length,o=Array(t>2?t-2:0),a=2;t>a;a++)o[a-2]=arguments[a];var i={done:!1,value:(0,l.take)(n)},f=function(n){return{done:!1,value:l.fork.apply(void 0,[e].concat(o,[n]))}},s=function(n){return{done:!1,value:(0,l.cancel)(n)}},p=void 0,v=void 0,g=function(n){return p=n},h=function(n){return v=n};return r({q1:function(){return["q2",i,h]},q2:function(){return v===c.END?[d]:p?["q3",s(p)]:["q1",f(v),g]},q3:function(){return["q1",f(v),g]}},"q1","takeLatest("+u(n)+", "+e.name+")")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function n(n,e){var t=[],r=!0,u=!1,o=void 0;try{for(var a,i=n[Symbol.iterator]();!(r=(a=i.next()).done)&&(t.push(a.value),!e||t.length!==e);r=!0);}catch(c){u=!0,o=c}finally{try{!r&&i.return&&i.return()}finally{if(u)throw o}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return n(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.takeEvery=o,e.takeLatest=a;var c=t(2),f=t(1),l=t(3),s={done:!0,value:void 0},d={}},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=t(1);Object.defineProperty(e,"TASK",{enumerable:!0,get:function(){return r.TASK}}),Object.defineProperty(e,"noop",{enumerable:!0,get:function(){return r.noop}}),Object.defineProperty(e,"is",{enumerable:!0,get:function(){return r.is}}),Object.defineProperty(e,"deferred",{enumerable:!0,get:function(){return r.deferred}}),Object.defineProperty(e,"arrayOfDeffered",{enumerable:!0,get:function(){return r.arrayOfDeffered}}),Object.defineProperty(e,"createMockTask",{enumerable:!0,get:function(){return r.createMockTask}});var u=t(3);Object.defineProperty(e,"asEffect",{enumerable:!0,get:function(){return u.asEffect}})}])}); | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ReduxSaga=e():n.ReduxSaga=e()}(this,function(){return function(n){function e(r){if(t[r])return t[r].exports;var u=t[r]={exports:{},id:r,loaded:!1};return n[r].call(u.exports,u,u.exports,e),u.loaded=!0,u.exports}var t={};return e.m=n,e.c=t,e.p="",e(0)}([function(n,e,t){"use strict";function r(n){if(n&&n.__esModule)return n;var e={};if(null!=n)for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e.default=n,e}function u(n){return n&&n.__esModule?n:{"default":n}}Object.defineProperty(e,"__esModule",{value:!0}),e.utils=e.effects=e.CANCEL=e.delay=e.takeLatest=e.takeEvery=e.buffers=e.channel=e.eventChannel=e.END=e.runSaga=void 0;var o=t(9);Object.defineProperty(e,"runSaga",{enumerable:!0,get:function(){return o.runSaga}});var a=t(2);Object.defineProperty(e,"END",{enumerable:!0,get:function(){return a.END}}),Object.defineProperty(e,"eventChannel",{enumerable:!0,get:function(){return a.eventChannel}}),Object.defineProperty(e,"channel",{enumerable:!0,get:function(){return a.channel}});var i=t(4);Object.defineProperty(e,"buffers",{enumerable:!0,get:function(){return i.buffers}});var c=t(10);Object.defineProperty(e,"takeEvery",{enumerable:!0,get:function(){return c.takeEvery}}),Object.defineProperty(e,"takeLatest",{enumerable:!0,get:function(){return c.takeLatest}});var f=t(1);Object.defineProperty(e,"delay",{enumerable:!0,get:function(){return f.delay}}),Object.defineProperty(e,"CANCEL",{enumerable:!0,get:function(){return f.CANCEL}});var l=t(8),s=u(l),d=t(6),v=r(d),p=t(11),g=r(p);e.default=s.default,e.effects=v,e.utils=g},function(n,e){"use strict";function t(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function r(n,e,t){if(!e(n))throw s("error","uncaught at check",t),new Error(t)}function u(n,e){var t=n.indexOf(e);t>=0&&n.splice(t,1)}function o(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=d({},n),t=new Promise(function(n,t){e.resolve=n,e.reject=t});return e.promise=t,e}function a(n){for(var e=[],t=0;n>t;t++)e.push(o());return e}function i(n){var e=arguments.length<=1||void 0===arguments[1]?!0:arguments[1],t=void 0,r=new Promise(function(r){t=setTimeout(function(){return r(e)},n)});return r[h]=function(){return clearTimeout(t)},r}function c(){var n,e=!0,r=void 0,u=void 0;return n={},t(n,g,!0),t(n,"isRunning",function(){return e}),t(n,"result",function(){return r}),t(n,"error",function(){return u}),t(n,"setRunning",function(n){return e=n}),t(n,"setResult",function(n){return r=n}),t(n,"setError",function(n){return u=n}),n}function f(){var n=arguments.length<=0||void 0===arguments[0]?0:arguments[0];return function(){return++n}}function l(n){var e=arguments.length<=1||void 0===arguments[1]?m:arguments[1],t=arguments.length<=2||void 0===arguments[2]?"":arguments[2],r={name:t,next:n,"throw":e,"return":k};return"undefined"!=typeof Symbol&&(r[Symbol.iterator]=function(){return r}),r}function s(n,e,t){"undefined"==typeof window?console.log("redux-saga "+n+": "+e+"\n"+(t&&t.stack||t)):console[n].call(console,e,t)}Object.defineProperty(e,"__esModule",{value:!0});var d=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol?"symbol":typeof n};e.check=r,e.remove=u,e.deferred=o,e.arrayOfDeffered=a,e.delay=i,e.createMockTask=c,e.autoInc=f,e.makeIterator=l,e.log=s;var p=e.sym=function(n){return"@@redux-saga/"+n},g=e.TASK=p("TASK"),h=(e.MATCH=p("MATCH"),e.CANCEL=p("cancelPromise")),y=e.konst=function(n){return function(){return n}},b=(e.kTrue=y(!0),e.kFalse=y(!1),e.noop=function(){},e.ident=function(n){return n},e.is={undef:function(n){return null===n||void 0===n},notUndef:function(n){return null!==n&&void 0!==n},func:function(n){return"function"==typeof n},number:function(n){return"number"==typeof n},array:Array.isArray,promise:function(n){return n&&b.func(n.then)},iterator:function(n){return n&&b.func(n.next)&&b.func(n.throw)},task:function(n){return n&&n[g]},take:function(n){return n&&b.func(n.take)},put:function(n){return n&&b.func(n.put)},observable:function(n){return n&&b.func(n.subscribe)},buffer:function(n){return n&&b.func(n.isEmpty)&&b.func(n.take)&&b.func(n.put)},pattern:function(n){return n&&("string"==typeof n||"symbol"===("undefined"==typeof n?"undefined":v(n))||b.func(n)||b.array(n))}}),m=function(n){throw n},k=function(n){return{value:n,done:!0}};e.internalErr=function(n){return new Error("\n redux-saga: Error checking hooks detected an inconsisten state. This is likely a bug\n in redux-saga code and not yours. Thanks for reporting this in the project's github repo.\n Error: "+n+"\n")}},function(n,e,t){"use strict";function r(){function n(n){return t.push(n),function(){return(0,a.remove)(t,n)}}function e(n){for(var e=t.slice(),r=0,u=e.length;u>r;r++)e[r](n)}var t=[];return{subscribe:n,emit:e}}function u(n){function e(){if(o&&c.length)throw(0,a.internalErr)("Cannot have a closed channel with pending takers");if(c.length&&!n.isEmpty())throw(0,a.internalErr)("Cannot have pending takers with non empty buffer")}function t(t){if(e(),(0,a.check)(t,a.is.notUndef,d),!o)if(c.length)for(var r=0;r<c.length;r++){var u=c[r];if(!u[a.MATCH]||u[a.MATCH](t))return c.splice(r,1),u(t)}else n.put(t)}function r(t,r){e(),(0,a.check)(t,a.is.func,"channel.take's callback must be a function"),arguments.length>1&&((0,a.check)(r,a.is.func,"channel.take's matcher argument must be a function"),t[a.MATCH]=r),o&&n.isEmpty()?t(f):n.isEmpty()?(c.push(t),t.cancel=function(){return(0,a.remove)(c,t)}):t(n.take())}function u(){if(e(),!o&&(o=!0,c.length)){var n=c;c=[];for(var t=0,r=n.length;r>t;t++)n[t](f);c=[]}}var o=!1,c=[];return arguments.length>0?(0,a.check)(n,a.is.buffer,s):n=i.buffers.fixed(),{take:r,put:t,close:u,get __takers__(){return c},get __closed__(){return o}}}function o(n){var e=arguments.length<=1||void 0===arguments[1]?i.buffers.none():arguments[1],t=arguments[2];arguments.length>2&&(0,a.check)(t,a.is.func,"Invalid match function passed to eventChannel");var r=u(e),o=n(function(n){l(n)?r.close():t&&!t(n)||r.put(n)});if(!a.is.func(o))throw new Error("in eventChannel: subscribe should return a function to unsubscribe");return{take:r.take,close:function(){r.__closed__||(r.close(),o())}}}Object.defineProperty(e,"__esModule",{value:!0}),e.UNDEFINED_INPUT_ERROR=e.INVALID_BUFFER=e.isEnd=e.END=void 0,e.emitter=r,e.channel=u,e.eventChannel=o;var a=t(1),i=t(4),c="@@redux-saga/CHANNEL_END",f=e.END={type:c},l=e.isEnd=function(n){return n&&n.type===c},s=e.INVALID_BUFFER="invalid buffer passed to channel factory function",d=e.UNDEFINED_INPUT_ERROR="Saga was provided with an undefined action"},function(n,e,t){"use strict";function r(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function u(n,e){if(arguments.length>=2)(0,k.check)(n,k.is.notUndef,"take(channel, pattern): channel is undefined"),(0,k.check)(n,k.is.take,"take(channel, pattern): argument "+String(n)+" is not a valid channel (channel argument must have a take method)"),(0,k.check)(e,k.is.notUndef,"take(channel, pattern): pattern is undefined"),(0,k.check)(e,k.is.pattern,"take(channel, pattern): argument "+String(e)+" is not a valid pattern (pattern must be String | Function: a => boolean | Array<String>)");else if(1===arguments.length)if((0,k.check)(n,k.is.notUndef,"take(patternOrChannel): undefined argument"),k.is.take(n))e="*";else{if(!k.is.pattern(n))throw new Error("take(patternOrChannel): argument "+String(n)+" is not valid channel or a valid pattern");e=n,n=null}else e="*";return U(_,{channel:n,pattern:e})}function o(){var n=u.apply(void 0,arguments);return n[_].maybe=!0,n}function a(n,e){return arguments.length>1?((0,k.check)(n,k.is.notUndef,"put(channel, action): argument channel is undefined"),(0,k.check)(n,k.is.put,"put(channel, action): argument "+n+" is not a valid channel (channel argument must have a put method)"),(0,k.check)(e,k.is.notUndef,"put(channel, action): argument action is undefined")):((0,k.check)(n,k.is.notUndef,"put(action): argument action is undefined"),e=n,n=null),U(j,{channel:n,action:e})}function i(n){return U(O,n)}function c(n,e,t){(0,k.check)(e,k.is.notUndef,n+": argument fn is undefined");var r=null;if(k.is.array(e)){var u=e,o=m(u,2);r=o[0],e=o[1]}else if(e.fn){var a=e;r=a.context,e=a.fn}return(0,k.check)(e,k.is.func,n+": argument "+e+" is not a function"),{context:r,fn:e,args:t}}function f(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return U(A,c("call",n,t))}function l(n,e){var t=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return U(A,c("apply",{context:n,fn:e},t))}function s(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return U(C,c("cps",n,t))}function d(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return U(w,c("fork",n,t))}function v(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];var u=d.apply(void 0,[n].concat(t));return u[w].detached=!0,u}function p(n){if((0,k.check)(n,k.is.notUndef,"join(task): argument task is undefined"),!x(n))throw new Error("join(task): argument "+n+" is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)");return U(P,n)}function g(n){if((0,k.check)(n,k.is.notUndef,"cancel(task): argument task is undefined"),!x(n))throw new Error("cancel(task): argument "+n+" is not a valid Task object \n(HINT: if you are getting this errors in tests, consider using createMockTask from redux-saga/utils)");return U(S,n)}function h(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return 0===arguments.length?n=k.ident:((0,k.check)(h,k.is.notUndef,"select(selector,[...]): argument selector is undefined"),(0,k.check)(n,k.is.func,"select(selector,[...]): argument "+n+" is not a function")),U(T,{selector:n,args:t})}function y(n,e){return(0,k.check)(n,k.is.notUndef,"actionChannel(pattern,...): argument pattern is undefined"),arguments.length>1&&((0,k.check)(e,k.is.notUndef,"actionChannel(pattern, buffer): argument buffer is undefined"),(0,k.check)(e,k.is.notUndef,"actionChannel(pattern, buffer): argument "+e+" is not a valid buffer")),U(N,{pattern:n,buffer:e})}function b(){return U(R,{})}Object.defineProperty(e,"__esModule",{value:!0}),e.asEffect=void 0;var m=function(){function n(n,e){var t=[],r=!0,u=!1,o=void 0;try{for(var a,i=n[Symbol.iterator]();!(r=(a=i.next()).done)&&(t.push(a.value),!e||t.length!==e);r=!0);}catch(c){u=!0,o=c}finally{try{!r&&i.return&&i.return()}finally{if(u)throw o}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return n(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.take=u,e.takem=o,e.put=a,e.race=i,e.call=f,e.apply=l,e.cps=s,e.fork=d,e.spawn=v,e.join=p,e.cancel=g,e.select=h,e.actionChannel=y,e.cancelled=b;var k=t(1),E=(0,k.sym)("IO"),_="TAKE",j="PUT",O="RACE",A="CALL",C="CPS",w="FORK",P="JOIN",S="CANCEL",T="SELECT",N="ACTION_CHANNEL",R="CANCELLED",U=function(n,e){var t;return t={},r(t,E,!0),r(t,n,e),t};a.sync=function(){var n=a.apply(void 0,arguments);return n[j].sync=!0,n};var x=function(n){return n[k.TASK]};e.asEffect={take:function(n){return n&&n[E]&&n[_]},put:function(n){return n&&n[E]&&n[j]},race:function(n){return n&&n[E]&&n[O]},call:function(n){return n&&n[E]&&n[A]},cps:function(n){return n&&n[E]&&n[C]},fork:function(n){return n&&n[E]&&n[w]},join:function(n){return n&&n[E]&&n[P]},cancel:function(n){return n&&n[E]&&n[S]},select:function(n){return n&&n[E]&&n[T]},actionChannel:function(n){return n&&n[E]&&n[N]},cancelled:function(n){return n&&n[E]&&n[R]}}},function(n,e,t){"use strict";function r(){var n=arguments.length<=0||void 0===arguments[0]?10:arguments[0],e=arguments[1],t=new Array(n),r=0,u=0,i=0;return{isEmpty:function(){return 0==r},put:function(f){if(n>r)t[u]=f,u=(u+1)%n,r++;else switch(e){case a:throw new Error(o);case c:t[u]=f,u=(u+1)%n,i=u}},take:function(){if(0!=r){var e=t[i];return t[i]=null,r--,i=(i+1)%n,e}}}}Object.defineProperty(e,"__esModule",{value:!0}),e.buffers=e.BUFFER_OVERFLOW=void 0;var u=t(1),o=e.BUFFER_OVERFLOW="Channel's Buffer overflow!",a=1,i=2,c=3,f={isEmpty:u.kTrue,put:u.noop,take:u.noop};e.buffers={none:function(){return f},fixed:function(n){return r(n,a)},dropping:function(n){return r(n,i)},sliding:function(n){return r(n,c)}}},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n,e){for(var t in e){var r=e[t];r.configurable=r.enumerable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,t,r)}return n}function o(n){if(Array.isArray(n)){for(var e=0,t=Array(n.length);e<n.length;e++)t[e]=n[e];return t}return Array.from(n)}function a(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function i(n){return("*"===n?E.wildcard:l.is.array(n)?E.array:l.is.func(n)?E.predicate:E.default)(n)}function c(n,e,t){function r(n){o(),t(n,!0)}function u(n){a.push(n),n.cont=function(u,o){c||((0,l.remove)(a,n),n.cont=l.noop,o?r(u):(n===e&&(i=u),a.length||(c=!0,t(i))))}}function o(){c||(c=!0,a.forEach(function(n){n.cont=l.noop,n.cancel()}),a=[])}var a=[],i=void 0,c=!1;return u(e),{addTask:u,cancelAll:o,abort:r,getTasks:function(){return a},taskNames:function(){return a.map(function(n){return n.name})}}}function f(n){function e(){Q.isRunning&&!Q.isCancelled&&(Q.isCancelled=!0,r(k))}function t(){n._isRunning&&!n._isCancelled&&(n._isCancelled=!0,X.cancelAll(),s(k))}function r(e,t){if(!Q.isRunning)throw new Error("Trying to resume an already finished generator");try{var u=void 0;t?u=n.throw(e):e===k?(Q.isCancelled=!0,r.cancel(),u=l.is.func(n.return)?n.return(k):{done:!0,value:k}):u=e===m?l.is.func(n.return)?n.return():{done:!0}:n.next(e),u.done?(Q.isMainRunning=!1,Q.cont&&Q.cont(u.value)):E(u.value,H,"",r)}catch(o){Q.isCancelled&&W("error","uncaught at "+K,o.message),Q.isMainRunning=!1,Q.cont(o,!0)}}function s(e,t){n._isRunning=!1,J.close(),t?(e instanceof Error&&(e.sagaStack="at "+K+" \n "+(e.sagaStack||e.stack)),z.cont||W("error","uncaught",e.sagaStack||e.stack),n._error=e,n._isAborted=!0,n._deferredEnd&&n._deferredEnd.reject(e)):(e===k&&h&&W("info",K+" has been cancelled",""),n._result=e,n._deferredEnd&&n._deferredEnd.resolve(e)),z.cont&&z.cont(e,t),z.joiners.forEach(function(n){return n.cb(e,t)}),z.joiners=null}function E(n,e){function t(n,e){a||(a=!0,u.cancel=l.noop,V&&(e?V.effectRejected(o,n):V.effectResolved(o,n)),u(n,e))}var r=arguments.length<=2||void 0===arguments[2]?"":arguments[2],u=arguments[3],o=b();V&&V.effectTriggered({effectId:o,parentEffectId:e,label:r,effect:n});var a=void 0;t.cancel=l.noop,u.cancel=function(){if(!a){a=!0;try{t.cancel()}catch(n){W("error","uncaught at "+K,n.message)}t.cancel=l.noop,V&&V.effectCancelled(o)}};var i=void 0;return l.is.promise(n)?_(n,t):l.is.iterator(n)?j(n,o,K,t):l.is.array(n)?N(n,o,t):l.is.notUndef(i=v.asEffect.take(n))?O(i,t):l.is.notUndef(i=v.asEffect.put(n))?A(i,t):l.is.notUndef(i=v.asEffect.race(n))?R(i,o,t):l.is.notUndef(i=v.asEffect.call(n))?C(i,o,t):l.is.notUndef(i=v.asEffect.cps(n))?w(i,t):l.is.notUndef(i=v.asEffect.fork(n))?P(i,o,t):l.is.notUndef(i=v.asEffect.join(n))?S(i,t):l.is.notUndef(i=v.asEffect.cancel(n))?T(i,t):l.is.notUndef(i=v.asEffect.select(n))?U(i,t):l.is.notUndef(i=v.asEffect.actionChannel(n))?x(i,t):l.is.notUndef(i=v.asEffect.cancelled(n))?M(i,t):t(n)}function _(n,e){var t=n[l.CANCEL];"function"==typeof t&&(e.cancel=t),n.then(e,function(n){return e(n,!0)})}function j(n,e,t,r){f(n,I,D,F,q,e,t,r)}function O(n,e){var t=n.channel,r=n.pattern,u=n.maybe;t=t||J;var o=function(n){return n instanceof Error?e(n,!0):e((0,p.isEnd)(n)&&!u?m:n)};try{t.take(o,i(r))}catch(a){return e(a,!0)}e.cancel=o.cancel}function A(n,e){var t=n.channel,r=n.action,u=n.sync;(0,d.default)(function(){var n=void 0;try{n=(t?t.put:D)(r)}catch(o){return e(o,!0)}return u&&l.is.promise(n)?void _(n,e):e(n)})}function C(n,e,t){var r=n.context,u=n.fn,o=n.args,a=void 0;try{a=u.apply(r,o)}catch(i){return t(i,!0)}return l.is.promise(a)?_(a,t):l.is.iterator(a)?j(a,e,u.name,t):t(a)}function w(n,e){var t=n.context,r=n.fn,u=n.args;try{r.apply(t,u.concat(function(n,t){return l.is.undef(n)?e(t):e(n,!0)}))}catch(o){return e(o,!0)}}function P(n,e,t){var r=n.context,u=n.fn,o=n.args,a=n.detached,i=void 0,c=void 0,s=void 0;try{i=u.apply(r,o)}catch(v){c=v}s=l.is.iterator(i)?i:c?(0,l.makeIterator)(function(){throw c}):(0,l.makeIterator)(function(){var n=void 0,e={done:!1,value:i},t=function(n){return{done:!0,value:n}};return function(r){return n?t(r):(n=!0,e)}}()),d.default.suspend();var p=f(s,I,D,F,q,e,u.name,a?null:l.noop);a?t(p):s._isRunning?(X.addTask(p),t(p)):s._error?X.abort(s._error):t(p),d.default.flush()}function S(n,e){n.isRunning()?!function(){var t={task:z,cb:e};e.cancel=function(){return(0,l.remove)(n.joiners,t)},n.joiners.push(t)}():n.isAborted()?e(n.error(),!0):e(n.result())}function T(n,e){n.isRunning()&&n.cancel(),e()}function N(n,e,t){function r(){u===a.length&&(o=!0,t(a))}if(!n.length)return t([]);var u=0,o=void 0,a=Array(n.length),i=n.map(function(n,e){var i=function(n,i){o||(i||(0,p.isEnd)(n)||n===m||n===k?(t.cancel(),t(n,i)):(a[e]=n,u++,r()))};return i.cancel=l.noop,i});t.cancel=function(){o||(o=!0,i.forEach(function(n){return n.cancel()}))},n.forEach(function(n,t){return E(n,e,t,i[t])})}function R(n,e,t){var r=void 0,u=Object.keys(n),o={};u.forEach(function(n){var e=function(e,u){r||(u?(t.cancel(),t(e,!0)):(0,p.isEnd)(e)||e===m||e===k||(t.cancel(),r=!0,t(a({},n,e))))};e.cancel=l.noop,o[n]=e}),t.cancel=function(){r||(r=!0,u.forEach(function(n){return o[n].cancel()}))},u.forEach(function(t){return E(n[t],e,t,o[t])})}function U(n,e){var t=n.selector,r=n.args;try{var u=t.apply(void 0,[F()].concat(o(r)));e(u)}catch(a){e(a,!0)}}function x(n,e){var t=n.pattern,r=n.buffer,u=i(t);u.pattern=t,e((0,p.eventChannel)(I,r||g.buffers.fixed(),u))}function M(n,e){e(!!Q.isCancelled)}function L(n,e,r,o){var i,c,f;return r._deferredEnd=null,c={},a(c,l.TASK,!0),a(c,"id",n),a(c,"name",e),i="done",f={},f[i]=f[i]||{},f[i].get=function(){if(r._deferredEnd)return r._deferredEnd.promise;var n=(0,l.deferred)();return r._deferredEnd=n,r._isRunning||(r._error?n.reject(r._error):n.resolve(r._result)),n.promise},a(c,"cont",o),a(c,"joiners",[]),a(c,"cancel",t),a(c,"isRunning",function(){return r._isRunning}),a(c,"isCancelled",function(){return r._isCancelled}),a(c,"isAborted",function(){return r._isAborted}),a(c,"result",function(){return r._result}),a(c,"error",function(){return r._error}),u(c,f),c}var I=arguments.length<=1||void 0===arguments[1]?function(){return l.noop}:arguments[1],D=arguments.length<=2||void 0===arguments[2]?l.noop:arguments[2],F=arguments.length<=3||void 0===arguments[3]?l.noop:arguments[3],q=arguments.length<=4||void 0===arguments[4]?{}:arguments[4],H=arguments.length<=5||void 0===arguments[5]?0:arguments[5],K=arguments.length<=6||void 0===arguments[6]?"anonymous":arguments[6],B=arguments[7];(0,l.check)(n,l.is.iterator,y);var V=q.sagaMonitor,G=q.logger,W=G||l.log,J=(0,p.eventChannel)(I);r.cancel=l.noop;var z=L(H,K,n,B),Q={name:K,cancel:e,isRunning:!0},X=c(K,Q,s);return B&&(B.cancel=t),n._isRunning=!0,r(),z}Object.defineProperty(e,"__esModule",{value:!0}),e.TASK_CANCEL=e.CHANNEL_END=e.NOT_ITERATOR_ERROR=void 0,e.default=f;var l=t(1),s=t(7),d=r(s),v=t(3),p=t(2),g=t(4),h=!1,y=e.NOT_ITERATOR_ERROR="proc first argument (Saga function result) must be an iterator",b=(0,l.autoInc)(),m=e.CHANNEL_END={toString:function(){return"@@redux-saga/CHANNEL_END"}},k=e.TASK_CANCEL={toString:function(){return"@@redux-saga/TASK_CANCEL"}},E={wildcard:function(){return l.kTrue},"default":function(n){return function(e){return e.type===n}},array:function(n){return function(e){return n.some(function(n){return n===e.type})}},predicate:function(n){return function(e){return n(e)}}}},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=t(3);Object.defineProperty(e,"take",{enumerable:!0,get:function(){return r.take}}),Object.defineProperty(e,"takem",{enumerable:!0,get:function(){return r.takem}}),Object.defineProperty(e,"put",{enumerable:!0,get:function(){return r.put}}),Object.defineProperty(e,"race",{enumerable:!0,get:function(){return r.race}}),Object.defineProperty(e,"call",{enumerable:!0,get:function(){return r.call}}),Object.defineProperty(e,"apply",{enumerable:!0,get:function(){return r.apply}}),Object.defineProperty(e,"cps",{enumerable:!0,get:function(){return r.cps}}),Object.defineProperty(e,"fork",{enumerable:!0,get:function(){return r.fork}}),Object.defineProperty(e,"spawn",{enumerable:!0,get:function(){return r.spawn}}),Object.defineProperty(e,"join",{enumerable:!0,get:function(){return r.join}}),Object.defineProperty(e,"cancel",{enumerable:!0,get:function(){return r.cancel}}),Object.defineProperty(e,"select",{enumerable:!0,get:function(){return r.select}}),Object.defineProperty(e,"actionChannel",{enumerable:!0,get:function(){return r.actionChannel}}),Object.defineProperty(e,"cancelled",{enumerable:!0,get:function(){return r.cancelled}})},function(n,e){"use strict";function t(n){u?r.push(n):(u=!0,r.push(n),t.flush())}Object.defineProperty(e,"__esModule",{value:!0}),e.default=t;var r=[],u=!1;t.suspend=function(){return u=!0},t.flush=function(){for(var n=void 0;n=r.shift();)n();u=!1}},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(){function n(n){function r(n){for(var t=arguments.length,r=Array(t>1?t-1:0),c=1;t>c;c++)r[c-1]=arguments[c];return(0,i.default)(n.apply(void 0,r),a.subscribe,o,u,e,0,n.name)}var u=n.getState,o=n.dispatch;t=r;var a=(0,c.emitter)();return function(n){return function(e){var t=n(e);return a.emit(e),t}}}var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=void 0;if(o.is.func(e))throw new Error("Saga middleware no longer accept Generator functions. Use sagaMiddleware.run instead");if(e.logger&&!o.is.func(e.logger))throw new Error("`options.logger` passed to the Saga middleware is not a function!");return n.run=function(n){for(var e=arguments.length,r=Array(e>1?e-1:0),u=1;e>u;u++)r[u-1]=arguments[u];return(0,o.check)(t,o.is.notUndef,"Before running a Saga, you must mount the Saga middleware on the Store using applyMiddleware"),(0,o.check)(n,o.is.func,"sagaMiddleware.run(saga, ...args): saga argument must be a Generator function!"),t.apply(void 0,[n].concat(r))},n}Object.defineProperty(e,"__esModule",{value:!0}),e.default=u;var o=t(1),a=t(5),i=r(a),c=t(2)},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n,e){var t=e.subscribe,r=e.dispatch,u=e.getState,a=e.sagaMonitor,c=e.logger;return(0,o.check)(n,o.is.iterator,"runSaga must be called on an iterator"),(0,i.default)(n,t,r,u,{sagaMonitor:a,logger:c})}Object.defineProperty(e,"__esModule",{value:!0}),e.runSaga=u;var o=t(1),a=t(5),i=r(a)},function(n,e,t){"use strict";function r(n,e){function t(e,t){if(o===d)return s;if(t)throw o=d,t;u&&u(e);var r=n[o](),a=i(r,3),c=a[0],f=a[1],l=a[2];return o=c,u=l,o===d?s:f}var r=arguments.length<=2||void 0===arguments[2]?"iterator":arguments[2],u=void 0,o=e;return(0,f.makeIterator)(t,function(n){return t(null,n)},r)}function u(n){return Array.isArray(n)?String(n.map(function(n){return String(n)})):String(n)}function o(n,e){for(var t=arguments.length,o=Array(t>2?t-2:0),a=2;t>a;a++)o[a-2]=arguments[a];var i={done:!1,value:(0,l.take)(n)},f=function(n){return{done:!1,value:l.fork.apply(void 0,[e].concat(o,[n]))}},s=void 0,v=function(n){return s=n};return r({q1:function(){return["q2",i,v]},q2:function(){return s===c.END?[d]:["q1",f(s)]}},"q1","takeEvery("+u(n)+", "+e.name+")")}function a(n,e){for(var t=arguments.length,o=Array(t>2?t-2:0),a=2;t>a;a++)o[a-2]=arguments[a];var i={done:!1,value:(0,l.take)(n)},f=function(n){return{done:!1,value:l.fork.apply(void 0,[e].concat(o,[n]))}},s=function(n){return{done:!1,value:(0,l.cancel)(n)}},v=void 0,p=void 0,g=function(n){return v=n},h=function(n){return p=n};return r({q1:function(){return["q2",i,h]},q2:function(){return p===c.END?[d]:v?["q3",s(v)]:["q1",f(p),g]},q3:function(){return["q1",f(p),g]}},"q1","takeLatest("+u(n)+", "+e.name+")")}Object.defineProperty(e,"__esModule",{value:!0});var i=function(){function n(n,e){var t=[],r=!0,u=!1,o=void 0;try{for(var a,i=n[Symbol.iterator]();!(r=(a=i.next()).done)&&(t.push(a.value),!e||t.length!==e);r=!0);}catch(c){u=!0,o=c}finally{try{!r&&i.return&&i.return()}finally{if(u)throw o}}return t}return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return n(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.takeEvery=o,e.takeLatest=a;var c=t(2),f=t(1),l=t(3),s={done:!0,value:void 0},d={}},function(n,e,t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=t(1);Object.defineProperty(e,"TASK",{enumerable:!0,get:function(){return r.TASK}}),Object.defineProperty(e,"noop",{enumerable:!0,get:function(){return r.noop}}),Object.defineProperty(e,"is",{enumerable:!0,get:function(){return r.is}}),Object.defineProperty(e,"deferred",{enumerable:!0,get:function(){return r.deferred}}),Object.defineProperty(e,"arrayOfDeffered",{enumerable:!0,get:function(){return r.arrayOfDeffered}}),Object.defineProperty(e,"createMockTask",{enumerable:!0,get:function(){return r.createMockTask}});var u=t(3);Object.defineProperty(e,"asEffect",{enumerable:!0,get:function(){return u.asEffect}})}])}); |
@@ -0,1 +1,2 @@ | ||
import {Action} from "redux"; | ||
import {Channel, Task, Buffer, Predicate} from "./types"; | ||
@@ -34,4 +35,4 @@ | ||
export function put<T>(action: T): PutEffect<T>; | ||
export function put<T>(channel: Channel<T>, action: T): PutEffect<T>; | ||
export function put<T extends Action>(action: T): PutEffect<T>; | ||
export function put<T extends Action>(channel: Channel<T>, action: T): PutEffect<T>; | ||
@@ -38,0 +39,0 @@ |
@@ -11,17 +11,19 @@ import { kTrue, noop } from './utils'; | ||
/** | ||
TODO: Need to make a more optimized implementation: e.g. Ring buffers, linked lists with Node Object pooling... | ||
**/ | ||
function arrBuffer() { | ||
var limit = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0]; | ||
function ringBuffer() { | ||
var limit = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0]; | ||
var overflowAction = arguments[1]; | ||
var arr = []; | ||
var arr = new Array(limit); | ||
var length = 0; | ||
var pushIndex = 0; | ||
var popIndex = 0; | ||
return { | ||
isEmpty: function isEmpty() { | ||
return !arr.length; | ||
return length == 0; | ||
}, | ||
put: function put(it) { | ||
if (arr.length < limit) { | ||
arr.push(it); | ||
if (length < limit) { | ||
arr[pushIndex] = it; | ||
pushIndex = (pushIndex + 1) % limit; | ||
length++; | ||
} else { | ||
@@ -32,4 +34,5 @@ switch (overflowAction) { | ||
case ON_OVERFLOW_SLIDE: | ||
arr.shift(); | ||
arr.push(it); | ||
arr[pushIndex] = it; | ||
pushIndex = (pushIndex + 1) % limit; | ||
popIndex = pushIndex; | ||
break; | ||
@@ -42,3 +45,9 @@ default: | ||
take: function take() { | ||
return arr.shift(); | ||
if (length != 0) { | ||
var it = arr[popIndex]; | ||
arr[popIndex] = null; | ||
length--; | ||
popIndex = (popIndex + 1) % limit; | ||
return it; | ||
} | ||
} | ||
@@ -53,10 +62,10 @@ }; | ||
fixed: function fixed(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_THROW); | ||
return ringBuffer(limit, ON_OVERFLOW_THROW); | ||
}, | ||
dropping: function dropping(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_DROP); | ||
return ringBuffer(limit, ON_OVERFLOW_DROP); | ||
}, | ||
sliding: function sliding(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_SLIDE); | ||
return ringBuffer(limit, ON_OVERFLOW_SLIDE); | ||
} | ||
}; |
@@ -142,2 +142,6 @@ import { is, check, remove, MATCH, internalErr } from './utils'; | ||
if (!is.func(unsubscribe)) { | ||
throw new Error('in eventChannel: subscribe should return a function to unsubscribe'); | ||
} | ||
return { | ||
@@ -144,0 +148,0 @@ take: chan.take, |
@@ -77,2 +77,7 @@ function _defineEnumerableProperties(obj, descs) { for (var key in descs) { var desc = descs[key]; desc.configurable = desc.enumerable = true; if ("value" in desc) desc.writable = true; Object.defineProperty(obj, key, desc); } return obj; } | ||
function abort(err) { | ||
cancelAll(); | ||
cb(err, true); | ||
} | ||
function addTask(task) { | ||
@@ -88,4 +93,3 @@ tasks.push(task); | ||
if (isErr) { | ||
cancelAll(); | ||
cb(res, true); | ||
abort(res); | ||
} else { | ||
@@ -119,2 +123,3 @@ if (task === mainTask) { | ||
cancelAll: cancelAll, | ||
abort: abort, | ||
getTasks: function getTasks() { | ||
@@ -361,3 +366,3 @@ return tasks; | ||
var data = void 0; | ||
return( | ||
return ( | ||
// Non declarative effect | ||
@@ -476,11 +481,7 @@ is.promise(effect) ? resolvePromise(effect, currCb) : is.iterator(effect) ? resolveIterator(effect, effectId, name, currCb) | ||
// catch synchronous failures; see #152 | ||
// catch synchronous failures; see #152 and #441 | ||
try { | ||
result = fn.apply(context, args); | ||
} catch (err) { | ||
if (!detached) { | ||
return cb(err); | ||
} else { | ||
error = err; | ||
} | ||
error = err; | ||
} | ||
@@ -493,4 +494,4 @@ | ||
// simple effect: wrap in a generator | ||
// do not bubble up synchronous failures for detached forks, instead create a failed task. See #152 | ||
// do not bubble up synchronous failures for detached forks | ||
// instead create a failed task. See #152 and #441 | ||
else { | ||
@@ -518,10 +519,14 @@ _iterator = error ? makeIterator(function () { | ||
var task = proc(_iterator, subscribe, dispatch, getState, options, effectId, fn.name, detached ? null : noop); | ||
if (!detached) { | ||
if (detached) { | ||
cb(task); | ||
} else { | ||
if (_iterator._isRunning) { | ||
taskQueue.addTask(task); | ||
cb(task); | ||
} else if (_iterator._error) { | ||
return cb(_iterator._error, true); | ||
taskQueue.abort(_iterator._error); | ||
} else { | ||
cb(task); | ||
} | ||
} | ||
cb(task); | ||
asap.flush(); | ||
@@ -528,0 +533,0 @@ // Fork effects are non cancellables |
@@ -149,2 +149,5 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
}; | ||
var kReturn = function kReturn(value) { | ||
return { value: value, done: true }; | ||
}; | ||
export function makeIterator(next) { | ||
@@ -154,3 +157,3 @@ var thro = arguments.length <= 1 || arguments[1] === undefined ? kThrow : arguments[1]; | ||
var iterator = { name: name, next: next, throw: thro }; | ||
var iterator = { name: name, next: next, throw: thro, return: kReturn }; | ||
if (typeof Symbol !== 'undefined') { | ||
@@ -157,0 +160,0 @@ iterator[Symbol.iterator] = function () { |
@@ -18,17 +18,19 @@ 'use strict'; | ||
/** | ||
TODO: Need to make a more optimized implementation: e.g. Ring buffers, linked lists with Node Object pooling... | ||
**/ | ||
function arrBuffer() { | ||
var limit = arguments.length <= 0 || arguments[0] === undefined ? Infinity : arguments[0]; | ||
function ringBuffer() { | ||
var limit = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0]; | ||
var overflowAction = arguments[1]; | ||
var arr = []; | ||
var arr = new Array(limit); | ||
var length = 0; | ||
var pushIndex = 0; | ||
var popIndex = 0; | ||
return { | ||
isEmpty: function isEmpty() { | ||
return !arr.length; | ||
return length == 0; | ||
}, | ||
put: function put(it) { | ||
if (arr.length < limit) { | ||
arr.push(it); | ||
if (length < limit) { | ||
arr[pushIndex] = it; | ||
pushIndex = (pushIndex + 1) % limit; | ||
length++; | ||
} else { | ||
@@ -39,4 +41,5 @@ switch (overflowAction) { | ||
case ON_OVERFLOW_SLIDE: | ||
arr.shift(); | ||
arr.push(it); | ||
arr[pushIndex] = it; | ||
pushIndex = (pushIndex + 1) % limit; | ||
popIndex = pushIndex; | ||
break; | ||
@@ -49,3 +52,9 @@ default: | ||
take: function take() { | ||
return arr.shift(); | ||
if (length != 0) { | ||
var it = arr[popIndex]; | ||
arr[popIndex] = null; | ||
length--; | ||
popIndex = (popIndex + 1) % limit; | ||
return it; | ||
} | ||
} | ||
@@ -60,10 +69,10 @@ }; | ||
fixed: function fixed(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_THROW); | ||
return ringBuffer(limit, ON_OVERFLOW_THROW); | ||
}, | ||
dropping: function dropping(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_DROP); | ||
return ringBuffer(limit, ON_OVERFLOW_DROP); | ||
}, | ||
sliding: function sliding(limit) { | ||
return arrBuffer(limit, ON_OVERFLOW_SLIDE); | ||
return ringBuffer(limit, ON_OVERFLOW_SLIDE); | ||
} | ||
}; |
@@ -153,2 +153,6 @@ 'use strict'; | ||
if (!_utils.is.func(unsubscribe)) { | ||
throw new Error('in eventChannel: subscribe should return a function to unsubscribe'); | ||
} | ||
return { | ||
@@ -155,0 +159,0 @@ take: chan.take, |
@@ -93,2 +93,7 @@ 'use strict'; | ||
function abort(err) { | ||
cancelAll(); | ||
cb(err, true); | ||
} | ||
function addTask(task) { | ||
@@ -104,4 +109,3 @@ tasks.push(task); | ||
if (isErr) { | ||
cancelAll(); | ||
cb(res, true); | ||
abort(res); | ||
} else { | ||
@@ -135,2 +139,3 @@ if (task === mainTask) { | ||
cancelAll: cancelAll, | ||
abort: abort, | ||
getTasks: function getTasks() { | ||
@@ -377,3 +382,3 @@ return tasks; | ||
var data = void 0; | ||
return( | ||
return ( | ||
// Non declarative effect | ||
@@ -492,11 +497,7 @@ _utils.is.promise(effect) ? resolvePromise(effect, currCb) : _utils.is.iterator(effect) ? resolveIterator(effect, effectId, name, currCb) | ||
// catch synchronous failures; see #152 | ||
// catch synchronous failures; see #152 and #441 | ||
try { | ||
result = fn.apply(context, args); | ||
} catch (err) { | ||
if (!detached) { | ||
return cb(err); | ||
} else { | ||
error = err; | ||
} | ||
error = err; | ||
} | ||
@@ -509,4 +510,4 @@ | ||
// simple effect: wrap in a generator | ||
// do not bubble up synchronous failures for detached forks, instead create a failed task. See #152 | ||
// do not bubble up synchronous failures for detached forks | ||
// instead create a failed task. See #152 and #441 | ||
else { | ||
@@ -534,10 +535,14 @@ _iterator = error ? (0, _utils.makeIterator)(function () { | ||
var task = proc(_iterator, subscribe, dispatch, getState, options, effectId, fn.name, detached ? null : _utils.noop); | ||
if (!detached) { | ||
if (detached) { | ||
cb(task); | ||
} else { | ||
if (_iterator._isRunning) { | ||
taskQueue.addTask(task); | ||
cb(task); | ||
} else if (_iterator._error) { | ||
return cb(_iterator._error, true); | ||
taskQueue.abort(_iterator._error); | ||
} else { | ||
cb(task); | ||
} | ||
} | ||
cb(task); | ||
_asap2.default.flush(); | ||
@@ -544,0 +549,0 @@ // Fork effects are non cancellables |
@@ -165,2 +165,5 @@ 'use strict'; | ||
}; | ||
var kReturn = function kReturn(value) { | ||
return { value: value, done: true }; | ||
}; | ||
function makeIterator(next) { | ||
@@ -170,3 +173,3 @@ var thro = arguments.length <= 1 || arguments[1] === undefined ? kThrow : arguments[1]; | ||
var iterator = { name: name, next: next, throw: thro }; | ||
var iterator = { name: name, next: next, throw: thro, return: kReturn }; | ||
if (typeof Symbol !== 'undefined') { | ||
@@ -173,0 +176,0 @@ iterator[Symbol.iterator] = function () { |
{ | ||
"name": "redux-saga", | ||
"version": "0.11.0", | ||
"version": "0.11.1", | ||
"description": "Saga middleware for Redux to handle Side Effects", | ||
@@ -52,10 +52,9 @@ "main": "lib/index.js", | ||
"babel-cli": "^6.1.18", | ||
"babel-core": "^6.7.6", | ||
"babel-core": "^6.14.0", | ||
"babel-eslint": "^6.0.3", | ||
"babel-loader": "^6.2.4", | ||
"babel-loader": "^6.2.5", | ||
"babel-polyfill": "^6.7.4", | ||
"babel-preset-es2015": "^6.1.18", | ||
"babel-preset-es2015-webpack": "^6.4.1", | ||
"babel-preset-react": "^6.1.18", | ||
"babel-preset-stage-2": "^6.1.18", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-react": "^6.11.1", | ||
"babel-preset-stage-2": "^6.13.0", | ||
"cross-env": "^1.0.8", | ||
@@ -62,0 +61,0 @@ "eslint": "^2.8.0", |
@@ -5,21 +5,10 @@ # redux-saga | ||
An alternative Side Effects middleware (aka Asynchronous Actions) for Redux applications. Instead of dispatching Thunks which get handled by the `redux-thunk` middleware, you create *Sagas* to gather all your Side Effects logic in a central place. | ||
`redux-saga` is a library that aims to make side effects (i.e. asynchronous things like data fetching and impure things like accessing the browser cache) in React/Redux applications easier and better. | ||
This means application logic lives in 2 places: | ||
The mental model is that a saga is like a separate thread in your application that's solely responsible for side effects. `redux-saga` is a redux middleware, which means this thread can be started, paused and cancelled from the main application with normal redux actions, it has access to the full redux application state and it can dispatch redux actions as well. | ||
- Reducers are responsible for handling state transitions between actions. | ||
- Sagas are responsible for orchestrating complex/asynchronous operations. | ||
It uses an ES6 feature called Generators to make those asynchronous flows easy to read, write and test. *(if you're not familiar with them [here are some introductory links](https://yelouafi.github.io/redux-saga/docs/ExternalResources.html))* By doing so, these asynchronous flows look like your standard synchronous JavaScript code. (kind of like `async`/`await`, but generators have a few more awesome features we need) | ||
Sagas are created using Generator functions. If you're not familiar with them you may find [some useful links here.](http://yelouafi.github.io/redux-saga/docs/ExternalResources.html) | ||
You might've used `redux-thunk` before to handle your data fetching. Contrary to redux thunk, you don't end up in callback hell, you can test your asynchronous flows easily and your actions stay pure. | ||
Unlike Thunks which get invoked on every action by Action Creators, Sagas are fired only once at the start of the application (but startup Sagas may fire other Sagas dynamically). They can be seen as Processes running in the background. Sagas watch the actions dispatched to the Store, then decide what to do based on dispatched actions: Either making an asynchronous call (like an AJAX request), dispatching other actions to the Store, or even starting other Sagas dynamically. | ||
In `redux-saga` all the above tasks are achieved by yielding **Effects**. Effects are simply JavaScript Objects containing instructions to be executed by the Saga middleware (As an analogy, you can see Redux actions as Objects containing instructions to be executed by the Store). `redux-saga` provides Effect creators for various tasks like calling an asynchronous function, dispatching an action to the Store, starting a background task or waiting for a future action that satisfies a certain condition. | ||
Using Generators, `redux-saga` allows you to write your asynchronous code in a simple synchronous style. Just like you can do with `async/await` functions. But Generators allow some things that aren't possible with `async` functions. | ||
The fact that Sagas yield plain Objects makes it easy to test all the logic inside your Generator by simply iterating over the yielded Objects and doing simple equality tests. | ||
Furthermore, tasks started in `redux-saga` can be cancelled at any moment either manually or automatically by putting them in a race with other Effects. | ||
# Getting started | ||
@@ -26,0 +15,0 @@ |
@@ -11,19 +11,22 @@ import { kTrue, noop } from './utils' | ||
/** | ||
TODO: Need to make a more optimized implementation: e.g. Ring buffers, linked lists with Node Object pooling... | ||
**/ | ||
function arrBuffer(limit = Infinity, overflowAction) { | ||
const arr = [] | ||
function ringBuffer(limit = 10, overflowAction) { | ||
const arr = new Array(limit) | ||
let length = 0 | ||
let pushIndex = 0 | ||
let popIndex = 0 | ||
return { | ||
isEmpty: () => !arr.length, | ||
isEmpty: () => length == 0, | ||
put: it => { | ||
if(arr.length < limit) { | ||
arr.push(it) | ||
if(length < limit) { | ||
arr[pushIndex] = it | ||
pushIndex = (pushIndex + 1) % limit | ||
length++ | ||
} else { | ||
switch (overflowAction) { | ||
switch(overflowAction) { | ||
case ON_OVERFLOW_THROW: | ||
throw new Error(BUFFER_OVERFLOW) | ||
case ON_OVERFLOW_SLIDE: | ||
arr.shift() | ||
arr.push(it) | ||
arr[pushIndex] = it | ||
pushIndex = (pushIndex + 1) % limit | ||
popIndex = pushIndex | ||
break | ||
@@ -35,3 +38,11 @@ default: | ||
}, | ||
take: () => arr.shift() | ||
take: () => { | ||
if(length != 0) { | ||
let it = arr[popIndex] | ||
arr[popIndex] = null | ||
length-- | ||
popIndex = (popIndex + 1) % limit | ||
return it | ||
} | ||
} | ||
} | ||
@@ -42,5 +53,5 @@ } | ||
none: () => zeroBuffer, | ||
fixed: limit => arrBuffer(limit, ON_OVERFLOW_THROW), | ||
dropping: limit => arrBuffer(limit, ON_OVERFLOW_DROP), | ||
sliding: limit => arrBuffer(limit, ON_OVERFLOW_SLIDE) | ||
fixed: limit => ringBuffer(limit, ON_OVERFLOW_THROW), | ||
dropping: limit => ringBuffer(limit, ON_OVERFLOW_DROP), | ||
sliding: limit => ringBuffer(limit, ON_OVERFLOW_SLIDE) | ||
} |
@@ -132,2 +132,6 @@ import { is, check, remove , MATCH, internalErr} from './utils' | ||
if(!is.func(unsubscribe)) { | ||
throw new Error('in eventChannel: subscribe should return a function to unsubscribe') | ||
} | ||
return { | ||
@@ -134,0 +138,0 @@ take: chan.take, |
@@ -50,2 +50,7 @@ import { noop, kTrue, is, log as _log, check, deferred, autoInc, remove, TASK, CANCEL, makeIterator } from './utils' | ||
function abort(err) { | ||
cancelAll() | ||
cb(err, true) | ||
} | ||
function addTask(task) { | ||
@@ -61,4 +66,3 @@ tasks.push(task) | ||
if(isErr) { | ||
cancelAll() | ||
cb(res, true) | ||
abort(res) | ||
} else { | ||
@@ -92,2 +96,3 @@ if(task === mainTask) { | ||
cancelAll, | ||
abort, | ||
getTasks: () => tasks, | ||
@@ -439,11 +444,7 @@ taskNames: () => tasks.map(t => t.name) | ||
// catch synchronous failures; see #152 | ||
// catch synchronous failures; see #152 and #441 | ||
try { | ||
result = fn.apply(context, args) | ||
} catch(err) { | ||
if(!detached) { | ||
return cb(err) | ||
} else { | ||
error = err | ||
} | ||
error = err | ||
} | ||
@@ -456,4 +457,4 @@ | ||
// simple effect: wrap in a generator | ||
// do not bubble up synchronous failures for detached forks, instead create a failed task. See #152 | ||
// do not bubble up synchronous failures for detached forks | ||
// instead create a failed task. See #152 and #441 | ||
else { | ||
@@ -480,10 +481,14 @@ _iterator = (error ? | ||
let task = proc(_iterator, subscribe, dispatch, getState, options, effectId, fn.name, (detached ? null : noop)) | ||
if(!detached) { | ||
if(detached) { | ||
cb(task) | ||
} else { | ||
if(_iterator._isRunning) { | ||
taskQueue.addTask(task) | ||
cb(task) | ||
} else if(_iterator._error) { | ||
return cb(_iterator._error, true) | ||
taskQueue.abort(_iterator._error) | ||
} else { | ||
cb(task) | ||
} | ||
} | ||
cb(task) | ||
asap.flush() | ||
@@ -490,0 +495,0 @@ // Fork effects are non cancellables |
@@ -53,3 +53,3 @@ export const sym = id => `@@redux-saga/${id}` | ||
const arr = [] | ||
for (var i = 0; i < length; i++) { | ||
for (let i = 0; i < length; i++) { | ||
arr.push(deferred()) | ||
@@ -92,4 +92,5 @@ } | ||
const kThrow = err => { throw err } | ||
const kReturn = value => ({value, done: true}) | ||
export function makeIterator(next, thro = kThrow, name = '') { | ||
const iterator = {name, next, throw: thro} | ||
const iterator = {name, next, throw: thro, return: kReturn} | ||
if(typeof Symbol !== 'undefined') { | ||
@@ -96,0 +97,0 @@ iterator[Symbol.iterator] = () => iterator |
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
350471
26
6164
206