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