1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.runSaga = runSaga;
|
5 |
|
6 | var _utils = require('./utils');
|
7 |
|
8 | var _proc = require('./proc');
|
9 |
|
10 | var _proc2 = _interopRequireDefault(_proc);
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 | var RUN_SAGA_SIGNATURE = 'runSaga(storeInterface, saga, ...args)';
|
15 | var NON_GENERATOR_ERR = RUN_SAGA_SIGNATURE + ': saga argument must be a Generator function!';
|
16 |
|
17 | function runSaga(storeInterface, saga) {
|
18 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
19 | args[_key - 2] = arguments[_key];
|
20 | }
|
21 |
|
22 | var iterator = void 0;
|
23 |
|
24 | if (_utils.is.iterator(storeInterface)) {
|
25 | if (process.env.NODE_ENV === 'development') {
|
26 | (0, _utils.log)('warn', 'runSaga(iterator, storeInterface) has been deprecated in favor of ' + RUN_SAGA_SIGNATURE);
|
27 | }
|
28 | iterator = storeInterface;
|
29 | storeInterface = saga;
|
30 | } else {
|
31 | (0, _utils.check)(saga, _utils.is.func, NON_GENERATOR_ERR);
|
32 | iterator = saga.apply(undefined, args);
|
33 | (0, _utils.check)(iterator, _utils.is.iterator, NON_GENERATOR_ERR);
|
34 | }
|
35 |
|
36 | var _storeInterface = storeInterface,
|
37 | subscribe = _storeInterface.subscribe,
|
38 | dispatch = _storeInterface.dispatch,
|
39 | getState = _storeInterface.getState,
|
40 | context = _storeInterface.context,
|
41 | sagaMonitor = _storeInterface.sagaMonitor,
|
42 | logger = _storeInterface.logger,
|
43 | onError = _storeInterface.onError;
|
44 |
|
45 |
|
46 | var effectId = (0, _utils.uid)();
|
47 |
|
48 | if (sagaMonitor) {
|
49 |
|
50 | sagaMonitor.effectTriggered = sagaMonitor.effectTriggered || _utils.noop;
|
51 | sagaMonitor.effectResolved = sagaMonitor.effectResolved || _utils.noop;
|
52 | sagaMonitor.effectRejected = sagaMonitor.effectRejected || _utils.noop;
|
53 | sagaMonitor.effectCancelled = sagaMonitor.effectCancelled || _utils.noop;
|
54 | sagaMonitor.actionDispatched = sagaMonitor.actionDispatched || _utils.noop;
|
55 |
|
56 | sagaMonitor.effectTriggered({ effectId: effectId, root: true, parentEffectId: 0, effect: { root: true, saga: saga, args: args } });
|
57 | }
|
58 |
|
59 | var task = (0, _proc2.default)(iterator, subscribe, (0, _utils.wrapSagaDispatch)(dispatch), getState, context, { sagaMonitor: sagaMonitor, logger: logger, onError: onError }, effectId, saga.name);
|
60 |
|
61 | if (sagaMonitor) {
|
62 | sagaMonitor.effectResolved(effectId, task);
|
63 | }
|
64 |
|
65 | return task;
|
66 | } |
\ | No newline at end of file |