redux-saga
Advanced tools
Comparing version 0.8.2 to 0.9.0
@@ -129,7 +129,8 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
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; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
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; }; | ||
exports.check = check; | ||
@@ -146,2 +147,5 @@ exports.remove = remove; | ||
var noop = exports.noop = function noop() {}; | ||
var ident = exports.ident = function ident(v) { | ||
return v; | ||
}; | ||
@@ -258,8 +262,9 @@ var isDev = exports.isDev = typeof process !== 'undefined' && process.env && ("development") === 'development'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.asEffect = exports.INVALID_PATTERN = exports.CANCEL_ARG_ERROR = exports.JOIN_ARG_ERROR = exports.FORK_ARG_ERROR = exports.CALL_FUNCTION_ARG_ERROR = undefined; | ||
exports.asEffect = exports.SELECT_ARG_ERROR = exports.INVALID_PATTERN = exports.CANCEL_ARG_ERROR = exports.JOIN_ARG_ERROR = exports.FORK_ARG_ERROR = exports.CALL_FUNCTION_ARG_ERROR = undefined; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.matcher = matcher; | ||
@@ -275,2 +280,4 @@ exports.take = take; | ||
exports.cancel = cancel; | ||
exports.select = select; | ||
exports.getState = getState; | ||
@@ -286,2 +293,3 @@ var _utils = __webpack_require__(1); | ||
var INVALID_PATTERN = exports.INVALID_PATTERN = "Invalid pattern passed to `take` (HINT: check if you didn't mispell a constant)"; | ||
var SELECT_ARG_ERROR = exports.SELECT_ARG_ERROR = "select first argument must be a function"; | ||
@@ -297,2 +305,3 @@ var IO = Symbol('IO'); | ||
var CANCEL = 'CANCEL'; | ||
var SELECT = 'SELECT'; | ||
@@ -415,2 +424,16 @@ var effect = function effect(type, payload) { | ||
function select(selector) { | ||
for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
(0, _utils.check)(selector, _utils.is.func, SELECT_ARG_ERROR); | ||
return effect(SELECT, { selector: selector, args: args }); | ||
} | ||
var getStateEff = select(_utils.ident); | ||
function getState() { | ||
return getStateEff; | ||
} | ||
var asEffect = exports.asEffect = { | ||
@@ -440,2 +463,5 @@ take: function take(effect) { | ||
return effect && effect[IO] && effect[CANCEL]; | ||
}, | ||
select: function select(effect) { | ||
return effect && effect[IO] && effect[SELECT]; | ||
} | ||
@@ -510,2 +536,4 @@ }; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -530,6 +558,8 @@ | ||
var dispatch = arguments.length <= 2 || arguments[2] === undefined ? _utils.noop : arguments[2]; | ||
var monitor = arguments.length <= 3 || arguments[3] === undefined ? _utils.noop : arguments[3]; | ||
var parentEffectId = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4]; | ||
var name = arguments.length <= 5 || arguments[5] === undefined ? 'anonymous' : arguments[5]; | ||
var getState = arguments.length <= 3 || arguments[3] === undefined ? _utils.noop : arguments[3]; | ||
var monitor = arguments.length <= 4 || arguments[4] === undefined ? _utils.noop : arguments[4]; | ||
var parentEffectId = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5]; | ||
var name = arguments.length <= 6 || arguments[6] === undefined ? 'anonymous' : arguments[6]; | ||
(0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR); | ||
@@ -708,3 +738,3 @@ | ||
// declarative effects | ||
: _utils.is.array(effect) ? runParallelEffect(effect, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.take(effect)) ? runTakeEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.put(effect)) ? runPutEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.race(effect)) ? runRaceEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.call(effect)) ? runCallEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.cps(effect)) ? runCPSEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.fork(effect)) ? runForkEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.join(effect)) ? runJoinEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.cancel(effect)) ? runCancelEffect(data, currCb) : /* anything else returned as is */currCb(null, effect) | ||
: _utils.is.array(effect) ? runParallelEffect(effect, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.take(effect)) ? runTakeEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.put(effect)) ? runPutEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.race(effect)) ? runRaceEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.call(effect)) ? runCallEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.cps(effect)) ? runCPSEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.fork(effect)) ? runForkEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.join(effect)) ? runJoinEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.cancel(effect)) ? runCancelEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.select(effect)) ? runSelectEffect(data, currCb) : /* anything else returned as is */currCb(null, effect) | ||
); | ||
@@ -726,3 +756,3 @@ } | ||
function resolveIterator(iterator, effectId, name, cb) { | ||
resolvePromise(proc(iterator, subscribe, dispatch, monitor, effectId, name).done, cb); | ||
resolvePromise(proc(iterator, subscribe, dispatch, getState, monitor, effectId, name).done, cb); | ||
} | ||
@@ -814,3 +844,3 @@ | ||
cb(null, proc(_iterator, subscribe, dispatch, monitor, effectId, fn.name, true)); | ||
cb(null, proc(_iterator, subscribe, dispatch, getState, monitor, effectId, fn.name, true)); | ||
// Fork effects are non cancellables | ||
@@ -942,6 +972,18 @@ } | ||
function runSelectEffect(_ref5, cb) { | ||
var selector = _ref5.selector; | ||
var args = _ref5.args; | ||
try { | ||
var state = selector.apply(undefined, [getState()].concat(_toConsumableArray(args))); | ||
cb(null, state); | ||
} catch (error) { | ||
cb(error); | ||
} | ||
} | ||
function newTask(id, name, iterator, done, forked) { | ||
var _ref5; | ||
var _ref6; | ||
return _ref5 = {}, _defineProperty(_ref5, _utils.TASK, true), _defineProperty(_ref5, 'id', id), _defineProperty(_ref5, 'name', name), _defineProperty(_ref5, 'done', done), _defineProperty(_ref5, 'forked', forked), _defineProperty(_ref5, 'cancel', function cancel(error) { | ||
return _ref6 = {}, _defineProperty(_ref6, _utils.TASK, true), _defineProperty(_ref6, 'id', id), _defineProperty(_ref6, 'name', name), _defineProperty(_ref6, 'done', done), _defineProperty(_ref6, 'forked', forked), _defineProperty(_ref6, 'cancel', function cancel(error) { | ||
if (!(error instanceof _SagaCancellationException2.default)) { | ||
@@ -951,9 +993,9 @@ error = new _SagaCancellationException2.default(MANUAL_CANCEL, name, error); | ||
done[CANCEL](error); | ||
}), _defineProperty(_ref5, 'isRunning', function isRunning() { | ||
}), _defineProperty(_ref6, 'isRunning', function isRunning() { | ||
return iterator._isRunning; | ||
}), _defineProperty(_ref5, 'getResult', function getResult() { | ||
}), _defineProperty(_ref6, 'getResult', function getResult() { | ||
return iterator._result; | ||
}), _defineProperty(_ref5, 'getError', function getError() { | ||
}), _defineProperty(_ref6, 'getError', function getError() { | ||
return iterator._error; | ||
}), _ref5; | ||
}), _ref6; | ||
} | ||
@@ -1006,3 +1048,3 @@ } | ||
module.exports = { take: _io.take, put: _io.put, race: _io.race, call: _io.call, apply: _io.apply, cps: _io.cps, fork: _io.fork, join: _io.join, cancel: _io.cancel }; | ||
module.exports = { take: _io.take, put: _io.put, race: _io.race, call: _io.call, apply: _io.apply, cps: _io.cps, fork: _io.fork, join: _io.join, cancel: _io.cancel, select: _io.select, getState: _io.getState }; | ||
@@ -1018,3 +1060,3 @@ /***/ }, | ||
}); | ||
exports.RUN_SAGA_DYNAMIC_ERROR = undefined; | ||
exports.RUN_SAGA_DYNAMIC_ERROR = exports.sagaArgError = undefined; | ||
exports.default = sagaMiddlewareFactory; | ||
@@ -1040,2 +1082,5 @@ | ||
var sagaArgError = exports.sagaArgError = function sagaArgError(fn, pos, saga) { | ||
return '\n ' + fn + ' can only be called on Generator functions\n Argument ' + saga + ' at position ' + pos + ' is not function!\n'; | ||
}; | ||
var RUN_SAGA_DYNAMIC_ERROR = exports.RUN_SAGA_DYNAMIC_ERROR = 'Before running a Saga dynamically using middleware.run, you must mount the Saga middleware on the Store using applyMiddleware'; | ||
@@ -1050,2 +1095,6 @@ | ||
sagas.forEach(function (saga, idx) { | ||
return (0, _utils.check)(saga, _utils.is.func, sagaArgError('createSagaMiddleware', idx, saga)); | ||
}); | ||
function sagaMiddleware(_ref) { | ||
@@ -1067,3 +1116,3 @@ var getState = _ref.getState; | ||
return (0, _proc2.default)(saga.apply(undefined, [getState].concat(args)), sagaEmitter.subscribe, dispatch, monitor, 0, saga.name); | ||
return (0, _proc2.default)(saga.apply(undefined, [getState].concat(args)), sagaEmitter.subscribe, dispatch, getState, monitor, 0, saga.name); | ||
} | ||
@@ -1078,3 +1127,3 @@ | ||
var result = next(action); // hit reducers | ||
// filter out monitor actions to avoid endless loop | ||
// filter out monitor actions to avoid endless loops | ||
// see https://github.com/yelouafi/redux-saga/issues/61 | ||
@@ -1095,2 +1144,4 @@ if (!action[_monitorActions.MONITOR_ACTION]) sagaEmitter.emit(action); | ||
} | ||
(0, _utils.check)(saga, _utils.is.func, sagaArgError('sagaMiddleware.run', 0, saga)); | ||
var task = runSagaDynamically.apply(undefined, [saga].concat(args)); | ||
@@ -1161,3 +1212,4 @@ task.done.catch(function (err) { | ||
subscribe: storeEmitter.subscribe, | ||
dispatch: store.dispatch | ||
dispatch: store.dispatch, | ||
getState: store.getState | ||
}; | ||
@@ -1171,7 +1223,9 @@ | ||
var dispatch = _ref.dispatch; | ||
var getState = _ref.getState; | ||
var monitor = arguments.length <= 2 || arguments[2] === undefined ? _utils.noop : arguments[2]; | ||
(0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR); | ||
return (0, _proc2.default)(iterator, subscribe, dispatch, monitor); | ||
return (0, _proc2.default)(iterator, subscribe, dispatch, getState, monitor); | ||
} | ||
@@ -1185,7 +1239,8 @@ | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.takeEvery = takeEvery; | ||
@@ -1192,0 +1247,0 @@ exports.takeLatest = takeLatest; |
@@ -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.takeLatest=e.takeEvery=e.storeIO=e.runSaga=e.isCancelError=e.SagaCancellationException=void 0;var o=t(9);Object.defineProperty(e,"runSaga",{enumerable:!0,get:function(){return o.runSaga}}),Object.defineProperty(e,"storeIO",{enumerable:!0,get:function(){return o.storeIO}});var a=t(10);Object.defineProperty(e,"takeEvery",{enumerable:!0,get:function(){return a.takeEvery}}),Object.defineProperty(e,"takeLatest",{enumerable:!0,get:function(){return a.takeLatest}});var i=t(8),c=u(i),f=t(2),s=u(f),l=t(7),d=r(l),v=t(12),p=r(v);e.default=c.default;var g=e.SagaCancellationException=s.default;e.isCancelError=function(n){return n instanceof g};e.effects=d,e.utils=p},function(n,e,t){(function(n){"use strict";function t(n,e,t){if(!e(n))throw new Error(t)}function r(n,e){var t=n.indexOf(e);t>=0&&n.splice(t,1)}function u(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=c({},n),t=new Promise(function(n,t){e.resolve=n,e.reject=t});return e.promise=t,e}function o(n){for(var e=[],t=0;n>t;t++)e.push(u());return e}function a(){var n=arguments.length<=0||void 0===arguments[0]?0:arguments[0];return function(){return++n}}function i(n){return Promise.resolve(1).then(function(){return n()})}var c=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};Object.defineProperty(e,"__esModule",{value:!0}),e.check=t,e.remove=r,e.deferred=u,e.arrayOfDeffered=o,e.autoInc=a,e.asap=i;var f=e.TASK=Symbol("TASK"),s=(e.kTrue=function(){return!0},e.noop=function(){},e.isDev="undefined"!=typeof n&&n.env&&!1,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},array:Array.isArray,promise:function(n){return n&&s.func(n.then)},iterator:function(n){return n&&s.func(n.next)&&s.func(n[Symbol.iterator])},"throw":function(n){return n&&s.func(n.throw)},task:function(n){return n&&n[f]}})}).call(e,t(13))},function(n,e){"use strict";function t(n,e,t){var r="SagaCancellationException; type: "+n+", saga: "+e+", origin: "+t;this.name="SagaCancellationException",this.message=r,this.type=n,this.saga=e,this.origin=t,this.stack=(new Error).stack}Object.defineProperty(e,"__esModule",{value:!0}),e.default=t,t.prototype=Object.create(Error.prototype),t.prototype.constructor=t},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){return("*"===n?j.wildcard:m.is.array(n)?j.array:m.is.func(n)?j.predicate:j.default)(n)}function o(n){if(arguments.length>0&&m.is.undef(n))throw new Error(_);return N(R,m.is.undef(n)?"*":n)}function a(n){return N(O,n)}function i(n){return N(b,n)}function c(n,e){(0,m.check)(n,m.is.notUndef,h);var t=null;if(m.is.array(n)){var r=n,u=g(r,2);t=u[0],n=u[1]}else if(n.fn){var o=n;t=o.context,n=o.fn}return(0,m.check)(n,m.is.func,h),{context:t,fn:n,args:e}}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 N(C,c(n,t))}function s(n,e){var t=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return N(C,c({context:n,fn:e},t))}function l(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return N(T,c(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 N(w,c(n,t))}function v(n){if(!I(n))throw new Error(y);return N(k,n)}function p(n){if(!I(n))throw new Error(E);return N(L,n)}var g=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")}}();Object.defineProperty(e,"__esModule",{value:!0}),e.asEffect=e.INVALID_PATTERN=e.CANCEL_ARG_ERROR=e.JOIN_ARG_ERROR=e.FORK_ARG_ERROR=e.CALL_FUNCTION_ARG_ERROR=void 0,e.matcher=u,e.take=o,e.put=a,e.race=i,e.call=f,e.apply=s,e.cps=l,e.fork=d,e.join=v,e.cancel=p;var m=t(1),h=e.CALL_FUNCTION_ARG_ERROR="call/cps/fork first argument must be a function, an array [context, function] or an object {context, fn}",y=(e.FORK_ARG_ERROR="fork first argument must be a generator function or an iterator",e.JOIN_ARG_ERROR="join argument must be a valid task (a result of a fork)"),E=e.CANCEL_ARG_ERROR="cancel argument must be a valid task (a result of a fork)",_=e.INVALID_PATTERN="Invalid pattern passed to `take` (HINT: check if you didn't mispell a constant)",A=Symbol("IO"),R="TAKE",O="PUT",b="RACE",C="CALL",T="CPS",w="FORK",k="JOIN",L="CANCEL",N=function(n,e){var t;return t={},r(t,A,!0),r(t,n,e),t},j={wildcard:function(){return m.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)}}},I=function(n){return n[m.TASK]};e.asEffect={take:function(n){return n&&n[A]&&n[R]},put:function(n){return n&&n[A]&&n[O]},race:function(n){return n&&n[A]&&n[b]},call:function(n){return n&&n[A]&&n[C]},cps:function(n){return n&&n[A]&&n[T]},fork:function(n){return n&&n[A]&&n[w]},join:function(n){return n&&n[A]&&n[k]},cancel:function(n){return n&&n[A]&&n[L]}}},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,r,u){var o;return o={},t(o,a,!0),t(o,"type",i),t(o,"effectId",n),t(o,"parentEffectId",e),t(o,"label",r),t(o,"effect",u),o}function u(n,e){var r;return r={},t(r,a,!0),t(r,"type",c),t(r,"effectId",n),t(r,"result",e),r}function o(n,e){var r;return r={},t(r,a,!0),t(r,"type",f),t(r,"effectId",n),t(r,"error",e),r}Object.defineProperty(e,"__esModule",{value:!0}),e.effectTriggered=r,e.effectResolved=u,e.effectRejected=o;var a=e.MONITOR_ACTION="MONITOR_ACTION",i=e.EFFECT_TRIGGERED="EFFECT_TRIGGERED",c=e.EFFECT_RESOLVED="EFFECT_RESOLVED",f=e.EFFECT_REJECTED="EFFECT_REJECTED"},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(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 o(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function a(n){function e(u,o){if(!n._isRunning)throw new Error("Trying to resume an already finished generator");try{if(u&&!M)throw u;var a=u?n.throw(u):n.next(o);a.done?t(a.value):r(a.value,I,"",e)}catch(u){if(t(u,!0),!(u instanceof d.default))throw u;i.isDev&&console.warn(S+": uncaught",u)}}function t(e,t){n._isRunning=!1,t?(n._error=e,U.reject(e)):(n._result=e,U.resolve(e)),D()}function r(n,e){function t(n,e){d||(d=!0,o.cancel=i.noop,j(n?s.effectRejected(a,n):s.effectResolved(a,e)),o(n,e))}var r=arguments.length<=2||void 0===arguments[2]?"":arguments[2],o=arguments[3],a=E();j(s.effectTriggered(a,e,r,n));var d=void 0;t.cancel=i.noop,o.cancel=function(n){if(!d){d=!0;try{t.cancel(n)}catch(e){}t.cancel=i.noop,o(n),j(s.effectRejected(a,n))}};var v=void 0;return i.is.promise(n)?u(n,t):i.is.iterator(n)?f(n,a,S,t):i.is.array(n)?T(n,a,t):i.is.notUndef(v=c.asEffect.take(n))?l(v,t):i.is.notUndef(v=c.asEffect.put(n))?_(v,t):i.is.notUndef(v=c.asEffect.race(n))?w(v,a,t):i.is.notUndef(v=c.asEffect.call(n))?A(v,a,t):i.is.notUndef(v=c.asEffect.cps(n))?R(v,t):i.is.notUndef(v=c.asEffect.fork(n))?O(v,a,t):i.is.notUndef(v=c.asEffect.join(n))?b(v,t):i.is.notUndef(v=c.asEffect.cancel(n))?C(v,t):t(null,n)}function u(n,e){var t=n[g];"function"==typeof t&&(e.cancel=t),n.then(function(n){return e(null,n)},function(n){return e(n)})}function f(n,e,t,r){u(a(n,L,N,j,e,t).done,r)}function l(n,e){var t={match:(0,c.matcher)(n),pattern:n,resolve:function(n){return e(null,n)}};P.push(t),e.cancel=function(){return(0,i.remove)(P,t)}}function _(n,e){(0,i.asap)(function(){return e(null,N(n))})}function A(n,e,t){var r=n.context,o=n.fn,a=n.args,c=o.apply(r,a);return i.is.promise(c)?u(c,t):i.is.iterator(c)?f(c,e,o.name,t):t(null,c)}function R(n,e){var t=n.context,r=n.fn,u=n.args;r.apply(t,u.concat(e))}function O(n,e,t){var r=n.context,u=n.fn,o=n.args,c=void 0,f=void 0;c=u.apply(r,o),f=i.is.iterator(c)?c:regeneratorRuntime.mark(function s(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,c;case 2:return n.abrupt("return",n.sent);case 3:case"end":return n.stop()}},s,this)})(),t(null,a(f,L,N,j,e,u.name,!0))}function b(n,e){u(n.done,e)}function C(n,e){n.done[g](new d.default(y,S,S)),e()}function T(n,e,t){function u(){o===c.length&&(a=!0,t(null,c))}if(!n.length)return void t(null,[]);var o=0,a=void 0,c=Array(n.length),f=n.map(function(n,e){var r=function(n,r){if(!a)if(n){try{t.cancel(new d.default(m,S,S))}catch(n){}t(n)}else c[e]=r,o++,u()};return r.cancel=i.noop,r});t.cancel=function(n){a||(a=!0,f.forEach(function(e){return e.cancel(n)}))},n.forEach(function(n,t){return r(n,e,t,f[t])})}function w(n,e,t){var u=void 0,a=Object.keys(n),c={};a.forEach(function(n){var e=function(e,r){if(!u)if(e){try{t.cancel(new d.default(h,S,S))}catch(e){}t(o({},n,e))}else{try{t.cancel(new d.default(h,S,S))}catch(e){}u=!0,t(null,o({},n,r))}};e.cancel=i.noop,c[n]=e}),t.cancel=function(n){u||(u=!0,a.forEach(function(e){return c[e].cancel(n)}))},a.forEach(function(t){return r(n[t],e,t,c[t])})}function k(n,e,t,r,u){var a;return a={},o(a,i.TASK,!0),o(a,"id",n),o(a,"name",e),o(a,"done",r),o(a,"forked",u),o(a,"cancel",function(n){n instanceof d.default||(n=new d.default(y,e,n)),r[g](n)}),o(a,"isRunning",function(){return t._isRunning}),o(a,"getResult",function(){return t._result}),o(a,"getError",function(){return t._error}),a}var L=arguments.length<=1||void 0===arguments[1]?function(){return i.noop}:arguments[1],N=arguments.length<=2||void 0===arguments[2]?i.noop:arguments[2],j=arguments.length<=3||void 0===arguments[3]?i.noop:arguments[3],I=arguments.length<=4||void 0===arguments[4]?0:arguments[4],S=arguments.length<=5||void 0===arguments[5]?"anonymous":arguments[5];(0,i.check)(n,i.is.iterator,v);var x=p(S),P=[],M=i.is.throw(n),U=(0,i.deferred)(),D=L(function(n){if(void 0===n)throw x;for(var e=0;e<P.length;e++){var t=P[e];t.match(n)&&(P=[],t.resolve(n))}});e.cancel=i.noop;var F=k(I,S,n,U.promise);return F.done[g]=function(n){var t=n.type,r=n.origin;e.cancel(new d.default(t,S,r))},n._isRunning=!0,e(),F}Object.defineProperty(e,"__esModule",{value:!0}),e.MANUAL_CANCEL=e.RACE_AUTO_CANCEL=e.PARALLEL_AUTO_CANCEL=e.CANCEL=e.undefindInputError=e.NOT_ITERATOR_ERROR=void 0,e.default=a;var i=t(1),c=t(3),f=t(4),s=u(f),l=t(2),d=r(l),v=e.NOT_ITERATOR_ERROR="proc first argument (Saga function result) must be an iterator",p=e.undefindInputError=function(n){return"\n "+n+" saga was provided with an undefined input action\n Hints :\n - check that your Action Creator returns a non undefined value\n - if the Saga was started using runSaga, check that your subscribe source provides the action to its listeners\n"},g=e.CANCEL=Symbol("@@redux-saga/cancelPromise"),m=e.PARALLEL_AUTO_CANCEL="PARALLEL_AUTO_CANCEL",h=e.RACE_AUTO_CANCEL="RACE_AUTO_CANCEL",y=e.MANUAL_CANCEL="MANUAL_CANCEL",E=(0,i.autoInc)()},function(n,e,t){"use strict";function r(){function n(n){return t.push(n),function(){return(0,u.remove)(t,n)}}function e(n){t.slice().forEach(function(e){return e(n)})}var t=[];return{subscribe:n,emit:e}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var u=t(1)},function(n,e,t){"use strict";var r=t(3);n.exports={take:r.take,put:r.put,race:r.race,call:r.call,apply:r.apply,cps:r.cps,fork:r.fork,join:r.join,cancel:r.cancel}},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(){function n(n){function e(n){for(var e=arguments.length,t=Array(e>1?e-1:0),u=1;e>u;u++)t[u-1]=arguments[u];return(0,i.default)(n.apply(void 0,[r].concat(t)),c.subscribe,a,l,0,n.name)}var r=n.getState,a=n.dispatch,c=(0,f.default)(),l=o.isDev?function(n){return(0,o.asap)(function(){return a(n)})}:void 0;return u=e,t.forEach(e),function(n){return function(e){var t=n(e);return e[s.MONITOR_ACTION]||c.emit(e),t}}}for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];var u=void 0;return n.run=function(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];if(!u)throw new Error(v);var o=u.apply(void 0,[n].concat(t));return o.done.catch(function(n){if(!(n instanceof d.default))throw n}),o},n}Object.defineProperty(e,"__esModule",{value:!0}),e.RUN_SAGA_DYNAMIC_ERROR=void 0,e.default=u;var o=t(1),a=t(5),i=r(a),c=t(6),f=r(c),s=t(4),l=t(2),d=r(l),v=e.RUN_SAGA_DYNAMIC_ERROR="Before running a Saga dynamically using middleware.run, you must mount the Saga middleware on the Store using applyMiddleware"},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n){if(a.isDev&&console.warn("storeIO is deprecated, to run Saga dynamically, use 'run' method of the middleware"),n[d])return n[d];var e=(0,s.default)(),t=n.dispatch;return n.dispatch=function(n){var r=t(n);return e.emit(n),r},n[d]={subscribe:e.subscribe,dispatch:n.dispatch},n[d]}function o(n,e){var t=e.subscribe,r=e.dispatch,u=arguments.length<=2||void 0===arguments[2]?a.noop:arguments[2];return(0,a.check)(n,a.is.iterator,l),(0,c.default)(n,t,r,u)}Object.defineProperty(e,"__esModule",{value:!0}),e.NOT_ITERATOR_ERROR=void 0,e.storeIO=u,e.runSaga=o;var a=t(1),i=t(5),c=r(i),f=t(6),s=r(f),l=e.NOT_ITERATOR_ERROR="runSaga must be called on an iterator",d=Symbol("IO")},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function o(n,e){function t(t,r){if(o)return p;if(r){if(o=!0,!(r instanceof d.default))throw r;return p}a&&a(t);var u=c(n[e],3),i=u[0],f=u[1],s=u[2];return a=s,e=v(f,t),v(i,t)}var r,o=void 0,a=void 0,i=(r={},u(r,Symbol.iterator,function(){return i}),u(r,"next",t),u(r,"throw",function(n){return t(null,n)}),r);return i}function a(n,e){for(var t=arguments.length,r=Array(t>2?t-2:0),u=2;t>u;u++)r[u-2]=arguments[u];var a={done:!1,value:(0,s.take)(n)},i=function(n){return{done:!1,value:s.fork.apply(void 0,[e].concat(r,[n]))}};return o({take:[a,"fork"],fork:[i,"take"]},"take")}function i(n,e){for(var t=arguments.length,r=Array(t>2?t-2:0),u=2;t>u;u++)r[u-2]=arguments[u];var a={done:!1,value:(0,s.take)(n)},i=function(){return{done:!1,value:s.fork.apply(void 0,[e].concat(r,[d]))}},c=function(){return{done:!1,value:(0,s.cancel)(l)}},f=function(){return l?"cancel":"fork"},l=void 0,d=void 0;return o({take:[a,f,function(n){return d=n}],cancel:[c,"fork"],fork:[i,"take",function(n){return l=n}]},"take")}var c=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")}}();Object.defineProperty(e,"__esModule",{value:!0}),e.takeEvery=a,e.takeLatest=i;var f=t(1),s=t(3),l=t(2),d=r(l),v=function(n,e){return f.is.func(n)?n(e):n},p={done:!0}},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(){var n,e=!0,t=void 0,u=void 0;return n={},r(n,o.TASK,!0),r(n,"isRunning",function(){return e}),r(n,"getResult",function(){return t}),r(n,"getError",function(){return u}),r(n,"setRunning",function(n){return e=n}),r(n,"setResult",function(n){return t=n}),r(n,"setError",function(n){return u=n}),n}Object.defineProperty(e,"__esModule",{value:!0}),e.createMockTask=u;var o=t(1)},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}var u=t(1),o=t(3),a=t(5),i=t(11),c=t(4),f=r(c);n.exports={TASK:u.TASK,noop:u.noop,is:u.is,asEffect:o.asEffect,deferred:u.deferred,arrayOfDeffered:u.arrayOfDeffered,asap:u.asap,CANCEL:a.CANCEL,RACE_AUTO_CANCEL:a.RACE_AUTO_CANCEL,PARALLEL_AUTO_CANCEL:a.PARALLEL_AUTO_CANCEL,MANUAL_CANCEL:a.MANUAL_CANCEL,createMockTask:i.createMockTask,monitorActions:f}},function(n,e){function t(){f=!1,a.length?c=a.concat(c):s=-1,c.length&&r()}function r(){if(!f){var n=setTimeout(t);f=!0;for(var e=c.length;e;){for(a=c,c=[];++s<e;)a&&a[s].run();s=-1,e=c.length}a=null,f=!1,clearTimeout(n)}}function u(n,e){this.fun=n,this.array=e}function o(){}var a,i=n.exports={},c=[],f=!1,s=-1;i.nextTick=function(n){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];c.push(new u(n,e)),1!==c.length||f||setTimeout(r,0)},u.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=o,i.addListener=o,i.once=o,i.off=o,i.removeListener=o,i.removeAllListeners=o,i.emit=o,i.binding=function(n){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(n){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}])}); | ||
!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.takeLatest=e.takeEvery=e.storeIO=e.runSaga=e.isCancelError=e.SagaCancellationException=void 0;var o=t(9);Object.defineProperty(e,"runSaga",{enumerable:!0,get:function(){return o.runSaga}}),Object.defineProperty(e,"storeIO",{enumerable:!0,get:function(){return o.storeIO}});var a=t(10);Object.defineProperty(e,"takeEvery",{enumerable:!0,get:function(){return a.takeEvery}}),Object.defineProperty(e,"takeLatest",{enumerable:!0,get:function(){return a.takeLatest}});var i=t(8),c=u(i),f=t(2),s=u(f),l=t(7),d=r(l),v=t(12),g=r(v);e.default=c.default;var p=e.SagaCancellationException=s.default;e.isCancelError=function(n){return n instanceof p};e.effects=d,e.utils=g},function(n,e,t){(function(n){"use strict";function t(n,e,t){if(!e(n))throw new Error(t)}function r(n,e){var t=n.indexOf(e);t>=0&&n.splice(t,1)}function u(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=c({},n),t=new Promise(function(n,t){e.resolve=n,e.reject=t});return e.promise=t,e}function o(n){for(var e=[],t=0;n>t;t++)e.push(u());return e}function a(){var n=arguments.length<=0||void 0===arguments[0]?0:arguments[0];return function(){return++n}}function i(n){return Promise.resolve(1).then(function(){return n()})}Object.defineProperty(e,"__esModule",{value:!0});var c=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};e.check=t,e.remove=r,e.deferred=u,e.arrayOfDeffered=o,e.autoInc=a,e.asap=i;var f=e.TASK=Symbol("TASK"),s=(e.kTrue=function(){return!0},e.noop=function(){},e.ident=function(n){return n},e.isDev="undefined"!=typeof n&&n.env&&!1,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},array:Array.isArray,promise:function(n){return n&&s.func(n.then)},iterator:function(n){return n&&s.func(n.next)&&s.func(n[Symbol.iterator])},"throw":function(n){return n&&s.func(n.throw)},task:function(n){return n&&n[f]}})}).call(e,t(13))},function(n,e){"use strict";function t(n,e,t){var r="SagaCancellationException; type: "+n+", saga: "+e+", origin: "+t;this.name="SagaCancellationException",this.message=r,this.type=n,this.saga=e,this.origin=t,this.stack=(new Error).stack}Object.defineProperty(e,"__esModule",{value:!0}),e.default=t,t.prototype=Object.create(Error.prototype),t.prototype.constructor=t},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){return("*"===n?P.wildcard:h.is.array(n)?P.array:h.is.func(n)?P.predicate:P.default)(n)}function o(n){if(arguments.length>0&&h.is.undef(n))throw new Error(R);return x(C,h.is.undef(n)?"*":n)}function a(n){return x(T,n)}function i(n){return x(w,n)}function c(n,e){(0,h.check)(n,h.is.notUndef,y);var t=null;if(h.is.array(n)){var r=n,u=E(r,2);t=u[0],n=u[1]}else if(n.fn){var o=n;t=o.context,n=o.fn}return(0,h.check)(n,h.is.func,y),{context:t,fn:n,args:e}}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 x(k,c(n,t))}function s(n,e){var t=arguments.length<=2||void 0===arguments[2]?[]:arguments[2];return x(k,c({context:n,fn:e},t))}function l(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];return x(L,c(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 x(N,c(n,t))}function v(n){if(!M(n))throw new Error(A);return x(S,n)}function g(n){if(!M(n))throw new Error(_);return x(j,n)}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];return(0,h.check)(n,h.is.func,O),x(I,{selector:n,args:t})}function m(){return U}Object.defineProperty(e,"__esModule",{value:!0}),e.asEffect=e.SELECT_ARG_ERROR=e.INVALID_PATTERN=e.CANCEL_ARG_ERROR=e.JOIN_ARG_ERROR=e.FORK_ARG_ERROR=e.CALL_FUNCTION_ARG_ERROR=void 0;var E=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.matcher=u,e.take=o,e.put=a,e.race=i,e.call=f,e.apply=s,e.cps=l,e.fork=d,e.join=v,e.cancel=g,e.select=p,e.getState=m;var h=t(1),y=e.CALL_FUNCTION_ARG_ERROR="call/cps/fork first argument must be a function, an array [context, function] or an object {context, fn}",A=(e.FORK_ARG_ERROR="fork first argument must be a generator function or an iterator",e.JOIN_ARG_ERROR="join argument must be a valid task (a result of a fork)"),_=e.CANCEL_ARG_ERROR="cancel argument must be a valid task (a result of a fork)",R=e.INVALID_PATTERN="Invalid pattern passed to `take` (HINT: check if you didn't mispell a constant)",O=e.SELECT_ARG_ERROR="select first argument must be a function",b=Symbol("IO"),C="TAKE",T="PUT",w="RACE",k="CALL",L="CPS",N="FORK",S="JOIN",j="CANCEL",I="SELECT",x=function(n,e){var t;return t={},r(t,b,!0),r(t,n,e),t},P={wildcard:function(){return h.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)}}},M=function(n){return n[h.TASK]},U=p(h.ident);e.asEffect={take:function(n){return n&&n[b]&&n[C]},put:function(n){return n&&n[b]&&n[T]},race:function(n){return n&&n[b]&&n[w]},call:function(n){return n&&n[b]&&n[k]},cps:function(n){return n&&n[b]&&n[L]},fork:function(n){return n&&n[b]&&n[N]},join:function(n){return n&&n[b]&&n[S]},cancel:function(n){return n&&n[b]&&n[j]},select:function(n){return n&&n[b]&&n[I]}}},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,r,u){var o;return o={},t(o,a,!0),t(o,"type",i),t(o,"effectId",n),t(o,"parentEffectId",e),t(o,"label",r),t(o,"effect",u),o}function u(n,e){var r;return r={},t(r,a,!0),t(r,"type",c),t(r,"effectId",n),t(r,"result",e),r}function o(n,e){var r;return r={},t(r,a,!0),t(r,"type",f),t(r,"effectId",n),t(r,"error",e),r}Object.defineProperty(e,"__esModule",{value:!0}),e.effectTriggered=r,e.effectResolved=u,e.effectRejected=o;var a=e.MONITOR_ACTION="MONITOR_ACTION",i=e.EFFECT_TRIGGERED="EFFECT_TRIGGERED",c=e.EFFECT_RESOLVED="EFFECT_RESOLVED",f=e.EFFECT_REJECTED="EFFECT_REJECTED"},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(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 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){function e(u,o){if(!n._isRunning)throw new Error("Trying to resume an already finished generator");try{if(u&&!F)throw u;var a=u?n.throw(u):n.next(o);a.done?t(a.value):r(a.value,P,"",e)}catch(u){if(t(u,!0),!(u instanceof v.default))throw u;c.isDev&&console.warn(M+": uncaught",u)}}function t(e,t){n._isRunning=!1,t?(n._error=e,G.reject(e)):(n._result=e,G.resolve(e)),K()}function r(n,e){function t(n,e){i||(i=!0,o.cancel=c.noop,x(n?l.effectRejected(a,n):l.effectResolved(a,e)),o(n,e))}var r=arguments.length<=2||void 0===arguments[2]?"":arguments[2],o=arguments[3],a=A();x(l.effectTriggered(a,e,r,n));var i=void 0;t.cancel=c.noop,o.cancel=function(n){if(!i){i=!0;try{t.cancel(n)}catch(e){}t.cancel=c.noop,o(n),x(l.effectRejected(a,n))}};var v=void 0;return c.is.promise(n)?u(n,t):c.is.iterator(n)?s(n,a,M,t):c.is.array(n)?w(n,a,t):c.is.notUndef(v=f.asEffect.take(n))?d(v,t):c.is.notUndef(v=f.asEffect.put(n))?_(v,t):c.is.notUndef(v=f.asEffect.race(n))?k(v,a,t):c.is.notUndef(v=f.asEffect.call(n))?R(v,a,t):c.is.notUndef(v=f.asEffect.cps(n))?O(v,t):c.is.notUndef(v=f.asEffect.fork(n))?b(v,a,t):c.is.notUndef(v=f.asEffect.join(n))?C(v,t):c.is.notUndef(v=f.asEffect.cancel(n))?T(v,t):c.is.notUndef(v=f.asEffect.select(n))?L(v,t):t(null,n)}function u(n,e){var t=n[m];"function"==typeof t&&(e.cancel=t),n.then(function(n){return e(null,n)},function(n){return e(n)})}function s(n,e,t,r){u(i(n,S,j,I,x,e,t).done,r)}function d(n,e){var t={match:(0,f.matcher)(n),pattern:n,resolve:function(n){return e(null,n)}};D.push(t),e.cancel=function(){return(0,c.remove)(D,t)}}function _(n,e){(0,c.asap)(function(){return e(null,j(n))})}function R(n,e,t){var r=n.context,o=n.fn,a=n.args,i=o.apply(r,a);return c.is.promise(i)?u(i,t):c.is.iterator(i)?s(i,e,o.name,t):t(null,i)}function O(n,e){var t=n.context,r=n.fn,u=n.args;r.apply(t,u.concat(e))}function b(n,e,t){var r=n.context,u=n.fn,o=n.args,a=void 0,f=void 0;a=u.apply(r,o),f=c.is.iterator(a)?a:regeneratorRuntime.mark(function s(){return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,a;case 2:return n.abrupt("return",n.sent);case 3:case"end":return n.stop()}},s,this)})(),t(null,i(f,S,j,I,x,e,u.name,!0))}function C(n,e){u(n.done,e)}function T(n,e){n.done[m](new v.default(y,M,M)),e()}function w(n,e,t){function u(){o===i.length&&(a=!0,t(null,i))}if(!n.length)return void t(null,[]);var o=0,a=void 0,i=Array(n.length),f=n.map(function(n,e){var r=function(n,r){if(!a)if(n){try{t.cancel(new v.default(E,M,M))}catch(n){}t(n)}else i[e]=r,o++,u()};return r.cancel=c.noop,r});t.cancel=function(n){a||(a=!0,f.forEach(function(e){return e.cancel(n)}))},n.forEach(function(n,t){return r(n,e,t,f[t])})}function k(n,e,t){var u=void 0,o=Object.keys(n),i={};o.forEach(function(n){var e=function(e,r){if(!u)if(e){try{t.cancel(new v.default(h,M,M))}catch(e){}t(a({},n,e))}else{try{t.cancel(new v.default(h,M,M))}catch(e){}u=!0,t(null,a({},n,r))}};e.cancel=c.noop,i[n]=e}),t.cancel=function(n){u||(u=!0,o.forEach(function(e){return i[e].cancel(n)}))},o.forEach(function(t){return r(n[t],e,t,i[t])})}function L(n,e){var t=n.selector,r=n.args;try{var u=t.apply(void 0,[I()].concat(o(r)));e(null,u)}catch(a){e(a)}}function N(n,e,t,r,u){var o;return o={},a(o,c.TASK,!0),a(o,"id",n),a(o,"name",e),a(o,"done",r),a(o,"forked",u),a(o,"cancel",function(n){n instanceof v.default||(n=new v.default(y,e,n)),r[m](n)}),a(o,"isRunning",function(){return t._isRunning}),a(o,"getResult",function(){return t._result}),a(o,"getError",function(){return t._error}),o}var S=arguments.length<=1||void 0===arguments[1]?function(){return c.noop}:arguments[1],j=arguments.length<=2||void 0===arguments[2]?c.noop:arguments[2],I=arguments.length<=3||void 0===arguments[3]?c.noop:arguments[3],x=arguments.length<=4||void 0===arguments[4]?c.noop:arguments[4],P=arguments.length<=5||void 0===arguments[5]?0:arguments[5],M=arguments.length<=6||void 0===arguments[6]?"anonymous":arguments[6];(0,c.check)(n,c.is.iterator,g);var U=p(M),D=[],F=c.is.throw(n),G=(0,c.deferred)(),K=S(function(n){if(void 0===n)throw U;for(var e=0;e<D.length;e++){var t=D[e];t.match(n)&&(D=[],t.resolve(n))}});e.cancel=c.noop;var J=N(P,M,n,G.promise);return J.done[m]=function(n){var t=n.type,r=n.origin;e.cancel(new v.default(t,M,r))},n._isRunning=!0,e(),J}Object.defineProperty(e,"__esModule",{value:!0}),e.MANUAL_CANCEL=e.RACE_AUTO_CANCEL=e.PARALLEL_AUTO_CANCEL=e.CANCEL=e.undefindInputError=e.NOT_ITERATOR_ERROR=void 0,e.default=i;var c=t(1),f=t(3),s=t(4),l=u(s),d=t(2),v=r(d),g=e.NOT_ITERATOR_ERROR="proc first argument (Saga function result) must be an iterator",p=e.undefindInputError=function(n){return"\n "+n+" saga was provided with an undefined input action\n Hints :\n - check that your Action Creator returns a non undefined value\n - if the Saga was started using runSaga, check that your subscribe source provides the action to its listeners\n"},m=e.CANCEL=Symbol("@@redux-saga/cancelPromise"),E=e.PARALLEL_AUTO_CANCEL="PARALLEL_AUTO_CANCEL",h=e.RACE_AUTO_CANCEL="RACE_AUTO_CANCEL",y=e.MANUAL_CANCEL="MANUAL_CANCEL",A=(0,c.autoInc)()},function(n,e,t){"use strict";function r(){function n(n){return t.push(n),function(){return(0,u.remove)(t,n)}}function e(n){t.slice().forEach(function(e){return e(n)})}var t=[];return{subscribe:n,emit:e}}Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var u=t(1)},function(n,e,t){"use strict";var r=t(3);n.exports={take:r.take,put:r.put,race:r.race,call:r.call,apply:r.apply,cps:r.cps,fork:r.fork,join:r.join,cancel:r.cancel,select:r.select,getState:r.getState}},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(){function n(n){function e(n){for(var e=arguments.length,t=Array(e>1?e-1:0),u=1;e>u;u++)t[u-1]=arguments[u];return(0,i.default)(n.apply(void 0,[r].concat(t)),c.subscribe,a,r,l,0,n.name)}var r=n.getState,a=n.dispatch,c=(0,f.default)(),l=o.isDev?function(n){return(0,o.asap)(function(){return a(n)})}:void 0;return u=e,t.forEach(e),function(n){return function(e){var t=n(e);return e[s.MONITOR_ACTION]||c.emit(e),t}}}for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];var u=void 0;return t.forEach(function(n,e){return(0,o.check)(n,o.is.func,v("createSagaMiddleware",e,n))}),n.run=function(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;e>r;r++)t[r-1]=arguments[r];if(!u)throw new Error(g);(0,o.check)(n,o.is.func,v("sagaMiddleware.run",0,n));var a=u.apply(void 0,[n].concat(t));return a.done.catch(function(n){if(!(n instanceof d.default))throw n}),a},n}Object.defineProperty(e,"__esModule",{value:!0}),e.RUN_SAGA_DYNAMIC_ERROR=e.sagaArgError=void 0,e.default=u;var o=t(1),a=t(5),i=r(a),c=t(6),f=r(c),s=t(4),l=t(2),d=r(l),v=e.sagaArgError=function(n,e,t){return"\n "+n+" can only be called on Generator functions\n Argument "+t+" at position "+e+" is not function!\n"},g=e.RUN_SAGA_DYNAMIC_ERROR="Before running a Saga dynamically using middleware.run, you must mount the Saga middleware on the Store using applyMiddleware"},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n){if(a.isDev&&console.warn("storeIO is deprecated, to run Saga dynamically, use 'run' method of the middleware"),n[d])return n[d];var e=(0,s.default)(),t=n.dispatch;return n.dispatch=function(n){var r=t(n);return e.emit(n),r},n[d]={subscribe:e.subscribe,dispatch:n.dispatch,getState:n.getState},n[d]}function o(n,e){var t=e.subscribe,r=e.dispatch,u=e.getState,o=arguments.length<=2||void 0===arguments[2]?a.noop:arguments[2];return(0,a.check)(n,a.is.iterator,l),(0,c.default)(n,t,r,u,o)}Object.defineProperty(e,"__esModule",{value:!0}),e.NOT_ITERATOR_ERROR=void 0,e.storeIO=u,e.runSaga=o;var a=t(1),i=t(5),c=r(i),f=t(6),s=r(f),l=e.NOT_ITERATOR_ERROR="runSaga must be called on an iterator",d=Symbol("IO")},function(n,e,t){"use strict";function r(n){return n&&n.__esModule?n:{"default":n}}function u(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}function o(n,e){function t(t,r){if(o)return g;if(r){if(o=!0,!(r instanceof d.default))throw r;return g}a&&a(t);var u=c(n[e],3),i=u[0],f=u[1],s=u[2];return a=s,e=v(f,t),v(i,t)}var r,o=void 0,a=void 0,i=(r={},u(r,Symbol.iterator,function(){return i}),u(r,"next",t),u(r,"throw",function(n){return t(null,n)}),r);return i}function a(n,e){for(var t=arguments.length,r=Array(t>2?t-2:0),u=2;t>u;u++)r[u-2]=arguments[u];var a={done:!1,value:(0,s.take)(n)},i=function(n){return{done:!1,value:s.fork.apply(void 0,[e].concat(r,[n]))}};return o({take:[a,"fork"],fork:[i,"take"]},"take")}function i(n,e){for(var t=arguments.length,r=Array(t>2?t-2:0),u=2;t>u;u++)r[u-2]=arguments[u];var a={done:!1,value:(0,s.take)(n)},i=function(){return{done:!1,value:s.fork.apply(void 0,[e].concat(r,[d]))}},c=function(){return{done:!1,value:(0,s.cancel)(l)}},f=function(){return l?"cancel":"fork"},l=void 0,d=void 0;return o({take:[a,f,function(n){return d=n}],cancel:[c,"fork"],fork:[i,"take",function(n){return l=n}]},"take")}Object.defineProperty(e,"__esModule",{value:!0});var c=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=a,e.takeLatest=i;var f=t(1),s=t(3),l=t(2),d=r(l),v=function(n,e){return f.is.func(n)?n(e):n},g={done:!0}},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(){var n,e=!0,t=void 0,u=void 0;return n={},r(n,o.TASK,!0),r(n,"isRunning",function(){return e}),r(n,"getResult",function(){return t}),r(n,"getError",function(){return u}),r(n,"setRunning",function(n){return e=n}),r(n,"setResult",function(n){return t=n}),r(n,"setError",function(n){return u=n}),n}Object.defineProperty(e,"__esModule",{value:!0}),e.createMockTask=u;var o=t(1)},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}var u=t(1),o=t(3),a=t(5),i=t(11),c=t(4),f=r(c);n.exports={TASK:u.TASK,noop:u.noop,is:u.is,asEffect:o.asEffect,deferred:u.deferred,arrayOfDeffered:u.arrayOfDeffered,asap:u.asap,CANCEL:a.CANCEL,RACE_AUTO_CANCEL:a.RACE_AUTO_CANCEL,PARALLEL_AUTO_CANCEL:a.PARALLEL_AUTO_CANCEL,MANUAL_CANCEL:a.MANUAL_CANCEL,createMockTask:i.createMockTask,monitorActions:f}},function(n,e){function t(){f=!1,a.length?c=a.concat(c):s=-1,c.length&&r()}function r(){if(!f){var n=setTimeout(t);f=!0;for(var e=c.length;e;){for(a=c,c=[];++s<e;)a&&a[s].run();s=-1,e=c.length}a=null,f=!1,clearTimeout(n)}}function u(n,e){this.fun=n,this.array=e}function o(){}var a,i=n.exports={},c=[],f=!1,s=-1;i.nextTick=function(n){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];c.push(new u(n,e)),1!==c.length||f||setTimeout(r,0)},u.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=o,i.addListener=o,i.once=o,i.off=o,i.removeListener=o,i.removeAllListeners=o,i.emit=o,i.binding=function(n){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(n){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}])}); |
@@ -5,2 +5,2 @@ 'use strict'; | ||
module.exports = { take: _io.take, put: _io.put, race: _io.race, call: _io.call, apply: _io.apply, cps: _io.cps, fork: _io.fork, join: _io.join, cancel: _io.cancel }; | ||
module.exports = { take: _io.take, put: _io.put, race: _io.race, call: _io.call, apply: _io.apply, cps: _io.cps, fork: _io.fork, join: _io.join, cancel: _io.cancel, select: _io.select, getState: _io.getState }; |
"use strict"; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.asEffect = exports.INVALID_PATTERN = exports.CANCEL_ARG_ERROR = exports.JOIN_ARG_ERROR = exports.FORK_ARG_ERROR = exports.CALL_FUNCTION_ARG_ERROR = undefined; | ||
exports.asEffect = exports.SELECT_ARG_ERROR = exports.INVALID_PATTERN = exports.CANCEL_ARG_ERROR = exports.JOIN_ARG_ERROR = exports.FORK_ARG_ERROR = exports.CALL_FUNCTION_ARG_ERROR = undefined; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.matcher = matcher; | ||
@@ -19,2 +20,4 @@ exports.take = take; | ||
exports.cancel = cancel; | ||
exports.select = select; | ||
exports.getState = getState; | ||
@@ -30,2 +33,3 @@ var _utils = require("./utils"); | ||
var INVALID_PATTERN = exports.INVALID_PATTERN = "Invalid pattern passed to `take` (HINT: check if you didn't mispell a constant)"; | ||
var SELECT_ARG_ERROR = exports.SELECT_ARG_ERROR = "select first argument must be a function"; | ||
@@ -41,2 +45,3 @@ var IO = Symbol('IO'); | ||
var CANCEL = 'CANCEL'; | ||
var SELECT = 'SELECT'; | ||
@@ -159,2 +164,16 @@ var effect = function effect(type, payload) { | ||
function select(selector) { | ||
for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
(0, _utils.check)(selector, _utils.is.func, SELECT_ARG_ERROR); | ||
return effect(SELECT, { selector: selector, args: args }); | ||
} | ||
var getStateEff = select(_utils.ident); | ||
function getState() { | ||
return getStateEff; | ||
} | ||
var asEffect = exports.asEffect = { | ||
@@ -184,3 +203,6 @@ take: function take(effect) { | ||
return effect && effect[IO] && effect[CANCEL]; | ||
}, | ||
select: function select(effect) { | ||
return effect && effect[IO] && effect[SELECT]; | ||
} | ||
}; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.RUN_SAGA_DYNAMIC_ERROR = undefined; | ||
exports.RUN_SAGA_DYNAMIC_ERROR = exports.sagaArgError = undefined; | ||
exports.default = sagaMiddlewareFactory; | ||
@@ -28,2 +28,5 @@ | ||
var sagaArgError = exports.sagaArgError = function sagaArgError(fn, pos, saga) { | ||
return '\n ' + fn + ' can only be called on Generator functions\n Argument ' + saga + ' at position ' + pos + ' is not function!\n'; | ||
}; | ||
var RUN_SAGA_DYNAMIC_ERROR = exports.RUN_SAGA_DYNAMIC_ERROR = 'Before running a Saga dynamically using middleware.run, you must mount the Saga middleware on the Store using applyMiddleware'; | ||
@@ -38,2 +41,6 @@ | ||
sagas.forEach(function (saga, idx) { | ||
return (0, _utils.check)(saga, _utils.is.func, sagaArgError('createSagaMiddleware', idx, saga)); | ||
}); | ||
function sagaMiddleware(_ref) { | ||
@@ -55,3 +62,3 @@ var getState = _ref.getState; | ||
return (0, _proc2.default)(saga.apply(undefined, [getState].concat(args)), sagaEmitter.subscribe, dispatch, monitor, 0, saga.name); | ||
return (0, _proc2.default)(saga.apply(undefined, [getState].concat(args)), sagaEmitter.subscribe, dispatch, getState, monitor, 0, saga.name); | ||
} | ||
@@ -66,3 +73,3 @@ | ||
var result = next(action); // hit reducers | ||
// filter out monitor actions to avoid endless loop | ||
// filter out monitor actions to avoid endless loops | ||
// see https://github.com/yelouafi/redux-saga/issues/61 | ||
@@ -83,2 +90,4 @@ if (!action[_monitorActions.MONITOR_ACTION]) sagaEmitter.emit(action); | ||
} | ||
(0, _utils.check)(saga, _utils.is.func, sagaArgError('sagaMiddleware.run', 0, saga)); | ||
var task = runSagaDynamically.apply(undefined, [saga].concat(args)); | ||
@@ -85,0 +94,0 @@ task.done.catch(function (err) { |
@@ -25,2 +25,4 @@ 'use strict'; | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -45,6 +47,8 @@ | ||
var dispatch = arguments.length <= 2 || arguments[2] === undefined ? _utils.noop : arguments[2]; | ||
var monitor = arguments.length <= 3 || arguments[3] === undefined ? _utils.noop : arguments[3]; | ||
var parentEffectId = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4]; | ||
var name = arguments.length <= 5 || arguments[5] === undefined ? 'anonymous' : arguments[5]; | ||
var getState = arguments.length <= 3 || arguments[3] === undefined ? _utils.noop : arguments[3]; | ||
var monitor = arguments.length <= 4 || arguments[4] === undefined ? _utils.noop : arguments[4]; | ||
var parentEffectId = arguments.length <= 5 || arguments[5] === undefined ? 0 : arguments[5]; | ||
var name = arguments.length <= 6 || arguments[6] === undefined ? 'anonymous' : arguments[6]; | ||
(0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR); | ||
@@ -223,3 +227,3 @@ | ||
// declarative effects | ||
: _utils.is.array(effect) ? runParallelEffect(effect, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.take(effect)) ? runTakeEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.put(effect)) ? runPutEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.race(effect)) ? runRaceEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.call(effect)) ? runCallEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.cps(effect)) ? runCPSEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.fork(effect)) ? runForkEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.join(effect)) ? runJoinEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.cancel(effect)) ? runCancelEffect(data, currCb) : /* anything else returned as is */currCb(null, effect) | ||
: _utils.is.array(effect) ? runParallelEffect(effect, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.take(effect)) ? runTakeEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.put(effect)) ? runPutEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.race(effect)) ? runRaceEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.call(effect)) ? runCallEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.cps(effect)) ? runCPSEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.fork(effect)) ? runForkEffect(data, effectId, currCb) : _utils.is.notUndef(data = _io.asEffect.join(effect)) ? runJoinEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.cancel(effect)) ? runCancelEffect(data, currCb) : _utils.is.notUndef(data = _io.asEffect.select(effect)) ? runSelectEffect(data, currCb) : /* anything else returned as is */currCb(null, effect) | ||
); | ||
@@ -241,3 +245,3 @@ } | ||
function resolveIterator(iterator, effectId, name, cb) { | ||
resolvePromise(proc(iterator, subscribe, dispatch, monitor, effectId, name).done, cb); | ||
resolvePromise(proc(iterator, subscribe, dispatch, getState, monitor, effectId, name).done, cb); | ||
} | ||
@@ -329,3 +333,3 @@ | ||
cb(null, proc(_iterator, subscribe, dispatch, monitor, effectId, fn.name, true)); | ||
cb(null, proc(_iterator, subscribe, dispatch, getState, monitor, effectId, fn.name, true)); | ||
// Fork effects are non cancellables | ||
@@ -457,6 +461,18 @@ } | ||
function runSelectEffect(_ref5, cb) { | ||
var selector = _ref5.selector; | ||
var args = _ref5.args; | ||
try { | ||
var state = selector.apply(undefined, [getState()].concat(_toConsumableArray(args))); | ||
cb(null, state); | ||
} catch (error) { | ||
cb(error); | ||
} | ||
} | ||
function newTask(id, name, iterator, done, forked) { | ||
var _ref5; | ||
var _ref6; | ||
return _ref5 = {}, _defineProperty(_ref5, _utils.TASK, true), _defineProperty(_ref5, 'id', id), _defineProperty(_ref5, 'name', name), _defineProperty(_ref5, 'done', done), _defineProperty(_ref5, 'forked', forked), _defineProperty(_ref5, 'cancel', function cancel(error) { | ||
return _ref6 = {}, _defineProperty(_ref6, _utils.TASK, true), _defineProperty(_ref6, 'id', id), _defineProperty(_ref6, 'name', name), _defineProperty(_ref6, 'done', done), _defineProperty(_ref6, 'forked', forked), _defineProperty(_ref6, 'cancel', function cancel(error) { | ||
if (!(error instanceof _SagaCancellationException2.default)) { | ||
@@ -466,10 +482,10 @@ error = new _SagaCancellationException2.default(MANUAL_CANCEL, name, error); | ||
done[CANCEL](error); | ||
}), _defineProperty(_ref5, 'isRunning', function isRunning() { | ||
}), _defineProperty(_ref6, 'isRunning', function isRunning() { | ||
return iterator._isRunning; | ||
}), _defineProperty(_ref5, 'getResult', function getResult() { | ||
}), _defineProperty(_ref6, 'getResult', function getResult() { | ||
return iterator._result; | ||
}), _defineProperty(_ref5, 'getError', function getError() { | ||
}), _defineProperty(_ref6, 'getError', function getError() { | ||
return iterator._error; | ||
}), _ref5; | ||
}), _ref6; | ||
} | ||
} |
@@ -52,3 +52,4 @@ 'use strict'; | ||
subscribe: storeEmitter.subscribe, | ||
dispatch: store.dispatch | ||
dispatch: store.dispatch, | ||
getState: store.getState | ||
}; | ||
@@ -62,7 +63,9 @@ | ||
var dispatch = _ref.dispatch; | ||
var getState = _ref.getState; | ||
var monitor = arguments.length <= 2 || arguments[2] === undefined ? _utils.noop : arguments[2]; | ||
(0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR); | ||
return (0, _proc2.default)(iterator, subscribe, dispatch, monitor); | ||
return (0, _proc2.default)(iterator, subscribe, dispatch, getState, monitor); | ||
} |
'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
exports.takeEvery = takeEvery; | ||
@@ -9,0 +10,0 @@ exports.takeLatest = takeLatest; |
'use strict'; | ||
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; }; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
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; }; | ||
exports.check = check; | ||
@@ -19,2 +20,5 @@ exports.remove = remove; | ||
var noop = exports.noop = function noop() {}; | ||
var ident = exports.ident = function ident(v) { | ||
return v; | ||
}; | ||
@@ -21,0 +25,0 @@ var isDev = exports.isDev = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development'; |
{ | ||
"name": "redux-saga", | ||
"version": "0.8.2", | ||
"version": "0.9.0", | ||
"description": "Saga middleware for Redux to handle Side Effects", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
# redux-saga | ||
[![npm version](https://img.shields.io/npm/v/redux-saga.svg?style=flat-square)](https://www.npmjs.com/package/redux-saga) | ||
[![Join the chat at https://gitter.im/yelouafi/redux-saga](https://badges.gitter.im/yelouafi/redux-saga.svg)](https://gitter.im/yelouafi/redux-saga?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[![npm version](https://img.shields.io/npm/v/redux-saga.svg?style=flat-square)](https://www.npmjs.com/package/redux-saga) | ||
@@ -114,3 +115,3 @@ An alternative Side Effects middleware (aka Asynchronous Actions) for Redux applications. | ||
import { createStore, applyMiddleware } from 'redux' | ||
import createSagaMiddleware from `redux-saga` | ||
import createSagaMiddleware from 'redux-saga' | ||
@@ -117,0 +118,0 @@ import reducer from './reducers' |
import { take, put, race, call, apply, cps, fork, join, cancel } from './internal/io' | ||
import { take, put, race, call, apply, cps, fork, join, cancel, select, getState } from './internal/io' | ||
module.exports = { take, put, race, call, apply, cps, fork, join, cancel } | ||
module.exports = { take, put, race, call, apply, cps, fork, join, cancel, select, getState } |
@@ -1,9 +0,10 @@ | ||
import { is, kTrue, check, TASK } from './utils' | ||
import { is, kTrue, ident, check, TASK } from './utils' | ||
export const CALL_FUNCTION_ARG_ERROR = "call/cps/fork first argument must be a function, an array [context, function] or an object {context, fn}" | ||
export const FORK_ARG_ERROR = "fork first argument must be a generator function or an iterator" | ||
export const JOIN_ARG_ERROR = "join argument must be a valid task (a result of a fork)" | ||
export const FORK_ARG_ERROR = "fork first argument must be a generator function or an iterator" | ||
export const JOIN_ARG_ERROR = "join argument must be a valid task (a result of a fork)" | ||
export const CANCEL_ARG_ERROR = "cancel argument must be a valid task (a result of a fork)" | ||
export const INVALID_PATTERN = "Invalid pattern passed to `take` (HINT: check if you didn't mispell a constant)" | ||
export const INVALID_PATTERN = "Invalid pattern passed to `take` (HINT: check if you didn't mispell a constant)" | ||
export const SELECT_ARG_ERROR = "select first argument must be a function" | ||
@@ -20,2 +21,3 @@ | ||
const CANCEL = 'CANCEL' | ||
const SELECT = 'SELECT' | ||
@@ -102,2 +104,14 @@ const effect = (type, payload) => ({ [IO]: true, [type]: payload }) | ||
export function select(selector, ...args) { | ||
check(selector, is.func, SELECT_ARG_ERROR) | ||
return effect(SELECT, {selector, args}) | ||
} | ||
const getStateEff = select(ident) | ||
export function getState() { | ||
return getStateEff | ||
} | ||
export const asEffect = { | ||
@@ -111,3 +125,4 @@ take : effect => effect && effect[IO] && effect[TAKE], | ||
join : effect => effect && effect[IO] && effect[JOIN], | ||
cancel : effect => effect && effect[IO] && effect[CANCEL] | ||
cancel : effect => effect && effect[IO] && effect[CANCEL], | ||
select : effect => effect && effect[IO] && effect[SELECT] | ||
} |
@@ -1,2 +0,2 @@ | ||
import { asap, isDev } from './utils' | ||
import { is, asap, isDev, check } from './utils' | ||
import proc from './proc' | ||
@@ -7,2 +7,6 @@ import emitter from './emitter' | ||
export const sagaArgError = (fn, pos, saga) => (` | ||
${fn} can only be called on Generator functions | ||
Argument ${saga} at position ${pos} is not function! | ||
`) | ||
export const RUN_SAGA_DYNAMIC_ERROR = 'Before running a Saga dynamically using middleware.run, you must mount the Saga middleware on the Store using applyMiddleware' | ||
@@ -13,4 +17,5 @@ | ||
sagas.forEach((saga, idx) => check(saga, is.func, sagaArgError('createSagaMiddleware', idx, saga))) | ||
function sagaMiddleware({getState, dispatch}) { | ||
const sagaEmitter = emitter() | ||
@@ -24,2 +29,3 @@ const monitor = isDev ? action => asap(() => dispatch(action)) : undefined | ||
dispatch, | ||
getState, | ||
monitor, | ||
@@ -37,3 +43,3 @@ 0, | ||
const result = next(action) // hit reducers | ||
// filter out monitor actions to avoid endless loop | ||
// filter out monitor actions to avoid endless loops | ||
// see https://github.com/yelouafi/redux-saga/issues/61 | ||
@@ -50,2 +56,4 @@ if(!action[MONITOR_ACTION]) | ||
} | ||
check(saga, is.func, sagaArgError('sagaMiddleware.run', 0, saga)) | ||
const task = runSagaDynamically(saga, ...args) | ||
@@ -52,0 +60,0 @@ task.done.catch(err => { |
@@ -26,2 +26,3 @@ import { noop, is, isDev, check, remove, deferred, autoInc, asap, TASK } from './utils' | ||
dispatch = noop, | ||
getState = noop, | ||
monitor = noop, | ||
@@ -222,2 +223,3 @@ parentEffectId = 0, | ||
: (is.notUndef(data = asEffect.cancel(effect))) ? runCancelEffect(data, currCb) | ||
: (is.notUndef(data = asEffect.select(effect))) ? runSelectEffect(data, currCb) | ||
: /* anything else returned as is */ currCb(null, effect) | ||
@@ -243,3 +245,3 @@ ) | ||
resolvePromise( | ||
proc(iterator, subscribe, dispatch, monitor, effectId, name).done, | ||
proc(iterator, subscribe, dispatch, getState, monitor, effectId, name).done, | ||
cb | ||
@@ -305,3 +307,3 @@ ) | ||
null, | ||
proc(_iterator, subscribe, dispatch, monitor, effectId, fn.name, true) | ||
proc(_iterator, subscribe, dispatch, getState, monitor, effectId, fn.name, true) | ||
) | ||
@@ -430,2 +432,11 @@ // Fork effects are non cancellables | ||
function runSelectEffect({selector, args}, cb) { | ||
try { | ||
const state = selector(getState(), ...args) | ||
cb(null, state) | ||
} catch(error) { | ||
cb(error) | ||
} | ||
} | ||
function newTask(id, name, iterator, done, forked) { | ||
@@ -432,0 +443,0 @@ return { |
@@ -36,3 +36,4 @@ import { is, check, noop, isDev } from './utils' | ||
subscribe: storeEmitter.subscribe, | ||
dispatch : store.dispatch | ||
dispatch : store.dispatch, | ||
getState : store.getState | ||
} | ||
@@ -43,3 +44,11 @@ | ||
export function runSaga(iterator, {subscribe, dispatch}, monitor = noop) { | ||
export function runSaga( | ||
iterator, | ||
{ | ||
subscribe, | ||
dispatch, | ||
getState | ||
}, | ||
monitor = noop | ||
) { | ||
@@ -52,4 +61,5 @@ check(iterator, is.iterator, NOT_ITERATOR_ERROR) | ||
dispatch, | ||
getState, | ||
monitor | ||
) | ||
} |
export const TASK = Symbol('TASK') | ||
export const kTrue = () => true | ||
export const noop = () => {} | ||
export const ident = v => v | ||
@@ -5,0 +6,0 @@ export const isDev = typeof process !== 'undefined' && process.env && process.env.NODE_ENV === 'development' |
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
218096
3076
231