@vve/redux-saga 8.4.0 → 9.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/effects.js +3 -2
- package/es/effects.js.map +1 -0
- package/es/index.js +11 -10
- package/es/index.js.map +1 -0
- package/es/internal/buffers.js +21 -45
- package/es/internal/buffers.js.map +1 -0
- package/es/internal/channel.js +36 -87
- package/es/internal/channel.js.map +1 -0
- package/es/internal/channels-trans-table.png +0 -0
- package/es/internal/convenient-io.js +6 -19
- package/es/internal/convenient-io.js.map +1 -0
- package/es/internal/io-helpers.js +7 -9
- package/es/internal/io-helpers.js.map +1 -0
- package/es/internal/io.js +70 -113
- package/es/internal/io.js.map +1 -0
- package/es/internal/middleware.js +42 -45
- package/es/internal/middleware.js.map +1 -0
- package/es/internal/proc.js +188 -358
- package/es/internal/proc.js.map +1 -0
- package/es/internal/runSaga.js +20 -27
- package/es/internal/runSaga.js.map +1 -0
- package/es/internal/sagaHelpers/fsmIterator.js +13 -22
- package/es/internal/sagaHelpers/fsmIterator.js.map +1 -0
- package/es/internal/sagaHelpers/index.js +12 -13
- package/es/internal/sagaHelpers/index.js.map +1 -0
- package/es/internal/sagaHelpers/takeEvery.js +13 -20
- package/es/internal/sagaHelpers/takeEvery.js.map +1 -0
- package/es/internal/sagaHelpers/takeLatest.js +19 -33
- package/es/internal/sagaHelpers/takeLatest.js.map +1 -0
- package/es/internal/sagaHelpers/throttle.js +22 -36
- package/es/internal/sagaHelpers/throttle.js.map +1 -0
- package/es/internal/scheduler.js +7 -11
- package/es/internal/scheduler.js.map +1 -0
- package/es/internal/utils.js +101 -205
- package/es/internal/utils.js.map +1 -0
- package/es/utils.js +5 -4
- package/es/utils.js.map +1 -0
- package/lib/effects.js +138 -30
- package/lib/effects.js.map +1 -0
- package/lib/index.js +86 -48
- package/lib/index.js.map +1 -0
- package/lib/internal/buffers.js +24 -48
- package/lib/internal/buffers.js.map +1 -0
- package/lib/internal/channel.js +43 -100
- package/lib/internal/channel.js.map +1 -0
- package/lib/internal/channels-trans-table.png +0 -0
- package/lib/internal/convenient-io.js +10 -23
- package/lib/internal/convenient-io.js.map +1 -0
- package/lib/internal/io-helpers.js +10 -15
- package/lib/internal/io-helpers.js.map +1 -0
- package/lib/internal/io.js +89 -149
- package/lib/internal/io.js.map +1 -0
- package/lib/internal/middleware.js +46 -51
- package/lib/internal/middleware.js.map +1 -0
- package/lib/internal/proc.js +194 -372
- package/lib/internal/proc.js.map +1 -0
- package/lib/internal/runSaga.js +25 -35
- package/lib/internal/runSaga.js.map +1 -0
- package/lib/internal/sagaHelpers/fsmIterator.js +19 -29
- package/lib/internal/sagaHelpers/fsmIterator.js.map +1 -0
- package/lib/internal/sagaHelpers/index.js +37 -27
- package/lib/internal/sagaHelpers/index.js.map +1 -0
- package/lib/internal/sagaHelpers/takeEvery.js +19 -31
- package/lib/internal/sagaHelpers/takeEvery.js.map +1 -0
- package/lib/internal/sagaHelpers/takeLatest.js +25 -44
- package/lib/internal/sagaHelpers/takeLatest.js.map +1 -0
- package/lib/internal/sagaHelpers/throttle.js +28 -49
- package/lib/internal/sagaHelpers/throttle.js.map +1 -0
- package/lib/internal/scheduler.js +11 -15
- package/lib/internal/scheduler.js.map +1 -0
- package/lib/internal/utils.js +119 -247
- package/lib/internal/utils.js.map +1 -0
- package/lib/utils.js +69 -22
- package/lib/utils.js.map +1 -0
- package/package.json +19 -18
package/lib/internal/proc.js
CHANGED
|
@@ -1,72 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
exports
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
var _channel =
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
var _utils2 = /*#__PURE__*/require("../utils");
|
|
18
|
-
|
|
19
|
-
var _convenientIo = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("./convenient-io"));
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
22
|
-
|
|
23
|
-
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); } if (Object.getOwnPropertySymbols) { var objectSymbols = Object.getOwnPropertySymbols(descs); for (var i = 0; i < objectSymbols.length; i++) { var sym = objectSymbols[i]; var desc = descs[sym]; desc.configurable = desc.enumerable = true; if ("value" in desc) desc.writable = true; Object.defineProperty(obj, sym, desc); } } return obj; }
|
|
24
|
-
|
|
25
|
-
function _extends() { _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; }; return _extends.apply(this, arguments); }
|
|
26
|
-
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.TASK_CANCEL = exports.NOT_ITERATOR_ERROR = exports.CHANNEL_END = void 0;
|
|
8
|
+
exports.default = proc;
|
|
9
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
var _scheduler = require("./scheduler");
|
|
12
|
+
var _io = require("./io");
|
|
13
|
+
var _channel = require("./channel");
|
|
14
|
+
var _buffers = require("./buffers");
|
|
15
|
+
var _utils2 = require("../utils");
|
|
16
|
+
var _convenientIo = _interopRequireDefault(require("./convenient-io"));
|
|
27
17
|
var NOT_ITERATOR_ERROR = 'proc first argument (Saga function result) must be an iterator';
|
|
28
18
|
exports.NOT_ITERATOR_ERROR = NOT_ITERATOR_ERROR;
|
|
29
19
|
var CHANNEL_END = {
|
|
30
|
-
toString
|
|
20
|
+
toString() {
|
|
31
21
|
return '@@redux-saga/CHANNEL_END';
|
|
32
22
|
}
|
|
33
23
|
};
|
|
34
24
|
exports.CHANNEL_END = CHANNEL_END;
|
|
35
25
|
var TASK_CANCEL = {
|
|
36
|
-
toString
|
|
26
|
+
toString() {
|
|
37
27
|
return '@@redux-saga/TASK_CANCEL';
|
|
38
28
|
}
|
|
39
29
|
};
|
|
40
30
|
exports.TASK_CANCEL = TASK_CANCEL;
|
|
41
31
|
var matchers = {
|
|
42
|
-
wildcard:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return typeof pattern === 'symbol' ? function (input) {
|
|
47
|
-
return input.type === pattern;
|
|
48
|
-
} : function (input) {
|
|
49
|
-
return input.type === String(pattern);
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
array: function array(patterns) {
|
|
53
|
-
return function (input) {
|
|
54
|
-
return patterns.some(function (p) {
|
|
55
|
-
return matcher(p)(input);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
predicate: function predicate(_predicate) {
|
|
60
|
-
return function (input) {
|
|
61
|
-
return _predicate(input);
|
|
62
|
-
};
|
|
63
|
-
}
|
|
32
|
+
wildcard: () => _utils.kTrue,
|
|
33
|
+
default: pattern => typeof pattern === 'symbol' ? input => input.type === pattern : input => input.type === String(pattern),
|
|
34
|
+
array: patterns => input => patterns.some(p => matcher(p)(input)),
|
|
35
|
+
predicate: _predicate => input => _predicate(input)
|
|
64
36
|
};
|
|
65
|
-
|
|
66
37
|
function matcher(pattern) {
|
|
67
38
|
// prettier-ignore
|
|
68
|
-
return (pattern === '*' ? matchers.wildcard : _utils.is.array(pattern) ? matchers.array : _utils.is.stringableFunc(pattern) ? matchers
|
|
39
|
+
return (pattern === '*' ? matchers.wildcard : _utils.is.array(pattern) ? matchers.array : _utils.is.stringableFunc(pattern) ? matchers.default : _utils.is.func(pattern) ? matchers.predicate : matchers.default)(pattern);
|
|
69
40
|
}
|
|
41
|
+
|
|
70
42
|
/**
|
|
71
43
|
Used to track a parent task and its forks
|
|
72
44
|
In the new fork model, forked tasks are attached by default to their parent
|
|
@@ -82,100 +54,81 @@ function matcher(pattern) {
|
|
|
82
54
|
- It aborts if any uncaught error bubbles up from forks
|
|
83
55
|
- If it completes, the return value is the one returned by the main task
|
|
84
56
|
**/
|
|
85
|
-
|
|
86
|
-
|
|
87
57
|
function forkQueue(name, mainTask, cb) {
|
|
88
58
|
var tasks = [],
|
|
89
|
-
|
|
90
|
-
|
|
59
|
+
result,
|
|
60
|
+
completed = false;
|
|
91
61
|
addTask(mainTask);
|
|
92
|
-
|
|
93
62
|
function abort(err) {
|
|
94
63
|
cancelAll();
|
|
95
64
|
cb(err, true);
|
|
96
65
|
}
|
|
97
|
-
|
|
98
66
|
function addTask(task) {
|
|
99
67
|
tasks.push(task);
|
|
100
|
-
|
|
101
|
-
task.cont = function (res, isErr) {
|
|
68
|
+
task.cont = (res, isErr) => {
|
|
102
69
|
if (completed) {
|
|
103
70
|
return;
|
|
104
71
|
}
|
|
105
|
-
|
|
106
72
|
(0, _utils.remove)(tasks, task);
|
|
107
73
|
task.cont = _utils.noop;
|
|
108
|
-
|
|
109
74
|
if (isErr) {
|
|
110
75
|
abort(res);
|
|
111
76
|
} else {
|
|
112
77
|
if (task === mainTask) {
|
|
113
78
|
result = res;
|
|
114
79
|
}
|
|
115
|
-
|
|
116
80
|
if (!tasks.length) {
|
|
117
81
|
completed = true;
|
|
118
82
|
cb(result);
|
|
119
83
|
}
|
|
120
84
|
}
|
|
121
|
-
};
|
|
122
|
-
|
|
85
|
+
};
|
|
86
|
+
// task.cont.cancel = task.cancel
|
|
123
87
|
}
|
|
124
88
|
|
|
125
89
|
function cancelAll() {
|
|
126
90
|
if (completed) {
|
|
127
91
|
return;
|
|
128
92
|
}
|
|
129
|
-
|
|
130
93
|
completed = true;
|
|
131
|
-
tasks.forEach(
|
|
94
|
+
tasks.forEach(t => {
|
|
132
95
|
t.cont = _utils.noop;
|
|
133
96
|
t.cancel();
|
|
134
97
|
});
|
|
135
98
|
tasks = [];
|
|
136
99
|
}
|
|
137
|
-
|
|
138
100
|
return {
|
|
139
|
-
addTask
|
|
140
|
-
cancelAll
|
|
141
|
-
abort
|
|
142
|
-
getTasks:
|
|
143
|
-
|
|
144
|
-
},
|
|
145
|
-
taskNames: function taskNames() {
|
|
146
|
-
return tasks.map(function (t) {
|
|
147
|
-
return t.name;
|
|
148
|
-
});
|
|
149
|
-
}
|
|
101
|
+
addTask,
|
|
102
|
+
cancelAll,
|
|
103
|
+
abort,
|
|
104
|
+
getTasks: () => tasks,
|
|
105
|
+
taskNames: () => tasks.map(t => t.name)
|
|
150
106
|
};
|
|
151
107
|
}
|
|
152
|
-
|
|
153
108
|
function createTaskIterator(_ref) {
|
|
154
109
|
var context = _ref.context,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
110
|
+
fn = _ref.fn,
|
|
111
|
+
args = _ref.args;
|
|
158
112
|
if (_utils.is.iterator(fn)) {
|
|
159
113
|
return fn;
|
|
160
|
-
}
|
|
161
|
-
|
|
114
|
+
}
|
|
162
115
|
|
|
116
|
+
// catch synchronous failures; see #152 and #441
|
|
163
117
|
var result, error;
|
|
164
|
-
|
|
165
118
|
try {
|
|
166
119
|
result = fn.apply(context, args);
|
|
167
120
|
} catch (err) {
|
|
168
121
|
error = err;
|
|
169
|
-
}
|
|
170
|
-
|
|
122
|
+
}
|
|
171
123
|
|
|
124
|
+
// i.e. a generator function returns an iterator
|
|
172
125
|
if (_utils.is.iterator(result)) {
|
|
173
126
|
return result;
|
|
174
|
-
}
|
|
175
|
-
// instead create a failed task. See #152 and #441
|
|
176
|
-
|
|
127
|
+
}
|
|
177
128
|
|
|
178
|
-
|
|
129
|
+
// do not bubble up synchronous failures for detached forks
|
|
130
|
+
// instead create a failed task. See #152 and #441
|
|
131
|
+
return error ? (0, _utils.makeIterator)(() => {
|
|
179
132
|
throw error;
|
|
180
133
|
}) : (0, _utils.makeIterator)(function () {
|
|
181
134
|
var pc;
|
|
@@ -183,15 +136,11 @@ function createTaskIterator(_ref) {
|
|
|
183
136
|
done: false,
|
|
184
137
|
value: result
|
|
185
138
|
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
return function (arg) {
|
|
139
|
+
var ret = value => ({
|
|
140
|
+
done: true,
|
|
141
|
+
value
|
|
142
|
+
});
|
|
143
|
+
return arg => {
|
|
195
144
|
if (!pc) {
|
|
196
145
|
pc = true;
|
|
197
146
|
return eff;
|
|
@@ -201,63 +150,32 @@ function createTaskIterator(_ref) {
|
|
|
201
150
|
};
|
|
202
151
|
}());
|
|
203
152
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (dispatch === void 0) {
|
|
219
|
-
dispatch = _utils.noop;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (getState === void 0) {
|
|
223
|
-
getState = _utils.noop;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
if (parentContext === void 0) {
|
|
227
|
-
parentContext = {};
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (options === void 0) {
|
|
231
|
-
options = {};
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
if (parentEffectId === void 0) {
|
|
235
|
-
parentEffectId = 0;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (name === void 0) {
|
|
239
|
-
name = 'anonymous';
|
|
240
|
-
}
|
|
241
|
-
|
|
153
|
+
var wrapHelper = helper => ({
|
|
154
|
+
fn: helper
|
|
155
|
+
});
|
|
156
|
+
function proc(iterator) {
|
|
157
|
+
var subscribe = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => _utils.noop;
|
|
158
|
+
var dispatch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _utils.noop;
|
|
159
|
+
var getState = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _utils.noop;
|
|
160
|
+
var parentContext = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
|
161
|
+
var options = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};
|
|
162
|
+
var parentEffectId = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0;
|
|
163
|
+
var name = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'anonymous';
|
|
164
|
+
var cont = arguments.length > 8 ? arguments[8] : undefined;
|
|
242
165
|
(0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR);
|
|
243
166
|
var effectsString = '[...effects]';
|
|
244
|
-
var runParallelEffect = (0, _utils.deprecate)(runAllEffect, (0, _utils.updateIncentive)(effectsString,
|
|
245
|
-
var
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
onError = _options.onError;
|
|
167
|
+
var runParallelEffect = (0, _utils.deprecate)(runAllEffect, (0, _utils.updateIncentive)(effectsString, `all(${effectsString})`));
|
|
168
|
+
var sagaMonitor = options.sagaMonitor,
|
|
169
|
+
logger = options.logger,
|
|
170
|
+
onError = options.onError;
|
|
249
171
|
var log = logger || _utils.log;
|
|
250
|
-
|
|
251
|
-
var logError = function logError(err) {
|
|
172
|
+
var logError = err => {
|
|
252
173
|
var message = err.sagaStack;
|
|
253
|
-
|
|
254
174
|
if (!message && err.stack) {
|
|
255
|
-
message = err.stack.split('\n')[0].indexOf(err.message) !== -1 ? err.stack :
|
|
175
|
+
message = err.stack.split('\n')[0].indexOf(err.message) !== -1 ? err.stack : `Error: ${err.message}\n${err.stack}`;
|
|
256
176
|
}
|
|
257
|
-
|
|
258
|
-
log('error', "uncaught at " + name, message || err.message || err);
|
|
177
|
+
log('error', `uncaught at ${name}`, message || err.message || err);
|
|
259
178
|
};
|
|
260
|
-
|
|
261
179
|
var stdChannel = (0, _channel.stdChannel)(subscribe);
|
|
262
180
|
var taskContext = Object.create(parentContext);
|
|
263
181
|
/**
|
|
@@ -265,30 +183,30 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
265
183
|
Each time the generator progresses. calling runEffect will set a new value
|
|
266
184
|
on it. It allows propagating cancellation to child effects
|
|
267
185
|
**/
|
|
268
|
-
|
|
269
186
|
next.cancel = _utils.noop;
|
|
187
|
+
|
|
270
188
|
/**
|
|
271
189
|
Creates a new task descriptor for this generator, We'll also create a main task
|
|
272
190
|
to track the main flow (besides other forked tasks)
|
|
273
191
|
**/
|
|
274
|
-
|
|
275
192
|
var task = newTask(parentEffectId, name, iterator, cont);
|
|
276
193
|
var mainTask = {
|
|
277
|
-
name
|
|
194
|
+
name,
|
|
278
195
|
cancel: cancelMain,
|
|
279
196
|
isRunning: true
|
|
280
197
|
};
|
|
281
198
|
var taskQueue = forkQueue(name, mainTask, end);
|
|
199
|
+
|
|
282
200
|
/**
|
|
283
201
|
cancellation of the main task. We'll simply resume the Generator with a Cancel
|
|
284
202
|
**/
|
|
285
|
-
|
|
286
203
|
function cancelMain() {
|
|
287
204
|
if (mainTask.isRunning && !mainTask.isCancelled) {
|
|
288
205
|
mainTask.isCancelled = true;
|
|
289
206
|
next(TASK_CANCEL);
|
|
290
207
|
}
|
|
291
208
|
}
|
|
209
|
+
|
|
292
210
|
/**
|
|
293
211
|
This may be called by a parent generator to trigger/propagate cancellation
|
|
294
212
|
cancel all pending tasks (including the main task), then end the current task.
|
|
@@ -296,8 +214,6 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
296
214
|
It's also propagated to all joiners of this task and their execution tree/joiners
|
|
297
215
|
Cancellation is noop for terminated/Cancelled tasks tasks
|
|
298
216
|
**/
|
|
299
|
-
|
|
300
|
-
|
|
301
217
|
function cancel() {
|
|
302
218
|
/**
|
|
303
219
|
We need to check both Running and Cancelled status
|
|
@@ -309,7 +225,6 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
309
225
|
/**
|
|
310
226
|
Ending with a Never result will propagate the Cancellation to all joiners
|
|
311
227
|
**/
|
|
312
|
-
|
|
313
228
|
end(TASK_CANCEL);
|
|
314
229
|
}
|
|
315
230
|
}
|
|
@@ -317,32 +232,31 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
317
232
|
attaches cancellation logic to this task's continuation
|
|
318
233
|
this will permit cancellation to propagate down the call chain
|
|
319
234
|
**/
|
|
235
|
+
cont && (cont.cancel = cancel);
|
|
320
236
|
|
|
237
|
+
// tracks the running status
|
|
238
|
+
iterator._isRunning = true;
|
|
321
239
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
iterator._isRunning = true; // kicks up the generator
|
|
325
|
-
|
|
326
|
-
next(); // then return the task descriptor to the caller
|
|
240
|
+
// kicks up the generator
|
|
241
|
+
next();
|
|
327
242
|
|
|
243
|
+
// then return the task descriptor to the caller
|
|
328
244
|
return task;
|
|
245
|
+
|
|
329
246
|
/**
|
|
330
247
|
This is the generator driver
|
|
331
248
|
It's a recursive async/continuation function which calls itself
|
|
332
249
|
until the generator terminates or throws
|
|
333
250
|
**/
|
|
334
|
-
|
|
335
251
|
function next(arg, isErr) {
|
|
336
252
|
// Preventive measure. If we end up here, then there is really something wrong
|
|
337
253
|
if (!mainTask.isRunning) {
|
|
338
254
|
throw new Error('Trying to resume an already finished generator');
|
|
339
255
|
}
|
|
340
|
-
|
|
341
256
|
try {
|
|
342
257
|
var result;
|
|
343
|
-
|
|
344
258
|
if (isErr) {
|
|
345
|
-
result = iterator
|
|
259
|
+
result = iterator.throw(arg);
|
|
346
260
|
} else if (arg === TASK_CANCEL) {
|
|
347
261
|
/**
|
|
348
262
|
getting TASK_CANCEL automatically cancels the main task
|
|
@@ -354,26 +268,23 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
354
268
|
/**
|
|
355
269
|
Cancels the current effect; this will propagate the cancellation down to any called tasks
|
|
356
270
|
**/
|
|
357
|
-
|
|
358
271
|
next.cancel();
|
|
359
272
|
/**
|
|
360
273
|
If this Generator has a `return` method then invokes it
|
|
361
274
|
This will jump to the finally block
|
|
362
275
|
**/
|
|
363
|
-
|
|
364
|
-
result = _utils.is.func(iterator["return"]) ? iterator["return"](TASK_CANCEL) : {
|
|
276
|
+
result = _utils.is.func(iterator.return) ? iterator.return(TASK_CANCEL) : {
|
|
365
277
|
done: true,
|
|
366
278
|
value: TASK_CANCEL
|
|
367
279
|
};
|
|
368
280
|
} else if (arg === CHANNEL_END) {
|
|
369
281
|
// We get CHANNEL_END by taking from a channel that ended using `take` (and not `takem` used to trap End of channels)
|
|
370
|
-
result = _utils.is.func(iterator
|
|
282
|
+
result = _utils.is.func(iterator.return) ? iterator.return() : {
|
|
371
283
|
done: true
|
|
372
284
|
};
|
|
373
285
|
} else {
|
|
374
286
|
result = iterator.next(arg);
|
|
375
287
|
}
|
|
376
|
-
|
|
377
288
|
if (!result.done) {
|
|
378
289
|
runEffect(result.value, parentEffectId, '', next);
|
|
379
290
|
} else {
|
|
@@ -387,27 +298,23 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
387
298
|
if (mainTask.isCancelled) {
|
|
388
299
|
logError(error);
|
|
389
300
|
}
|
|
390
|
-
|
|
391
301
|
mainTask.isMainRunning = false;
|
|
392
302
|
mainTask.cont(error, true);
|
|
393
303
|
}
|
|
394
304
|
}
|
|
395
|
-
|
|
396
305
|
function end(result, isErr) {
|
|
397
306
|
iterator._isRunning = false;
|
|
398
307
|
stdChannel.close();
|
|
399
|
-
|
|
400
308
|
if (!isErr) {
|
|
401
309
|
iterator._result = result;
|
|
402
310
|
iterator._deferredEnd && iterator._deferredEnd.resolve(result);
|
|
403
311
|
} else {
|
|
404
312
|
if (result instanceof Error) {
|
|
405
313
|
Object.defineProperty(result, 'sagaStack', {
|
|
406
|
-
value:
|
|
314
|
+
value: `at ${name} \n ${result.sagaStack || result.stack}`,
|
|
407
315
|
configurable: true
|
|
408
316
|
});
|
|
409
317
|
}
|
|
410
|
-
|
|
411
318
|
if (!task.cont) {
|
|
412
319
|
if (result instanceof Error && onError) {
|
|
413
320
|
onError(result);
|
|
@@ -415,84 +322,72 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
415
322
|
logError(result);
|
|
416
323
|
}
|
|
417
324
|
}
|
|
418
|
-
|
|
419
325
|
iterator._error = result;
|
|
420
326
|
iterator._isAborted = true;
|
|
421
327
|
iterator._deferredEnd && iterator._deferredEnd.reject(result);
|
|
422
328
|
}
|
|
423
|
-
|
|
424
329
|
task.cont && task.cont(result, isErr);
|
|
425
|
-
task.joiners.forEach(
|
|
426
|
-
return j.cb(result, isErr);
|
|
427
|
-
});
|
|
330
|
+
task.joiners.forEach(j => j.cb(result, isErr));
|
|
428
331
|
task.joiners = null;
|
|
429
332
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
label = '';
|
|
434
|
-
}
|
|
435
|
-
|
|
333
|
+
function runEffect(effect, parentEffectId) {
|
|
334
|
+
var label = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
335
|
+
var cb = arguments.length > 3 ? arguments[3] : undefined;
|
|
436
336
|
if (getContext('mobxStyle')) {
|
|
437
|
-
effect = (0, _convenientIo
|
|
337
|
+
effect = (0, _convenientIo.default)(effect);
|
|
438
338
|
}
|
|
439
|
-
|
|
440
339
|
var effectId = (0, _utils.uid)();
|
|
441
340
|
sagaMonitor && sagaMonitor.effectTriggered({
|
|
442
|
-
effectId
|
|
443
|
-
parentEffectId
|
|
444
|
-
label
|
|
445
|
-
effect
|
|
341
|
+
effectId,
|
|
342
|
+
parentEffectId,
|
|
343
|
+
label,
|
|
344
|
+
effect
|
|
446
345
|
});
|
|
346
|
+
|
|
447
347
|
/**
|
|
448
348
|
completion callback and cancel callback are mutually exclusive
|
|
449
349
|
We can't cancel an already completed effect
|
|
450
350
|
And We can't complete an already cancelled effectId
|
|
451
351
|
**/
|
|
352
|
+
var effectSettled;
|
|
452
353
|
|
|
453
|
-
|
|
454
|
-
|
|
354
|
+
// Completion callback passed to the appropriate effect runner
|
|
455
355
|
function currCb(res, isErr) {
|
|
456
356
|
if (effectSettled) {
|
|
457
357
|
return;
|
|
458
358
|
}
|
|
459
|
-
|
|
460
359
|
effectSettled = true;
|
|
461
360
|
cb.cancel = _utils.noop; // defensive measure
|
|
462
|
-
|
|
463
361
|
if (sagaMonitor) {
|
|
464
362
|
isErr ? sagaMonitor.effectRejected(effectId, res) : sagaMonitor.effectResolved(effectId, res);
|
|
465
363
|
}
|
|
466
|
-
|
|
467
364
|
cb(res, isErr);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
currCb.cancel = _utils.noop; // setup cancellation logic on the parent cb
|
|
365
|
+
}
|
|
366
|
+
// tracks down the current cancel
|
|
367
|
+
currCb.cancel = _utils.noop;
|
|
472
368
|
|
|
473
|
-
|
|
369
|
+
// setup cancellation logic on the parent cb
|
|
370
|
+
cb.cancel = () => {
|
|
474
371
|
// prevents cancelling an already completed effect
|
|
475
372
|
if (effectSettled) {
|
|
476
373
|
return;
|
|
477
374
|
}
|
|
478
|
-
|
|
479
375
|
effectSettled = true;
|
|
480
376
|
/**
|
|
481
377
|
propagates cancel downward
|
|
482
378
|
catch uncaught cancellations errors; since we can no longer call the completion
|
|
483
379
|
callback, log errors raised during cancellations into the console
|
|
484
380
|
**/
|
|
485
|
-
|
|
486
381
|
try {
|
|
487
382
|
currCb.cancel();
|
|
488
383
|
} catch (err) {
|
|
489
384
|
logError(err);
|
|
490
385
|
}
|
|
491
|
-
|
|
492
386
|
currCb.cancel = _utils.noop; // defensive measure
|
|
493
387
|
|
|
494
388
|
sagaMonitor && sagaMonitor.effectCancelled(effectId);
|
|
495
389
|
};
|
|
390
|
+
|
|
496
391
|
/**
|
|
497
392
|
each effect runner must attach its own logic of cancellation to the provided callback
|
|
498
393
|
it allows this generator to propagate cancellation downward.
|
|
@@ -505,72 +400,55 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
505
400
|
promise[CANCEL] method in their returned promises
|
|
506
401
|
ATTENTION! calling cancel must have no effect on an already completed or cancelled effect
|
|
507
402
|
**/
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
/* anything else returned as is */
|
|
516
|
-
currCb(effect)
|
|
403
|
+
var data;
|
|
404
|
+
// prettier-ignore
|
|
405
|
+
return (
|
|
406
|
+
// Non declarative effect
|
|
407
|
+
_utils.is.promise(effect) ? resolvePromise(effect, currCb) : _utils.is.helper(effect) ? runForkEffect(wrapHelper(effect), effectId, currCb) : _utils.is.iterator(effect) ? resolveIterator(effect, effectId, name, currCb)
|
|
408
|
+
|
|
409
|
+
// declarative effects
|
|
410
|
+
: _utils.is.array(effect) ? runParallelEffect(effect, effectId, currCb) : (data = _io.asEffect.take(effect)) ? runTakeEffect(data, currCb) : (data = _io.asEffect.put(effect)) ? runPutEffect(data, currCb) : (data = _io.asEffect.all(effect)) ? runAllEffect(data, effectId, currCb) : (data = _io.asEffect.race(effect)) ? runRaceEffect(data, effectId, currCb) : (data = _io.asEffect.call(effect)) ? runCallEffect(data, effectId, currCb) : (data = _io.asEffect.cps(effect)) ? runCPSEffect(data, currCb) : (data = _io.asEffect.fork(effect)) ? runForkEffect(data, effectId, currCb) : (data = _io.asEffect.join(effect)) ? runJoinEffect(data, currCb) : (data = _io.asEffect.cancel(effect)) ? runCancelEffect(data, currCb) : (data = _io.asEffect.select(effect)) ? runSelectEffect(data, currCb) : (data = _io.asEffect.selectSelf(effect)) ? runSelectSelfEffect(data, currCb) : (data = _io.asEffect.putMutation(effect)) ? runPutMutationEffect(data, currCb) : (data = _io.asEffect.putAsyncAction(effect)) ? runPutAsyncEffect(data, currCb) : (data = _io.asEffect.actionChannel(effect)) ? runChannelEffect(data, currCb) : (data = _io.asEffect.flush(effect)) ? runFlushEffect(data, currCb) : (data = _io.asEffect.cancelled(effect)) ? runCancelledEffect(data, currCb) : (data = _io.asEffect.getContext(effect)) ? runGetContextEffect(data, currCb) : (data = _io.asEffect.setContext(effect)) ? runSetContextEffect(data, currCb) : /* anything else returned as is */currCb(effect)
|
|
517
411
|
);
|
|
518
412
|
}
|
|
519
|
-
|
|
520
413
|
function resolvePromise(promise, cb) {
|
|
521
414
|
var cancelPromise = promise[_utils.CANCEL];
|
|
522
|
-
|
|
523
415
|
if (_utils.is.func(cancelPromise)) {
|
|
524
416
|
cb.cancel = cancelPromise;
|
|
525
417
|
} else if (_utils.is.func(promise.abort)) {
|
|
526
|
-
cb.cancel =
|
|
527
|
-
|
|
528
|
-
}; // TODO: add support for the fetch API, whenever they get around to
|
|
418
|
+
cb.cancel = () => promise.abort();
|
|
419
|
+
// TODO: add support for the fetch API, whenever they get around to
|
|
529
420
|
// adding cancel support
|
|
530
|
-
|
|
531
421
|
}
|
|
532
422
|
|
|
533
|
-
promise.then(cb,
|
|
534
|
-
return cb(error, true);
|
|
535
|
-
});
|
|
423
|
+
promise.then(cb, error => cb(error, true));
|
|
536
424
|
}
|
|
537
|
-
|
|
538
425
|
function resolveIterator(iterator, effectId, name, cb) {
|
|
539
426
|
proc(iterator, subscribe, dispatch, getState, taskContext, options, effectId, name, cb);
|
|
540
427
|
}
|
|
541
|
-
|
|
542
428
|
function runTakeEffect(_ref2, cb) {
|
|
543
429
|
var channel = _ref2.channel,
|
|
544
|
-
|
|
545
|
-
|
|
430
|
+
pattern = _ref2.pattern,
|
|
431
|
+
maybe = _ref2.maybe;
|
|
546
432
|
channel = channel || stdChannel;
|
|
547
|
-
|
|
548
|
-
var takeCb = function takeCb(inp) {
|
|
549
|
-
return inp instanceof Error ? cb(inp, true) : (0, _channel.isEnd)(inp) && !maybe ? cb(CHANNEL_END) : cb(inp);
|
|
550
|
-
};
|
|
551
|
-
|
|
433
|
+
var takeCb = inp => inp instanceof Error ? cb(inp, true) : (0, _channel.isEnd)(inp) && !maybe ? cb(CHANNEL_END) : cb(inp);
|
|
552
434
|
try {
|
|
553
435
|
channel.take(takeCb, namespaceFilter(pattern, matcher));
|
|
554
436
|
} catch (err) {
|
|
555
437
|
return cb(err, true);
|
|
556
438
|
}
|
|
557
|
-
|
|
558
439
|
cb.cancel = takeCb.cancel;
|
|
559
440
|
}
|
|
560
|
-
|
|
561
441
|
function runPutEffect(_ref3, cb) {
|
|
562
442
|
var channel = _ref3.channel,
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
443
|
+
action = _ref3.action,
|
|
444
|
+
resolve = _ref3.resolve;
|
|
566
445
|
/**
|
|
567
446
|
Schedule the put in case another saga is holding a lock.
|
|
568
447
|
The put will be executed atomically. ie nested puts will execute after
|
|
569
448
|
this put has terminated.
|
|
570
449
|
**/
|
|
571
|
-
(0, _scheduler.asap)(
|
|
450
|
+
(0, _scheduler.asap)(() => {
|
|
572
451
|
var result;
|
|
573
|
-
|
|
574
452
|
try {
|
|
575
453
|
result = (channel ? channel.put : dispatch)(namespaceDecorate(action));
|
|
576
454
|
} catch (error) {
|
|
@@ -578,71 +456,59 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
578
456
|
if (channel || resolve) return cb(error, true);
|
|
579
457
|
logError(error);
|
|
580
458
|
}
|
|
581
|
-
|
|
582
459
|
if (resolve && _utils.is.promise(result)) {
|
|
583
460
|
resolvePromise(result, cb);
|
|
584
461
|
} else {
|
|
585
462
|
return cb(result);
|
|
586
463
|
}
|
|
587
|
-
});
|
|
464
|
+
});
|
|
465
|
+
// Put effects are non cancellables
|
|
588
466
|
}
|
|
589
467
|
|
|
590
468
|
function runCallEffect(_ref4, effectId, cb) {
|
|
591
469
|
var context = _ref4.context,
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
var result;
|
|
595
|
-
|
|
470
|
+
fn = _ref4.fn,
|
|
471
|
+
args = _ref4.args;
|
|
472
|
+
var result;
|
|
473
|
+
// catch synchronous failures; see #152
|
|
596
474
|
try {
|
|
597
475
|
result = fn.apply(context, args);
|
|
598
476
|
} catch (error) {
|
|
599
477
|
return cb(error, true);
|
|
600
478
|
}
|
|
601
|
-
|
|
602
479
|
return _utils.is.promise(result) ? resolvePromise(result, cb) : _utils.is.iterator(result) ? resolveIterator(result, effectId, fn.name, cb) : cb(result);
|
|
603
480
|
}
|
|
604
|
-
|
|
605
481
|
function runCPSEffect(_ref5, cb) {
|
|
606
482
|
var context = _ref5.context,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
483
|
+
fn = _ref5.fn,
|
|
484
|
+
args = _ref5.args;
|
|
610
485
|
// CPS (ie node style functions) can define their own cancellation logic
|
|
611
486
|
// by setting cancel field on the cb
|
|
487
|
+
|
|
612
488
|
// catch synchronous failures; see #152
|
|
613
489
|
try {
|
|
614
|
-
var cpsCb =
|
|
615
|
-
return _utils.is.undef(err) ? cb(res) : cb(err, true);
|
|
616
|
-
};
|
|
617
|
-
|
|
490
|
+
var cpsCb = (err, res) => _utils.is.undef(err) ? cb(res) : cb(err, true);
|
|
618
491
|
fn.apply(context, args.concat(cpsCb));
|
|
619
|
-
|
|
620
492
|
if (cpsCb.cancel) {
|
|
621
|
-
cb.cancel =
|
|
622
|
-
return cpsCb.cancel();
|
|
623
|
-
};
|
|
493
|
+
cb.cancel = () => cpsCb.cancel();
|
|
624
494
|
}
|
|
625
495
|
} catch (error) {
|
|
626
496
|
return cb(error, true);
|
|
627
497
|
}
|
|
628
498
|
}
|
|
629
|
-
|
|
630
499
|
function runForkEffect(_ref6, effectId, cb) {
|
|
631
500
|
var context = _ref6.context,
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
501
|
+
fn = _ref6.fn,
|
|
502
|
+
args = _ref6.args,
|
|
503
|
+
detached = _ref6.detached;
|
|
635
504
|
var taskIterator = createTaskIterator({
|
|
636
|
-
context
|
|
637
|
-
fn
|
|
638
|
-
args
|
|
505
|
+
context,
|
|
506
|
+
fn,
|
|
507
|
+
args
|
|
639
508
|
});
|
|
640
|
-
|
|
641
509
|
try {
|
|
642
510
|
(0, _scheduler.suspend)();
|
|
643
|
-
|
|
644
511
|
var _task = proc(taskIterator, subscribe, dispatch, getState, taskContext, options, effectId, fn.name, detached ? null : _utils.noop);
|
|
645
|
-
|
|
646
512
|
if (detached) {
|
|
647
513
|
cb(_task);
|
|
648
514
|
} else {
|
|
@@ -657,66 +523,55 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
657
523
|
}
|
|
658
524
|
} finally {
|
|
659
525
|
(0, _scheduler.flush)();
|
|
660
|
-
}
|
|
661
|
-
|
|
526
|
+
}
|
|
527
|
+
// Fork effects are non cancellables
|
|
662
528
|
}
|
|
663
529
|
|
|
664
530
|
function runJoinEffect(t, cb) {
|
|
665
531
|
if (t.isRunning()) {
|
|
666
532
|
var joiner = {
|
|
667
|
-
task
|
|
668
|
-
cb
|
|
669
|
-
};
|
|
670
|
-
|
|
671
|
-
cb.cancel = function () {
|
|
672
|
-
return (0, _utils.remove)(t.joiners, joiner);
|
|
533
|
+
task,
|
|
534
|
+
cb
|
|
673
535
|
};
|
|
674
|
-
|
|
536
|
+
cb.cancel = () => (0, _utils.remove)(t.joiners, joiner);
|
|
675
537
|
t.joiners.push(joiner);
|
|
676
538
|
} else {
|
|
677
539
|
t.isAborted() ? cb(t.error(), true) : cb(t.result());
|
|
678
540
|
}
|
|
679
541
|
}
|
|
680
|
-
|
|
681
542
|
function runCancelEffect(taskToCancel, cb) {
|
|
682
543
|
if (taskToCancel === _utils.SELF_CANCELLATION) {
|
|
683
544
|
taskToCancel = task;
|
|
684
545
|
}
|
|
685
|
-
|
|
686
546
|
if (taskToCancel.isRunning()) {
|
|
687
547
|
taskToCancel.cancel();
|
|
688
548
|
}
|
|
689
|
-
|
|
690
|
-
|
|
549
|
+
cb();
|
|
550
|
+
// cancel effects are non cancellables
|
|
691
551
|
}
|
|
692
552
|
|
|
693
553
|
function runAllEffect(effects, effectId, cb) {
|
|
694
554
|
var keys = Object.keys(effects);
|
|
695
|
-
|
|
696
555
|
if (!keys.length) {
|
|
697
556
|
return cb(_utils.is.array(effects) ? [] : {});
|
|
698
557
|
}
|
|
699
|
-
|
|
700
558
|
var completedCount = 0;
|
|
701
559
|
var completed;
|
|
702
560
|
var results = {};
|
|
703
561
|
var childCbs = {};
|
|
704
|
-
|
|
705
562
|
function checkEffectEnd() {
|
|
706
563
|
if (completedCount === keys.length) {
|
|
707
564
|
completed = true;
|
|
708
|
-
cb(_utils.is.array(effects) ? _utils.array.from(
|
|
565
|
+
cb(_utils.is.array(effects) ? _utils.array.from((0, _objectSpread2.default)((0, _objectSpread2.default)({}, results), {}, {
|
|
709
566
|
length: keys.length
|
|
710
567
|
})) : results);
|
|
711
568
|
}
|
|
712
569
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
var chCbAtKey = function chCbAtKey(res, isErr) {
|
|
570
|
+
keys.forEach(key => {
|
|
571
|
+
var chCbAtKey = (res, isErr) => {
|
|
716
572
|
if (completed) {
|
|
717
573
|
return;
|
|
718
574
|
}
|
|
719
|
-
|
|
720
575
|
if (isErr || (0, _channel.isEnd)(res) || res === CHANNEL_END || res === TASK_CANCEL) {
|
|
721
576
|
cb.cancel();
|
|
722
577
|
cb(res, isErr);
|
|
@@ -726,89 +581,70 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
726
581
|
checkEffectEnd();
|
|
727
582
|
}
|
|
728
583
|
};
|
|
729
|
-
|
|
730
584
|
chCbAtKey.cancel = _utils.noop;
|
|
731
585
|
childCbs[key] = chCbAtKey;
|
|
732
586
|
});
|
|
733
|
-
|
|
734
|
-
cb.cancel = function () {
|
|
587
|
+
cb.cancel = () => {
|
|
735
588
|
if (!completed) {
|
|
736
589
|
completed = true;
|
|
737
|
-
keys.forEach(
|
|
738
|
-
return childCbs[key].cancel();
|
|
739
|
-
});
|
|
590
|
+
keys.forEach(key => childCbs[key].cancel());
|
|
740
591
|
}
|
|
741
592
|
};
|
|
742
|
-
|
|
743
|
-
keys.forEach(function (key) {
|
|
744
|
-
return runEffect(effects[key], effectId, key, childCbs[key]);
|
|
745
|
-
});
|
|
593
|
+
keys.forEach(key => runEffect(effects[key], effectId, key, childCbs[key]));
|
|
746
594
|
}
|
|
747
|
-
|
|
748
595
|
function runRaceEffect(effects, effectId, cb) {
|
|
749
596
|
var completed;
|
|
750
597
|
var keys = Object.keys(effects);
|
|
751
598
|
var childCbs = {};
|
|
752
|
-
keys.forEach(
|
|
753
|
-
var chCbAtKey =
|
|
599
|
+
keys.forEach(key => {
|
|
600
|
+
var chCbAtKey = (res, isErr) => {
|
|
754
601
|
if (completed) {
|
|
755
602
|
return;
|
|
756
603
|
}
|
|
757
|
-
|
|
758
604
|
if (isErr) {
|
|
759
605
|
// Race Auto cancellation
|
|
760
606
|
cb.cancel();
|
|
761
607
|
cb(res, true);
|
|
762
608
|
} else if (!(0, _channel.isEnd)(res) && res !== CHANNEL_END && res !== TASK_CANCEL) {
|
|
763
|
-
var _response;
|
|
764
|
-
|
|
765
609
|
cb.cancel();
|
|
766
610
|
completed = true;
|
|
767
|
-
var response =
|
|
768
|
-
|
|
611
|
+
var response = {
|
|
612
|
+
[key]: res
|
|
613
|
+
};
|
|
614
|
+
cb(_utils.is.array(effects) ? [].slice.call((0, _objectSpread2.default)((0, _objectSpread2.default)({}, response), {}, {
|
|
769
615
|
length: keys.length
|
|
770
616
|
})) : response);
|
|
771
617
|
}
|
|
772
618
|
};
|
|
773
|
-
|
|
774
619
|
chCbAtKey.cancel = _utils.noop;
|
|
775
620
|
childCbs[key] = chCbAtKey;
|
|
776
621
|
});
|
|
777
|
-
|
|
778
|
-
cb.cancel = function () {
|
|
622
|
+
cb.cancel = () => {
|
|
779
623
|
// prevents unnecessary cancellation
|
|
780
624
|
if (!completed) {
|
|
781
625
|
completed = true;
|
|
782
|
-
keys.forEach(
|
|
783
|
-
return childCbs[key].cancel();
|
|
784
|
-
});
|
|
626
|
+
keys.forEach(key => childCbs[key].cancel());
|
|
785
627
|
}
|
|
786
628
|
};
|
|
787
|
-
|
|
788
|
-
keys.forEach(function (key) {
|
|
629
|
+
keys.forEach(key => {
|
|
789
630
|
if (completed) {
|
|
790
631
|
return;
|
|
791
632
|
}
|
|
792
|
-
|
|
793
633
|
runEffect(effects[key], effectId, key, childCbs[key]);
|
|
794
634
|
});
|
|
795
635
|
}
|
|
796
|
-
|
|
797
636
|
function runSelectEffect(_ref7, cb) {
|
|
798
637
|
var selector = _ref7.selector,
|
|
799
|
-
|
|
800
|
-
|
|
638
|
+
args = _ref7.args;
|
|
801
639
|
try {
|
|
802
640
|
// compat
|
|
803
|
-
var state =
|
|
804
|
-
|
|
641
|
+
var state = (0, _objectSpread2.default)({}, getState());
|
|
805
642
|
state[getContext(_utils2.pageKey)] = state[getReducerKey()];
|
|
806
|
-
cb(selector
|
|
643
|
+
cb(selector(state, ...args));
|
|
807
644
|
} catch (error) {
|
|
808
645
|
cb(error, true);
|
|
809
646
|
}
|
|
810
647
|
}
|
|
811
|
-
|
|
812
648
|
function runSelectSelfEffect(_, cb) {
|
|
813
649
|
try {
|
|
814
650
|
var state = getState()[getReducerKey()];
|
|
@@ -817,19 +653,17 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
817
653
|
cb(error, true);
|
|
818
654
|
}
|
|
819
655
|
}
|
|
820
|
-
|
|
821
656
|
function runPutMutationEffect(_ref8, cb) {
|
|
822
657
|
var fn = _ref8.fn;
|
|
823
658
|
var action = {
|
|
824
659
|
type: '@@INNER/SAGA_EDIT',
|
|
825
660
|
page: getReducerKey(),
|
|
826
|
-
fn
|
|
661
|
+
fn
|
|
827
662
|
};
|
|
828
663
|
return runPutEffect({
|
|
829
|
-
action
|
|
664
|
+
action
|
|
830
665
|
}, cb);
|
|
831
666
|
}
|
|
832
|
-
|
|
833
667
|
function runPutAsyncEffect(_ref9, cb) {
|
|
834
668
|
var action = _ref9.action;
|
|
835
669
|
return runPutEffect({
|
|
@@ -838,45 +672,35 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
838
672
|
if (err) {
|
|
839
673
|
return cb(res, err);
|
|
840
674
|
}
|
|
841
|
-
|
|
842
675
|
resolvePromise(action['@@INNER/DONE_MARK'], cb);
|
|
843
676
|
});
|
|
844
677
|
}
|
|
845
|
-
|
|
846
678
|
function runChannelEffect(_ref10, cb) {
|
|
847
679
|
var pattern = _ref10.pattern,
|
|
848
|
-
|
|
680
|
+
buffer = _ref10.buffer;
|
|
849
681
|
var match = matcher(pattern);
|
|
850
682
|
match.pattern = pattern;
|
|
851
683
|
cb((0, _channel.eventChannel)(subscribe, buffer || _buffers.buffers.fixed(), match));
|
|
852
684
|
}
|
|
853
|
-
|
|
854
685
|
function runCancelledEffect(data, cb) {
|
|
855
686
|
cb(!!mainTask.isCancelled);
|
|
856
687
|
}
|
|
857
|
-
|
|
858
688
|
function runFlushEffect(channel, cb) {
|
|
859
689
|
channel.flush(cb);
|
|
860
690
|
}
|
|
861
|
-
|
|
862
691
|
function runGetContextEffect(prop, cb) {
|
|
863
692
|
cb(prop === ' ' ? taskContext : taskContext[prop]);
|
|
864
693
|
}
|
|
865
|
-
|
|
866
694
|
function runSetContextEffect(props, cb) {
|
|
867
695
|
_utils.object.assign(taskContext, props);
|
|
868
|
-
|
|
869
696
|
cb();
|
|
870
697
|
}
|
|
871
|
-
|
|
872
698
|
function getContext(prop) {
|
|
873
699
|
return taskContext[prop];
|
|
874
700
|
}
|
|
875
|
-
|
|
876
701
|
function getReducerKey() {
|
|
877
702
|
return getContext(_utils2.reducerKey) || getContext(_utils2.pageKey);
|
|
878
703
|
}
|
|
879
|
-
|
|
880
704
|
function namespaceDecorate(action) {
|
|
881
705
|
if (getContext(_utils2.pageKey)) {
|
|
882
706
|
Object.defineProperty(action, _utils2.pageKey, {
|
|
@@ -886,49 +710,47 @@ function proc(iterator, subscribe, dispatch, getState, parentContext, options, p
|
|
|
886
710
|
writable: false
|
|
887
711
|
});
|
|
888
712
|
}
|
|
889
|
-
|
|
890
713
|
return action;
|
|
891
|
-
}
|
|
892
|
-
|
|
714
|
+
}
|
|
893
715
|
|
|
716
|
+
// todo remove
|
|
894
717
|
function namespaceFilter(pattern, next) {
|
|
895
718
|
var nxt = next(pattern);
|
|
896
|
-
return
|
|
719
|
+
return action => {
|
|
897
720
|
return nxt(action);
|
|
898
721
|
};
|
|
899
722
|
}
|
|
900
|
-
|
|
901
723
|
function newTask(id, name, iterator, cont) {
|
|
902
|
-
var _done, _ref11, _mutatorMap;
|
|
903
|
-
|
|
904
724
|
iterator._deferredEnd = null;
|
|
905
|
-
return
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
iterator._deferredEnd
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
725
|
+
return {
|
|
726
|
+
[_utils.TASK]: true,
|
|
727
|
+
id,
|
|
728
|
+
name,
|
|
729
|
+
get done() {
|
|
730
|
+
if (iterator._deferredEnd) {
|
|
731
|
+
return iterator._deferredEnd.promise;
|
|
732
|
+
} else {
|
|
733
|
+
var def = (0, _utils.deferred)();
|
|
734
|
+
iterator._deferredEnd = def;
|
|
735
|
+
if (!iterator._isRunning) {
|
|
736
|
+
iterator._error ? def.reject(iterator._error) : def.resolve(iterator._result);
|
|
737
|
+
}
|
|
738
|
+
return def.promise;
|
|
914
739
|
}
|
|
915
|
-
|
|
916
|
-
|
|
740
|
+
},
|
|
741
|
+
cont,
|
|
742
|
+
joiners: [],
|
|
743
|
+
cancel,
|
|
744
|
+
isRunning: () => iterator._isRunning,
|
|
745
|
+
isCancelled: () => iterator._isCancelled,
|
|
746
|
+
isAborted: () => iterator._isAborted,
|
|
747
|
+
result: () => iterator._result,
|
|
748
|
+
error: () => iterator._error,
|
|
749
|
+
setContext(props) {
|
|
750
|
+
(0, _utils.check)(props, _utils.is.object, (0, _utils.createSetContextWarning)('task', props));
|
|
751
|
+
_utils.object.assign(taskContext, props);
|
|
917
752
|
}
|
|
918
|
-
}
|
|
919
|
-
return iterator._isRunning;
|
|
920
|
-
}, _ref11.isCancelled = function isCancelled() {
|
|
921
|
-
return iterator._isCancelled;
|
|
922
|
-
}, _ref11.isAborted = function isAborted() {
|
|
923
|
-
return iterator._isAborted;
|
|
924
|
-
}, _ref11.result = function result() {
|
|
925
|
-
return iterator._result;
|
|
926
|
-
}, _ref11.error = function error() {
|
|
927
|
-
return iterator._error;
|
|
928
|
-
}, _ref11.setContext = function setContext(props) {
|
|
929
|
-
(0, _utils.check)(props, _utils.is.object, (0, _utils.createSetContextWarning)('task', props));
|
|
930
|
-
|
|
931
|
-
_utils.object.assign(taskContext, props);
|
|
932
|
-
}, _defineEnumerableProperties(_ref11, _mutatorMap), _ref11;
|
|
753
|
+
};
|
|
933
754
|
}
|
|
934
|
-
}
|
|
755
|
+
}
|
|
756
|
+
//# sourceMappingURL=proc.js.map
|