redux-saga
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.SAGA_NOT_A_GENERATOR_ERROR = exports.join = exports.fork = exports.cps = exports.call = exports.race = exports.put = exports.take = undefined; | ||
exports.join = exports.fork = exports.cps = exports.call = exports.race = exports.put = exports.take = undefined; | ||
@@ -62,4 +62,2 @@ var _io = require('./io'); | ||
var SAGA_NOT_A_GENERATOR_ERROR = exports.SAGA_NOT_A_GENERATOR_ERROR = "Saga must be a Generator function"; | ||
exports.default = function () { | ||
@@ -77,4 +75,2 @@ for (var _len = arguments.length, sagas = Array(_len), _key = 0; _key < _len; _key++) { | ||
sagas.forEach(function (saga) { | ||
if (!_utils.is.generator(saga)) throw new Error(SAGA_NOT_A_GENERATOR_ERROR); | ||
(0, _proc2.default)(saga(getState), subscribe, dispatch, saga.name); | ||
@@ -81,0 +77,0 @@ }); |
@@ -17,3 +17,3 @@ 'use strict'; | ||
var NOT_ITERATOR_ERROR = exports.NOT_ITERATOR_ERROR = "proc first argument must be an iterator"; | ||
var NOT_ITERATOR_ERROR = exports.NOT_ITERATOR_ERROR = "proc first argument (Saga function result) must be an iterator"; | ||
@@ -90,3 +90,4 @@ function proc(iterator) { | ||
function runCallEffect(fn, args) { | ||
return !_utils.is.generator(fn) ? Promise.resolve(fn.apply(undefined, _toConsumableArray(args))) : proc(fn.apply(undefined, _toConsumableArray(args)), subscribe, dispatch); | ||
var result = fn.apply(undefined, _toConsumableArray(args)); | ||
return !_utils.is.iterator(result) ? Promise.resolve(result) : proc(result, subscribe, dispatch); | ||
} | ||
@@ -105,35 +106,45 @@ | ||
var _generator = undefined, | ||
var result = undefined, | ||
_generator = undefined, | ||
_iterator = undefined; | ||
if (_utils.is.generator(task)) { | ||
var isFunc = _utils.is.func(task); | ||
// we run the function, next we'll check if this is a generator function | ||
// (generator is a function that returns an iterator) | ||
if (isFunc) result = task.apply(undefined, _toConsumableArray(args)); | ||
// A generator function: i.e. returns an iterator | ||
if (_utils.is.iterator(result)) { | ||
_generator = task; | ||
_iterator = _generator.apply(undefined, _toConsumableArray(args)); | ||
} else if (_utils.is.iterator(task)) { | ||
// directly forking an iterator | ||
_iterator = task; | ||
} else { | ||
_iterator = result; | ||
} | ||
// directly forking an iterator | ||
else if (_utils.is.iterator(task)) { | ||
_iterator = task; | ||
} | ||
//simple effect: wrap in a generator | ||
_iterator = regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return _utils.is.func(task) ? task.apply(undefined, _toConsumableArray(args)) : task; | ||
else { | ||
_iterator = regeneratorRuntime.mark(function _callee() { | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return isFunc ? result : task; | ||
case 2: | ||
return _context.abrupt('return', _context.sent); | ||
case 2: | ||
return _context.abrupt('return', _context.sent); | ||
case 3: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})(); | ||
} | ||
case 3: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})(); | ||
} | ||
var _done = proc(_iterator, subscribe, dispatch); | ||
var taskDesc = (_taskDesc = {}, _defineProperty(_taskDesc, _utils.TASK, true), _defineProperty(_taskDesc, '_generator', _generator), _defineProperty(_taskDesc, '_iterator', _iterator), _defineProperty(_taskDesc, '_done', _done), _defineProperty(_taskDesc, 'name', _generator && _generator.name), _defineProperty(_taskDesc, 'isRunning', function isRunning() { | ||
var taskDesc = (_taskDesc = {}, _defineProperty(_taskDesc, _utils.TASK, true), _defineProperty(_taskDesc, '_generator', _generator), _defineProperty(_taskDesc, '_iterator', _iterator), _defineProperty(_taskDesc, '_done', _done), _defineProperty(_taskDesc, 'name', isFunc ? task.name : 'anonymous'), _defineProperty(_taskDesc, 'isRunning', function isRunning() { | ||
return _iterator._isRunning; | ||
@@ -140,0 +151,0 @@ }), _defineProperty(_taskDesc, 'result', function result() { |
{ | ||
"name": "redux-saga", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"description": "Saga middleware for Redux to handle Side Effects", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -267,9 +267,8 @@ An alternative Side Effect model for Redux applications. Instead of dispatching thunks | ||
while( yield take(types.CHECKOUT_REQUEST) ) { | ||
try { | ||
const cart = getState().cart | ||
const {result, error} = yield call(api.buyProducts, cart) | ||
if(!error) | ||
yield put(actions.checkoutSuccess(result)) | ||
else | ||
yield put(actions.checkoutFailure(error)) | ||
const cart = getState().cart | ||
const {result, error} = yield call(api.buyProducts, cart) | ||
if(!error) | ||
yield put(actions.checkoutSuccess(result)) | ||
else | ||
yield put(actions.checkoutFailure(error)) | ||
} | ||
@@ -324,3 +323,3 @@ } | ||
if(result) | ||
if(posts) | ||
put( actions.receivePosts(posts) ) | ||
@@ -575,3 +574,4 @@ else | ||
cd examples/real-world | ||
npm install | ||
npm start | ||
``` |
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
45034
10
381