"use strict";var exports=module.exports={};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TASK_CANCEL = exports.CHANNEL_END = exports.NOT_ITERATOR_ERROR = undefined;
var _keys = require('../../../babel-runtime/core-js/object/keys.js');
var _keys2 = _interopRequireDefault(_keys);
var _from = require('../../../babel-runtime/core-js/array/from.js');
var _from2 = _interopRequireDefault(_from);
var _defineProperty2 = require('../../../babel-runtime/core-js/object/define-property.js');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
exports.default = proc;
var _utils = require('./utils.js');
var _scheduler = require('./scheduler.js');
var _io = require('./io.js');
var _channel = require('./channel.js');
var _buffers = require('./buffers.js');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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;(0, _defineProperty3.default)(obj, key, desc);
}return obj;
}
function _toConsumableArray(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}return arr2;
} else {
return (0, _from2.default)(arr);
}
}
function _defineProperty(obj, key, value) {
if (key in obj) {
(0, _defineProperty3.default)(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
} else {
obj[key] = value;
}return obj;
}
var isDev = "development" === 'development';
var NOT_ITERATOR_ERROR = exports.NOT_ITERATOR_ERROR = 'proc first argument (Saga function result) must be an iterator';
var CHANNEL_END = exports.CHANNEL_END = {
toString: function toString() {
return '@@redux-saga/CHANNEL_END';
}
};
var TASK_CANCEL = exports.TASK_CANCEL = {
toString: function toString() {
return '@@redux-saga/TASK_CANCEL';
}
};
var matchers = {
wildcard: function wildcard() {
return _utils.kTrue;
},
default: function _default(pattern) {
return function (input) {
return input.type === pattern;
};
},
array: function array(patterns) {
return function (input) {
return patterns.some(function (p) {
return p === input.type;
});
};
},
predicate: function predicate(_predicate) {
return function (input) {
return _predicate(input);
};
}
};
function matcher(pattern) {
return (pattern === '*' ? matchers.wildcard : _utils.is.array(pattern) ? matchers.array : _utils.is.func(pattern) ? matchers.predicate : matchers.default)(pattern);
}
/**
Used to track a parent task and its forks
In the new fork model, forked tasks are attached by default to their parent
We model this using the concept of Parent task && main Task
main task is the main flow of the current Generator, the parent tasks is the
aggregation of the main tasks + all its forked tasks.
Thus the whole model represents an execution tree with multiple branches (vs the
linear execution tree in sequential (non parallel) programming)
A parent tasks has the following semantics
- It completes iff all its forks either complete or all cancelled
- If it's cancelled, all forks are cancelled as well
- It aborts if any uncaught error bubbles up from forks
- If it completes, the return value is the one returned by the main task
**/
function forkQueue(name, mainTask, cb) {
var tasks = [],
result = void 0,
completed = false;
addTask(mainTask);
function abort(err) {
cancelAll();
cb(err, true);
}
function addTask(task) {
tasks.push(task);
task.cont = function (res, isErr) {
if (completed) {
return;
}
(0, _utils.remove)(tasks, task);
task.cont = _utils.noop;
if (isErr) {
abort(res);
} else {
if (task === mainTask) {
result = res;
}
if (!tasks.length) {
completed = true;
cb(result);
}
}
};
// task.cont.cancel = task.cancel
}
function cancelAll() {
if (completed) {
return;
}
completed = true;
tasks.forEach(function (t) {
t.cont = _utils.noop;
t.cancel();
});
tasks = [];
}
return {
addTask: addTask,
cancelAll: cancelAll,
abort: abort,
getTasks: function getTasks() {
return tasks;
},
taskNames: function taskNames() {
return tasks.map(function (t) {
return t.name;
});
}
};
}
function createTaskIterator(_ref) {
var context = _ref.context,
fn = _ref.fn,
args = _ref.args;
if (_utils.is.iterator(fn)) {
return fn;
}
// catch synchronous failures; see #152 and #441
var result = void 0,
error = void 0;
try {
result = fn.apply(context, args);
} catch (err) {
error = err;
}
// i.e. a generator function returns an iterator
if (_utils.is.iterator(result)) {
return result;
}
// do not bubble up synchronous failures for detached forks
// instead create a failed task. See #152 and #441
return error ? (0, _utils.makeIterator)(function () {
throw error;
}) : (0, _utils.makeIterator)(function () {
var pc = void 0;
var eff = { done: false, value: result };
var ret = function ret(value) {
return { done: true, value: value };
};
return function (arg) {
if (!pc) {
pc = true;
return eff;
} else {
return ret(arg);
}
};
}());
}
function wrapHelper(helper) {
return {
fn: helper
};
}
function proc(iterator) {
var subscribe = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
return _utils.noop;
};
var dispatch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _utils.noop;
var getState = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _utils.noop;
var options = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
var parentEffectId = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
var name = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 'anonymous';
var cont = arguments[7];
(0, _utils.check)(iterator, _utils.is.iterator, NOT_ITERATOR_ERROR);
var sagaMonitor = options.sagaMonitor,
logger = options.logger,
onError = options.onError;
var log = logger || _utils.log;
var stdChannel = (0, _channel.stdChannel)(subscribe);
/**
Tracks the current effect cancellation
Each time the generator progresses. calling runEffect will set a new value
on it. It allows propagating cancellation to child effects
**/
next.cancel = _utils.noop;
/**
Creates a new task descriptor for this generator, We'll also create a main task
to track the main flow (besides other forked tasks)
**/
var task = newTask(parentEffectId, name, iterator, cont);
var mainTask = { name: name, cancel: cancelMain, isRunning: true };
var taskQueue = forkQueue(name, mainTask, end);
/**
cancellation of the main task. We'll simply resume the Generator with a Cancel
**/
function cancelMain() {
if (mainTask.isRunning && !mainTask.isCancelled) {
mainTask.isCancelled = true;
next(TASK_CANCEL);
}
}
/**
This may be called by a parent generator to trigger/propagate cancellation
cancel all pending tasks (including the main task), then end the current task.
Cancellation propagates down to the whole execution tree holded by this Parent task
It's also propagated to all joiners of this task and their execution tree/joiners
Cancellation is noop for terminated/Cancelled tasks tasks
**/
function cancel() {
/**
We need to check both Running and Cancelled status
Tasks can be Cancelled but still Running
**/
if (
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序精品:医药网:tab变换,使用Labrador

共552个文件
js:471个
png:33个
wxss:8个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
14 浏览量
2023-06-01
15:40:21
上传
评论
收藏 2.73MB RAR 举报
温馨提示
微信小程序精品:医药网:tab变换,使用Labrador
资源推荐
资源详情
资源评论

















收起资源包目录





































































































共 552 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论


蒙奇·D·路飞-
- 粉丝: 4441
- 资源: 407
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


安全验证
文档复制为VIP权益,开通VIP直接复制
