Apps Home
|
Create an App
Mini goal menu
Author:
rainydio_bc
Description
Source Code
Launch App
Current Users
Created by:
Rainydio_Bc
(function (setTimeout, clearTimeout) { (function (cb) { 'use strict'; cb = cb && cb.hasOwnProperty('default') ? cb['default'] : cb; function symbolObservablePonyfill(root) { var result; var Symbol = root.Symbol; if (typeof Symbol === 'function') { if (Symbol.observable) { result = Symbol.observable; } else { result = Symbol('observable'); Symbol.observable = result; } } else { result = '@@observable'; } return result; } /* global window */ var root; if (typeof self !== 'undefined') { root = self; } else if (typeof window !== 'undefined') { root = window; } else if (typeof global !== 'undefined') { root = global; } else if (typeof module !== 'undefined') { root = module; } else { root = Function('return this')(); } var result = symbolObservablePonyfill(root); /** * These are private action types reserved by Redux. * For any unknown actions, you must return the current state. * If the current state is undefined, you must return the initial state. * Do not reference these action types directly in your code. */ var randomString = function randomString() { return Math.random().toString(36).substring(7).split('').join('.'); }; var ActionTypes = { INIT: "@@redux/INIT" + randomString(), REPLACE: "@@redux/REPLACE" + randomString(), PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() { return "@@redux/PROBE_UNKNOWN_ACTION" + randomString(); } }; /** * @param {any} obj The object to inspect. * @returns {boolean} True if the argument appears to be a plain object. */ function isPlainObject(obj) { if (typeof obj !== 'object' || obj === null) return false; var proto = obj; while (Object.getPrototypeOf(proto) !== null) { proto = Object.getPrototypeOf(proto); } return Object.getPrototypeOf(obj) === proto; } /** * Creates a Redux store that holds the state tree. * The only way to change the data in the store is to call `dispatch()` on it. * * There should only be a single store in your app. To specify how different * parts of the state tree respond to actions, you may combine several reducers * into a single reducer function by using `combineReducers`. * * @param {Function} reducer A function that returns the next state tree, given * the current state tree and the action to handle. * * @param {any} [preloadedState] The initial state. You may optionally specify it * to hydrate the state from the server in universal apps, or to restore a * previously serialized user session. * If you use `combineReducers` to produce the root reducer function, this must be * an object with the same shape as `combineReducers` keys. * * @param {Function} [enhancer] The store enhancer. You may optionally specify it * to enhance the store with third-party capabilities such as middleware, * time travel, persistence, etc. The only store enhancer that ships with Redux * is `applyMiddleware()`. * * @returns {Store} A Redux store that lets you read the state, dispatch actions * and subscribe to changes. */ function createStore(reducer, preloadedState, enhancer) { var _ref2; if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') { throw new Error('It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function'); } if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { enhancer = preloadedState; preloadedState = undefined; } if (typeof enhancer !== 'undefined') { if (typeof enhancer !== 'function') { throw new Error('Expected the enhancer to be a function.'); } return enhancer(createStore)(reducer, preloadedState); } if (typeof reducer !== 'function') { throw new Error('Expected the reducer to be a function.'); } var currentReducer = reducer; var currentState = preloadedState; var currentListeners = []; var nextListeners = currentListeners; var isDispatching = false; function ensureCanMutateNextListeners() { if (nextListeners === currentListeners) { nextListeners = currentListeners.slice(); } } /** * Reads the state tree managed by the store. * * @returns {any} The current state tree of your application. */ function getState() { if (isDispatching) { throw new Error('You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.'); } return currentState; } /** * Adds a change listener. It will be called any time an action is dispatched, * and some part of the state tree may potentially have changed. You may then * call `getState()` to read the current state tree inside the callback. * * You may call `dispatch()` from a change listener, with the following * caveats: * * 1. The subscriptions are snapshotted just before every `dispatch()` call. * If you subscribe or unsubscribe while the listeners are being invoked, this * will not have any effect on the `dispatch()` that is currently in progress. * However, the next `dispatch()` call, whether nested or not, will use a more * recent snapshot of the subscription list. * * 2. The listener should not expect to see all state changes, as the state * might have been updated multiple times during a nested `dispatch()` before * the listener is called. It is, however, guaranteed that all subscribers * registered before the `dispatch()` started will be called with the latest * state by the time it exits. * * @param {Function} listener A callback to be invoked on every dispatch. * @returns {Function} A function to remove this change listener. */ function subscribe(listener) { if (typeof listener !== 'function') { throw new Error('Expected the listener to be a function.'); } if (isDispatching) { throw new Error('You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api-reference/store#subscribe(listener) for more details.'); } var isSubscribed = true; ensureCanMutateNextListeners(); nextListeners.push(listener); return function unsubscribe() { if (!isSubscribed) { return; } if (isDispatching) { throw new Error('You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api-reference/store#subscribe(listener) for more details.'); } isSubscribed = false; ensureCanMutateNextListeners(); var index = nextListeners.indexOf(listener); nextListeners.splice(index, 1); }; } /** * Dispatches an action. It is the only way to trigger a state change. * * The `reducer` function, used to create the store, will be called with the * current state tree and the given `action`. Its return value will * be considered the **next** state of the tree, and the change listeners * will be notified. * * The base implementation only supports plain object actions. If you want to * dispatch a Promise, an Observable, a thunk, or something else, you need to * wrap your store creating function into the corresponding middleware. For * example, see the documentation for the `redux-thunk` package. Even the * middleware will eventually dispatch plain object actions using this method. * * @param {Object} action A plain object representing “what changed”. It is * a good idea to keep actions serializable so you can record and replay user * sessions, or use the time travelling `redux-devtools`. An action must have * a `type` property which may not be `undefined`. It is a good idea to use * string constants for action types. * * @returns {Object} For convenience, the same action object you dispatched. * * Note that, if you use a custom middleware, it may wrap `dispatch()` to * return something else (for example, a Promise you can await). */ function dispatch(action) { if (!isPlainObject(action)) { throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.'); } if (typeof action.type === 'undefined') { throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?'); } if (isDispatching) { throw new Error('Reducers may not dispatch actions.'); } try { isDispatching = true; currentState = currentReducer(currentState, action); } finally { isDispatching = false; } var listeners = currentListeners = nextListeners; for (var i = 0; i < listeners.length; i++) { var listener = listeners[i]; listener(); } return action; } /** * Replaces the reducer currently used by the store to calculate the state. * * You might need this if your app implements code splitting and you want to * load some of the reducers dynamically. You might also need this if you * implement a hot reloading mechanism for Redux. * * @param {Function} nextReducer The reducer for the store to use instead. * @returns {void} */ function replaceReducer(nextReducer) { if (typeof nextReducer !== 'function') { throw new Error('Expected the nextReducer to be a function.'); } currentReducer = nextReducer; dispatch({ type: ActionTypes.REPLACE }); } /** * Interoperability point for observable/reactive libraries. * @returns {observable} A minimal observable of state changes. * For more information, see the observable proposal: * https://github.com/tc39/proposal-observable */ function observable() { var _ref; var outerSubscribe = subscribe; return _ref = { /** * The minimal observable subscription method. * @param {Object} observer Any object that can be used as an observer. * The observer object should have a `next` method. * @returns {subscription} An object with an `unsubscribe` method that can * be used to unsubscribe the observable from the store, and prevent further * emission of values from the observable. */ subscribe: function subscribe(observer) { if (typeof observer !== 'object' || observer === null) { throw new TypeError('Expected the observer to be an object.'); } function observeState() { if (observer.next) { observer.next(getState()); } } observeState(); var unsubscribe = outerSubscribe(observeState); return { unsubscribe: unsubscribe }; } }, _ref[result] = function () { return this; }, _ref; } // When a store is created, an "INIT" action is dispatched so that every // reducer returns their initial state. This effectively populates // the initial state tree. dispatch({ type: ActionTypes.INIT }); return _ref2 = { dispatch: dispatch, subscribe: subscribe, getState: getState, replaceReducer: replaceReducer }, _ref2[result] = observable, _ref2; } function getUndefinedStateErrorMessage(key, action) { var actionType = action && action.type; var actionDescription = actionType && "action \"" + String(actionType) + "\"" || 'an action'; return "Given " + actionDescription + ", reducer \"" + key + "\" returned undefined. " + "To ignore an action, you must explicitly return the previous state. " + "If you want this reducer to hold no value, you can return null instead of undefined."; } function assertReducerShape(reducers) { Object.keys(reducers).forEach(function (key) { var reducer = reducers[key]; var initialState = reducer(undefined, { type: ActionTypes.INIT }); if (typeof initialState === 'undefined') { throw new Error("Reducer \"" + key + "\" returned undefined during initialization. " + "If the state passed to the reducer is undefined, you must " + "explicitly return the initial state. The initial state may " + "not be undefined. If you don't want to set a value for this reducer, " + "you can use null instead of undefined."); } if (typeof reducer(undefined, { type: ActionTypes.PROBE_UNKNOWN_ACTION() }) === 'undefined') { throw new Error("Reducer \"" + key + "\" returned undefined when probed with a random type. " + ("Don't try to handle " + ActionTypes.INIT + " or other actions in \"redux/*\" ") + "namespace. They are considered private. Instead, you must return the " + "current state for any unknown actions, unless it is undefined, " + "in which case you must return the initial state, regardless of the " + "action type. The initial state may not be undefined, but can be null."); } }); } /** * Turns an object whose values are different reducer functions, into a single * reducer function. It will call every child reducer, and gather their results * into a single state object, whose keys correspond to the keys of the passed * reducer functions. * * @param {Object} reducers An object whose values correspond to different * reducer functions that need to be combined into one. One handy way to obtain * it is to use ES6 `import * as reducers` syntax. The reducers may never return * undefined for any action. Instead, they should return their initial state * if the state passed to them was undefined, and the current state for any * unrecognized action. * * @returns {Function} A reducer function that invokes every reducer inside the * passed object, and builds a state object with the same shape. */ function combineReducers(reducers) { var reducerKeys = Object.keys(reducers); var finalReducers = {}; for (var i = 0; i < reducerKeys.length; i++) { var key = reducerKeys[i]; if (typeof reducers[key] === 'function') { finalReducers[key] = reducers[key]; } } var finalReducerKeys = Object.keys(finalReducers); var shapeAssertionError; try { assertReducerShape(finalReducers); } catch (e) { shapeAssertionError = e; } return function combination(state, action) { if (state === void 0) { state = {}; } if (shapeAssertionError) { throw shapeAssertionError; } var hasChanged = false; var nextState = {}; for (var _i = 0; _i < finalReducerKeys.length; _i++) { var _key = finalReducerKeys[_i]; var reducer = finalReducers[_key]; var previousStateForKey = state[_key]; var nextStateForKey = reducer(previousStateForKey, action); if (typeof nextStateForKey === 'undefined') { var errorMessage = getUndefinedStateErrorMessage(_key, action); throw new Error(errorMessage); } nextState[_key] = nextStateForKey; hasChanged = hasChanged || nextStateForKey !== previousStateForKey; } return hasChanged ? nextState : state; }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } /** * Composes single-argument functions from right to left. The rightmost * function can take multiple arguments as it provides the signature for * the resulting composite function. * * @param {...Function} funcs The functions to compose. * @returns {Function} A function obtained by composing the argument functions * from right to left. For example, compose(f, g, h) is identical to doing * (...args) => f(g(h(...args))). */ function compose() { for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) { funcs[_key] = arguments[_key]; } if (funcs.length === 0) { return function (arg) { return arg; }; } if (funcs.length === 1) { return funcs[0]; } return funcs.reduce(function (a, b) { return function () { return a(b.apply(void 0, arguments)); }; }); } /** * Creates a store enhancer that applies middleware to the dispatch method * of the Redux store. This is handy for a variety of tasks, such as expressing * asynchronous actions in a concise manner, or logging every action payload. * * See `redux-thunk` package as an example of the Redux middleware. * * Because middleware is potentially asynchronous, this should be the first * store enhancer in the composition chain. * * Note that each middleware will be given the `dispatch` and `getState` functions * as named arguments. * * @param {...Function} middlewares The middleware chain to be applied. * @returns {Function} A store enhancer applying the middleware. */ function applyMiddleware() { for (var _len = arguments.length, middlewares = new Array(_len), _key = 0; _key < _len; _key++) { middlewares[_key] = arguments[_key]; } return function (createStore) { return function () { var store = createStore.apply(void 0, arguments); var _dispatch = function dispatch() { throw new Error("Dispatching while constructing your middleware is not allowed. " + "Other middleware would not be applied to this dispatch."); }; var middlewareAPI = { getState: store.getState, dispatch: function dispatch() { return _dispatch.apply(void 0, arguments); } }; var chain = middlewares.map(function (middleware) { return middleware(middlewareAPI); }); _dispatch = compose.apply(void 0, chain)(store.dispatch); return _objectSpread({}, store, { dispatch: _dispatch }); }; }; } var createSymbol = function createSymbol(name) { return "@@redux-saga/" + name; }; var CANCEL = /*#__PURE__*/ createSymbol('CANCEL_PROMISE'); var CHANNEL_END_TYPE = /*#__PURE__*/ createSymbol('CHANNEL_END'); var IO = /*#__PURE__*/ createSymbol('IO'); var MATCH = /*#__PURE__*/ createSymbol('MATCH'); var MULTICAST = /*#__PURE__*/ createSymbol('MULTICAST'); var SAGA_ACTION = /*#__PURE__*/ createSymbol('SAGA_ACTION'); var SELF_CANCELLATION = /*#__PURE__*/ createSymbol('SELF_CANCELLATION'); var TASK = /*#__PURE__*/ createSymbol('TASK'); var TASK_CANCEL = /*#__PURE__*/ createSymbol('TASK_CANCEL'); var TERMINATE = /*#__PURE__*/ createSymbol('TERMINATE'); var SAGA_LOCATION = /*#__PURE__*/ createSymbol('LOCATION'); 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); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var undef = function undef(v) { return v === null || v === undefined; }; var notUndef = function notUndef(v) { return v !== null && v !== undefined; }; var func = function func(f) { return typeof f === 'function'; }; var string = function string(s) { return typeof s === 'string'; }; var array = Array.isArray; var promise = function promise(p) { return p && func(p.then); }; var iterator = function iterator(it) { return it && func(it.next) && func(it.throw); }; var pattern = function pattern(pat) { return pat && (string(pat) || symbol(pat) || func(pat) || array(pat) && pat.every(pattern)); }; var channel = function channel(ch) { return ch && func(ch.take) && func(ch.close); }; var stringableFunc = function stringableFunc(f) { return func(f) && f.hasOwnProperty('toString'); }; var symbol = function symbol(sym) { return Boolean(sym) && typeof Symbol === 'function' && sym.constructor === Symbol && sym !== Symbol.prototype; }; var multicast = function multicast(ch) { return channel(ch) && ch[MULTICAST]; }; function delayP(ms, val) { if (val === void 0) { val = true; } var timeoutId; var promise = new Promise(function (resolve) { timeoutId = setTimeout(resolve, ms, val); }); promise[CANCEL] = function () { clearTimeout(timeoutId); }; return promise; } var konst = function konst(v) { return function () { return v; }; }; var kTrue = /*#__PURE__*/ konst(true); var noop = function noop() {}; var identity = function identity(v) { return v; }; var assignWithSymbols = function assignWithSymbols(target, source) { _extends(target, source); if (Object.getOwnPropertySymbols) { Object.getOwnPropertySymbols(source).forEach(function (s) { target[s] = source[s]; }); } }; var flatMap = function flatMap(mapper, arr) { var _ref; return (_ref = []).concat.apply(_ref, arr.map(mapper)); }; function remove(array$$1, item) { var index = array$$1.indexOf(item); if (index >= 0) { array$$1.splice(index, 1); } } function once(fn) { var called = false; return function () { if (called) { return; } called = true; fn(); }; } var kThrow = function kThrow(err) { throw err; }; var kReturn = function kReturn(value) { return { value: value, done: true }; }; function makeIterator(next, thro, name) { if (thro === void 0) { thro = kThrow; } if (name === void 0) { name = 'iterator'; } var iterator$$1 = { meta: { name: name }, next: next, throw: thro, return: kReturn, isSagaIterator: true }; if (typeof Symbol !== 'undefined') { iterator$$1[Symbol.iterator] = function () { return iterator$$1; }; } return iterator$$1; } function logError(error, _ref2) { var sagaStack = _ref2.sagaStack; /*eslint-disable no-console*/ console.error(error); console.error(sagaStack); } var createEmptyArray = function createEmptyArray(n) { return Array.apply(null, new Array(n)); }; var wrapSagaDispatch = function wrapSagaDispatch(dispatch) { return function (action) { return dispatch(Object.defineProperty(action, SAGA_ACTION, { value: true })); }; }; var shouldTerminate = function shouldTerminate(res) { return res === TERMINATE; }; var shouldCancel = function shouldCancel(res) { return res === TASK_CANCEL; }; var shouldComplete = function shouldComplete(res) { return shouldTerminate(res) || shouldCancel(res); }; function createAllStyleChildCallbacks(shape, parentCallback) { var keys = Object.keys(shape); var totalCount = keys.length; var completedCount = 0; var completed; var results = array(shape) ? createEmptyArray(totalCount) : {}; var childCallbacks = {}; function checkEnd() { if (completedCount === totalCount) { completed = true; parentCallback(results); } } keys.forEach(function (key) { var chCbAtKey = function chCbAtKey(res, isErr) { if (completed) { return; } if (isErr || shouldComplete(res)) { parentCallback.cancel(); parentCallback(res, isErr); } else { results[key] = res; completedCount++; checkEnd(); } }; chCbAtKey.cancel = noop; childCallbacks[key] = chCbAtKey; }); parentCallback.cancel = function () { if (!completed) { completed = true; keys.forEach(function (key) { return childCallbacks[key].cancel(); }); } }; return childCallbacks; } function getMetaInfo(fn) { return { name: fn.name || 'anonymous', location: getLocation(fn) }; } function getLocation(instrumented) { return instrumented[SAGA_LOCATION]; } var BUFFER_OVERFLOW = "Channel's Buffer overflow!"; var ON_OVERFLOW_THROW = 1; var ON_OVERFLOW_DROP = 2; var ON_OVERFLOW_SLIDE = 3; var ON_OVERFLOW_EXPAND = 4; var zeroBuffer = { isEmpty: kTrue, put: noop, take: noop }; function ringBuffer(limit, overflowAction) { if (limit === void 0) { limit = 10; } var arr = new Array(limit); var length = 0; var pushIndex = 0; var popIndex = 0; var push = function push(it) { arr[pushIndex] = it; pushIndex = (pushIndex + 1) % limit; length++; }; var take = function take() { if (length != 0) { var it = arr[popIndex]; arr[popIndex] = null; length--; popIndex = (popIndex + 1) % limit; return it; } }; var flush = function flush() { var items = []; while (length) { items.push(take()); } return items; }; return { isEmpty: function isEmpty() { return length == 0; }, put: function put(it) { if (length < limit) { push(it); } else { var doubledLimit; switch (overflowAction) { case ON_OVERFLOW_THROW: throw new Error(BUFFER_OVERFLOW); case ON_OVERFLOW_SLIDE: arr[pushIndex] = it; pushIndex = (pushIndex + 1) % limit; popIndex = pushIndex; break; case ON_OVERFLOW_EXPAND: doubledLimit = 2 * limit; arr = flush(); length = arr.length; pushIndex = arr.length; popIndex = 0; arr.length = doubledLimit; limit = doubledLimit; push(it); break; default: // DROP } } }, take: take, flush: flush }; } var none = function none() { return zeroBuffer; }; var fixed = function fixed(limit) { return ringBuffer(limit, ON_OVERFLOW_THROW); }; var dropping = function dropping(limit) { return ringBuffer(limit, ON_OVERFLOW_DROP); }; var sliding = function sliding(limit) { return ringBuffer(limit, ON_OVERFLOW_SLIDE); }; var expanding = function expanding(initialSize) { return ringBuffer(initialSize, ON_OVERFLOW_EXPAND); }; var buffers = /*#__PURE__*/Object.freeze({ none: none, fixed: fixed, dropping: dropping, sliding: sliding, expanding: expanding }); var TAKE = 'TAKE'; var PUT = 'PUT'; var ALL = 'ALL'; var RACE = 'RACE'; var CALL = 'CALL'; var CPS = 'CPS'; var FORK = 'FORK'; var JOIN = 'JOIN'; var CANCEL$1 = 'CANCEL'; var SELECT = 'SELECT'; var ACTION_CHANNEL = 'ACTION_CHANNEL'; var CANCELLED = 'CANCELLED'; var FLUSH = 'FLUSH'; var GET_CONTEXT = 'GET_CONTEXT'; var SET_CONTEXT = 'SET_CONTEXT'; var effectTypes = /*#__PURE__*/Object.freeze({ TAKE: TAKE, PUT: PUT, ALL: ALL, RACE: RACE, CALL: CALL, CPS: CPS, FORK: FORK, JOIN: JOIN, CANCEL: CANCEL$1, SELECT: SELECT, ACTION_CHANNEL: ACTION_CHANNEL, CANCELLED: CANCELLED, FLUSH: FLUSH, GET_CONTEXT: GET_CONTEXT, SET_CONTEXT: SET_CONTEXT }); var makeEffect = function makeEffect(type, payload) { var _ref; return _ref = {}, _ref[IO] = true, _ref.combinator = false, _ref.type = type, _ref.payload = payload, _ref; }; function take(patternOrChannel, multicastPattern) { if (patternOrChannel === void 0) { patternOrChannel = '*'; } if (pattern(patternOrChannel)) { return makeEffect(TAKE, { pattern: patternOrChannel }); } if (multicast(patternOrChannel) && notUndef(multicastPattern) && pattern(multicastPattern)) { return makeEffect(TAKE, { channel: patternOrChannel, pattern: multicastPattern }); } if (channel(patternOrChannel)) { return makeEffect(TAKE, { channel: patternOrChannel }); } } function put(channel$1, action) { if (undef(action)) { action = channel$1; // `undefined` instead of `null` to make default parameter work channel$1 = undefined; } return makeEffect(PUT, { channel: channel$1, action: action }); } function getFnCallDescriptor(fnDescriptor, args) { var context = null; var fn; if (func(fnDescriptor)) { fn = fnDescriptor; } else { if (array(fnDescriptor)) { context = fnDescriptor[0]; fn = fnDescriptor[1]; } else { context = fnDescriptor.context; fn = fnDescriptor.fn; } if (context && string(fn) && func(context[fn])) { fn = context[fn]; } } return { context: context, fn: fn, args: args }; } function call(fnDescriptor) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } return makeEffect(CALL, getFnCallDescriptor(fnDescriptor, args)); } function fork(fnDescriptor) { for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { args[_key3 - 1] = arguments[_key3]; } return makeEffect(FORK, getFnCallDescriptor(fnDescriptor, args)); } function cancel(taskOrTasks) { if (taskOrTasks === void 0) { taskOrTasks = SELF_CANCELLATION; } return makeEffect(CANCEL$1, taskOrTasks); } function select(selector) { if (selector === void 0) { selector = identity; } for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { args[_key5 - 1] = arguments[_key5]; } return makeEffect(SELECT, { selector: selector, args: args }); } var delay = /*#__PURE__*/ call.bind(null, delayP); function deferred() { var def = {}; def.promise = new Promise(function (resolve, reject) { def.resolve = resolve; def.reject = reject; }); return def; } var queue = []; /** Variable to hold a counting semaphore - Incrementing adds a lock and puts the scheduler in a `suspended` state (if it's not already suspended) - Decrementing releases a lock. Zero locks puts the scheduler in a `released` state. This triggers flushing the queued tasks. **/ var semaphore = 0; /** Executes a task 'atomically'. Tasks scheduled during this execution will be queued and flushed after this task has finished (assuming the scheduler endup in a released state). **/ function exec(task$$1) { try { suspend(); task$$1(); } finally { release(); } } /** Executes or queues a task depending on the state of the scheduler (`suspended` or `released`) **/ function asap(task$$1) { queue.push(task$$1); if (!semaphore) { suspend(); flush$1(); } } /** * Puts the scheduler in a `suspended` state and executes a task immediately. */ function immediately(task$$1) { try { suspend(); return task$$1(); } finally { flush$1(); } } /** Puts the scheduler in a `suspended` state. Scheduled tasks will be queued until the scheduler is released. **/ function suspend() { semaphore++; } /** Puts the scheduler in a `released` state. **/ function release() { semaphore--; } /** Releases the current lock. Executes all queued tasks if the scheduler is in the released state. **/ function flush$1() { release(); var task$$1; while (!semaphore && (task$$1 = queue.shift()) !== undefined) { exec(task$$1); } } var array$1 = function array$$1(patterns) { return function (input) { return patterns.some(function (p$$1) { return matcher(p$$1)(input); }); }; }; var predicate = function predicate(_predicate) { return function (input) { return _predicate(input); }; }; var string$1 = function string$$1(pattern$$1) { return function (input) { return input.type === String(pattern$$1); }; }; var symbol$1 = function symbol$$1(pattern$$1) { return function (input) { return input.type === pattern$$1; }; }; var wildcard = function wildcard() { return kTrue; }; function matcher(pattern$$1) { // prettier-ignore var matcherCreator = pattern$$1 === '*' ? wildcard : string(pattern$$1) ? string$1 : array(pattern$$1) ? array$1 : stringableFunc(pattern$$1) ? string$1 : func(pattern$$1) ? predicate : symbol(pattern$$1) ? symbol$1 : null; if (matcherCreator === null) { throw new Error("invalid pattern: " + pattern$$1); } return matcherCreator(pattern$$1); } var END = { type: CHANNEL_END_TYPE }; var isEnd = function isEnd(a$$1) { return a$$1 && a$$1.type === CHANNEL_END_TYPE; }; function channel$1(buffer$1) { if (buffer$1 === void 0) { buffer$1 = expanding(); } var closed = false; var takers = []; function put$$1(input) { if (closed) { return; } if (takers.length === 0) { return buffer$1.put(input); } var cb$$1 = takers.shift(); cb$$1(input); } function take$$1(cb$$1) { if (closed && buffer$1.isEmpty()) { cb$$1(END); } else if (!buffer$1.isEmpty()) { cb$$1(buffer$1.take()); } else { takers.push(cb$$1); cb$$1.cancel = function () { remove(takers, cb$$1); }; } } function flush$$1(cb$$1) { if (closed && buffer$1.isEmpty()) { cb$$1(END); return; } cb$$1(buffer$1.flush()); } function close() { if (closed) { return; } closed = true; var arr = takers; takers = []; for (var i$$1 = 0, len = arr.length; i$$1 < len; i$$1++) { var taker = arr[i$$1]; taker(END); } } return { take: take$$1, put: put$$1, flush: flush$$1, close: close }; } function multicastChannel() { var _ref; var closed = false; var currentTakers = []; var nextTakers = currentTakers; var ensureCanMutateNextTakers = function ensureCanMutateNextTakers() { if (nextTakers !== currentTakers) { return; } nextTakers = currentTakers.slice(); }; var close = function close() { closed = true; var takers = currentTakers = nextTakers; nextTakers = []; takers.forEach(function (taker) { taker(END); }); }; return _ref = {}, _ref[MULTICAST] = true, _ref.put = function put$$1(input) { if (closed) { return; } if (isEnd(input)) { close(); return; } var takers = currentTakers = nextTakers; for (var i$$1 = 0, len = takers.length; i$$1 < len; i$$1++) { var taker = takers[i$$1]; if (taker[MATCH](input)) { taker.cancel(); taker(input); } } }, _ref.take = function take$$1(cb$$1, matcher) { if (matcher === void 0) { matcher = wildcard; } if (closed) { cb$$1(END); return; } cb$$1[MATCH] = matcher; ensureCanMutateNextTakers(); nextTakers.push(cb$$1); cb$$1.cancel = once(function () { ensureCanMutateNextTakers(); remove(nextTakers, cb$$1); }); }, _ref.close = close, _ref; } function stdChannel() { var chan = multicastChannel(); var put$$1 = chan.put; chan.put = function (input) { if (input[SAGA_ACTION]) { put$$1(input); return; } asap(function () { put$$1(input); }); }; return chan; } var RUNNING = 0; var CANCELLED$1 = 1; var ABORTED = 2; var DONE = 3; function resolvePromise(promise$$1, cb$$1) { var cancelPromise = promise$$1[CANCEL]; if (func(cancelPromise)) { cb$$1.cancel = cancelPromise; } promise$$1.then(cb$$1, function (error) { cb$$1(error, true); }); } var current = 0; var nextEffectId = (function () { return ++current; }); var _effectRunnerMap; function getIteratorMetaInfo(iterator$$1, fn) { if (iterator$$1.isSagaIterator) { return { name: iterator$$1.meta.name }; } return getMetaInfo(fn); } function createTaskIterator(_ref) { var context = _ref.context, fn = _ref.fn, args = _ref.args; // catch synchronous failures; see #152 and #441 try { var result = fn.apply(context, args); // i.e. a generator function returns an iterator if (iterator(result)) { return result; } var resolved = false; var next = function next(arg) { if (!resolved) { resolved = true; // Only promises returned from fork will be interpreted. See #1573 return { value: result, done: !promise(result) }; } else { return { value: arg, done: true }; } }; return makeIterator(next); } catch (err) { // do not bubble up synchronous failures for detached forks // instead create a failed task. See #152 and #441 return makeIterator(function () { throw err; }); } } function runPutEffect(env, _ref2, cb$$1) { var channel$$1 = _ref2.channel, action = _ref2.action, resolve = _ref2.resolve; /** Schedule the put in case another saga is holding a lock. The put will be executed atomically. ie nested puts will execute after this put has terminated. **/ asap(function () { var result; try { result = (channel$$1 ? channel$$1.put : env.dispatch)(action); } catch (error) { cb$$1(error, true); return; } if (resolve && promise(result)) { resolvePromise(result, cb$$1); } else { cb$$1(result); } }); // Put effects are non cancellables } function runTakeEffect(env, _ref3, cb$$1) { var _ref3$channel = _ref3.channel, channel$$1 = _ref3$channel === void 0 ? env.channel : _ref3$channel, pattern$$1 = _ref3.pattern, maybe = _ref3.maybe; var takeCb = function takeCb(input) { if (input instanceof Error) { cb$$1(input, true); return; } if (isEnd(input) && !maybe) { cb$$1(TERMINATE); return; } cb$$1(input); }; try { channel$$1.take(takeCb, notUndef(pattern$$1) ? matcher(pattern$$1) : null); } catch (err) { cb$$1(err, true); return; } cb$$1.cancel = takeCb.cancel; } function runCallEffect(env, _ref4, cb$$1, _ref5) { var context = _ref4.context, fn = _ref4.fn, args = _ref4.args; var task$$1 = _ref5.task; // catch synchronous failures; see #152 try { var result = fn.apply(context, args); if (promise(result)) { resolvePromise(result, cb$$1); return; } if (iterator(result)) { // resolve iterator proc(env, result, task$$1.context, current, getMetaInfo(fn), /* isRoot */ false, cb$$1); return; } cb$$1(result); } catch (error) { cb$$1(error, true); } } function runCPSEffect(env, _ref6, cb$$1) { var context = _ref6.context, fn = _ref6.fn, args = _ref6.args; // CPS (ie node style functions) can define their own cancellation logic // by setting cancel field on the cb // catch synchronous failures; see #152 try { var cpsCb = function cpsCb(err, res) { if (undef(err)) { cb$$1(res); } else { cb$$1(err, true); } }; fn.apply(context, args.concat(cpsCb)); if (cpsCb.cancel) { cb$$1.cancel = cpsCb.cancel; } } catch (error) { cb$$1(error, true); } } function runForkEffect(env, _ref7, cb$$1, _ref8) { var context = _ref7.context, fn = _ref7.fn, args = _ref7.args, detached = _ref7.detached; var parent = _ref8.task; var taskIterator = createTaskIterator({ context: context, fn: fn, args: args }); var meta = getIteratorMetaInfo(taskIterator, fn); immediately(function () { var child = proc(env, taskIterator, parent.context, current, meta, detached, noop); if (detached) { cb$$1(child); } else { if (child.isRunning()) { parent.queue.addTask(child); cb$$1(child); } else if (child.isAborted()) { parent.queue.abort(child.error()); } else { cb$$1(child); } } }); // Fork effects are non cancellables } function runJoinEffect(env, taskOrTasks, cb$$1, _ref9) { var task$$1 = _ref9.task; var joinSingleTask = function joinSingleTask(taskToJoin, cb$$1) { if (taskToJoin.isRunning()) { var joiner = { task: task$$1, cb: cb$$1 }; cb$$1.cancel = function () { if (taskToJoin.isRunning()) remove(taskToJoin.joiners, joiner); }; taskToJoin.joiners.push(joiner); } else { if (taskToJoin.isAborted()) { cb$$1(taskToJoin.error(), true); } else { cb$$1(taskToJoin.result()); } } }; if (array(taskOrTasks)) { if (taskOrTasks.length === 0) { cb$$1([]); return; } var childCallbacks = createAllStyleChildCallbacks(taskOrTasks, cb$$1); taskOrTasks.forEach(function (t$$1, i$$1) { joinSingleTask(t$$1, childCallbacks[i$$1]); }); } else { joinSingleTask(taskOrTasks, cb$$1); } } function cancelSingleTask(taskToCancel) { if (taskToCancel.isRunning()) { taskToCancel.cancel(); } } function runCancelEffect(env, taskOrTasks, cb$$1, _ref10) { var task$$1 = _ref10.task; if (taskOrTasks === SELF_CANCELLATION) { cancelSingleTask(task$$1); } else if (array(taskOrTasks)) { taskOrTasks.forEach(cancelSingleTask); } else { cancelSingleTask(taskOrTasks); } cb$$1(); // cancel effects are non cancellables } function runAllEffect(env, effects, cb$$1, _ref11) { var digestEffect = _ref11.digestEffect; var effectId = current; var keys = Object.keys(effects); if (keys.length === 0) { cb$$1(array(effects) ? [] : {}); return; } var childCallbacks = createAllStyleChildCallbacks(effects, cb$$1); keys.forEach(function (key) { digestEffect(effects[key], effectId, childCallbacks[key], key); }); } function runRaceEffect(env, effects, cb$$1, _ref12) { var digestEffect = _ref12.digestEffect; var effectId = current; var keys = Object.keys(effects); var response = array(effects) ? createEmptyArray(keys.length) : {}; var childCbs = {}; var completed = false; keys.forEach(function (key) { var chCbAtKey = function chCbAtKey(res, isErr) { if (completed) { return; } if (isErr || shouldComplete(res)) { // Race Auto cancellation cb$$1.cancel(); cb$$1(res, isErr); } else { cb$$1.cancel(); completed = true; response[key] = res; cb$$1(response); } }; chCbAtKey.cancel = noop; childCbs[key] = chCbAtKey; }); cb$$1.cancel = function () { // prevents unnecessary cancellation if (!completed) { completed = true; keys.forEach(function (key) { return childCbs[key].cancel(); }); } }; keys.forEach(function (key) { if (completed) { return; } digestEffect(effects[key], effectId, childCbs[key], key); }); } function runSelectEffect(env, _ref13, cb$$1) { var selector = _ref13.selector, args = _ref13.args; try { var state = selector.apply(void 0, [env.getState()].concat(args)); cb$$1(state); } catch (error) { cb$$1(error, true); } } function runChannelEffect(env, _ref14, cb$$1) { var pattern$$1 = _ref14.pattern, buffer$$1 = _ref14.buffer; var chan = channel$1(buffer$$1); var match = matcher(pattern$$1); var taker = function taker(action) { if (!isEnd(action)) { env.channel.take(taker, match); } chan.put(action); }; var close = chan.close; chan.close = function () { taker.cancel(); close(); }; env.channel.take(taker, match); cb$$1(chan); } function runCancelledEffect(env, data, cb$$1, _ref15) { var task$$1 = _ref15.task; cb$$1(task$$1.isCancelled()); } function runFlushEffect(env, channel$$1, cb$$1) { channel$$1.flush(cb$$1); } function runGetContextEffect(env, prop, cb$$1, _ref16) { var task$$1 = _ref16.task; cb$$1(task$$1.context[prop]); } function runSetContextEffect(env, props, cb$$1, _ref17) { var task$$1 = _ref17.task; assignWithSymbols(task$$1.context, props); cb$$1(); } var effectRunnerMap = (_effectRunnerMap = {}, _effectRunnerMap[TAKE] = runTakeEffect, _effectRunnerMap[PUT] = runPutEffect, _effectRunnerMap[ALL] = runAllEffect, _effectRunnerMap[RACE] = runRaceEffect, _effectRunnerMap[CALL] = runCallEffect, _effectRunnerMap[CPS] = runCPSEffect, _effectRunnerMap[FORK] = runForkEffect, _effectRunnerMap[JOIN] = runJoinEffect, _effectRunnerMap[CANCEL$1] = runCancelEffect, _effectRunnerMap[SELECT] = runSelectEffect, _effectRunnerMap[ACTION_CHANNEL] = runChannelEffect, _effectRunnerMap[CANCELLED] = runCancelledEffect, _effectRunnerMap[FLUSH] = runFlushEffect, _effectRunnerMap[GET_CONTEXT] = runGetContextEffect, _effectRunnerMap[SET_CONTEXT] = runSetContextEffect, _effectRunnerMap); /** Used to track a parent task and its forks In the 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 if 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(mainTask, onAbort, cont) { var tasks = []; var result; var completed = false; addTask(mainTask); var getTasks = function getTasks() { return tasks; }; function abort(err) { onAbort(); cancelAll(); cont(err, true); } function addTask(task$$1) { tasks.push(task$$1); task$$1.cont = function (res, isErr) { if (completed) { return; } remove(tasks, task$$1); task$$1.cont = noop; if (isErr) { abort(res); } else { if (task$$1 === mainTask) { result = res; } if (!tasks.length) { completed = true; cont(result); } } }; } function cancelAll() { if (completed) { return; } completed = true; tasks.forEach(function (t$$1) { t$$1.cont = noop; t$$1.cancel(); }); tasks = []; } return { addTask: addTask, cancelAll: cancelAll, abort: abort, getTasks: getTasks }; } // there can be only a single saga error created at any given moment function formatLocation(fileName, lineNumber) { return fileName + "?" + lineNumber; } function effectLocationAsString(effect$$1) { var location = getLocation(effect$$1); if (location) { var code = location.code, fileName = location.fileName, lineNumber = location.lineNumber; var source = code + " " + formatLocation(fileName, lineNumber); return source; } return ''; } function sagaLocationAsString(sagaMeta) { var name = sagaMeta.name, location = sagaMeta.location; if (location) { return name + " " + formatLocation(location.fileName, location.lineNumber); } return name; } function cancelledTasksAsString(sagaStack) { var cancelledTasks = flatMap(function (i$$1) { return i$$1.cancelledTasks; }, sagaStack); if (!cancelledTasks.length) { return ''; } return ['Tasks cancelled due to error:'].concat(cancelledTasks).join('\n'); } var crashedEffect = null; var sagaStack = []; var addSagaFrame = function addSagaFrame(frame) { frame.crashedEffect = crashedEffect; sagaStack.push(frame); }; var clear = function clear() { crashedEffect = null; sagaStack.length = 0; }; // this sets crashed effect for the soon-to-be-reported saga frame // this slightly streatches the singleton nature of this module into wrong direction // as it's even less obvious what's the data flow here, but it is what it is for now var setCrashedEffect = function setCrashedEffect(effect$$1) { crashedEffect = effect$$1; }; /** @returns {string} @example The above error occurred in task errorInPutSaga {pathToFile} when executing effect put({type: 'REDUCER_ACTION_ERROR_IN_PUT'}) {pathToFile} created by fetchSaga {pathToFile} created by rootSaga {pathToFile} */ var toString = function toString() { var firstSaga = sagaStack[0], otherSagas = sagaStack.slice(1); var crashedEffectLocation = firstSaga.crashedEffect ? effectLocationAsString(firstSaga.crashedEffect) : null; var errorMessage = "The above error occurred in task " + sagaLocationAsString(firstSaga.meta) + (crashedEffectLocation ? " \n when executing effect " + crashedEffectLocation : ''); return [errorMessage].concat(otherSagas.map(function (s$$1) { return " created by " + sagaLocationAsString(s$$1.meta); }), [cancelledTasksAsString(sagaStack)]).join('\n'); }; function newTask(env, mainTask, parentContext, parentEffectId, meta, isRoot, cont) { var _task; var status = RUNNING; var taskResult; var taskError; var deferredEnd = null; var cancelledDueToErrorTasks = []; var context = Object.create(parentContext); var queue = forkQueue(mainTask, function onAbort() { cancelledDueToErrorTasks.push.apply(cancelledDueToErrorTasks, queue.getTasks().map(function (t$$1) { return t$$1.meta.name; })); }, end); /** 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 held 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$$1() { if (status === RUNNING) { // Setting status to CANCELLED does not necessarily mean that the task/iterators are stopped // effects in the iterator's finally block will still be executed status = CANCELLED$1; queue.cancelAll(); // Ending with a TASK_CANCEL will propagate the Cancellation to all joiners end(TASK_CANCEL, false); } } function end(result, isErr) { if (!isErr) { // The status here may be RUNNING or CANCELLED // If the status is CANCELLED, then we do not need to change it here if (result === TASK_CANCEL) { status = CANCELLED$1; } else if (status !== CANCELLED$1) { status = DONE; } taskResult = result; deferredEnd && deferredEnd.resolve(result); } else { status = ABORTED; addSagaFrame({ meta: meta, cancelledTasks: cancelledDueToErrorTasks }); if (task$$1.isRoot) { var sagaStack = toString(); // we've dumped the saga stack to string and are passing it to user's code // we know that it won't be needed anymore and we need to clear it clear(); env.onError(result, { sagaStack: sagaStack }); } taskError = result; deferredEnd && deferredEnd.reject(result); } task$$1.cont(result, isErr); task$$1.joiners.forEach(function (joiner) { joiner.cb(result, isErr); }); task$$1.joiners = null; } function setContext$$1(props) { assignWithSymbols(context, props); } function toPromise() { if (deferredEnd) { return deferredEnd.promise; } deferredEnd = deferred(); if (status === ABORTED) { deferredEnd.reject(taskError); } else if (status !== RUNNING) { deferredEnd.resolve(taskResult); } return deferredEnd.promise; } var task$$1 = (_task = {}, _task[TASK] = true, _task.id = parentEffectId, _task.meta = meta, _task.isRoot = isRoot, _task.context = context, _task.joiners = [], _task.queue = queue, _task.cancel = cancel$$1, _task.cont = cont, _task.end = end, _task.setContext = setContext$$1, _task.toPromise = toPromise, _task.isRunning = function isRunning() { return status === RUNNING; }, _task.isCancelled = function isCancelled() { return status === CANCELLED$1 || status === RUNNING && mainTask.status === CANCELLED$1; }, _task.isAborted = function isAborted() { return status === ABORTED; }, _task.result = function result() { return taskResult; }, _task.error = function error() { return taskError; }, _task); return task$$1; } function proc(env, iterator$1, parentContext, parentEffectId, meta, isRoot, cont) { var finalRunEffect = env.finalizeRunEffect(runEffect); /** 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 = noop; /** Creates a main task to track the main flow */ var mainTask = { meta: meta, cancel: cancelMain, status: RUNNING /** Creates a new task descriptor for this generator. A task is the aggregation of it's mainTask and all it's forked tasks. **/ }; var task$$1 = newTask(env, mainTask, parentContext, parentEffectId, meta, isRoot, cont); var executingContext = { task: task$$1, digestEffect: digestEffect /** cancellation of the main task. We'll simply resume the Generator with a TASK_CANCEL **/ }; function cancelMain() { if (mainTask.status === RUNNING) { mainTask.status = CANCELLED$1; next(TASK_CANCEL); } } /** attaches cancellation logic to this task's continuation this will permit cancellation to propagate down the call chain **/ cont.cancel = task$$1.cancel; // kicks up the generator next(); // then return the task descriptor to the caller return task$$1; /** * This is the generator driver * It's a recursive async/continuation function which calls itself * until the generator terminates or throws * @param {internal commands(TASK_CANCEL | TERMINATE) | any} arg - value, generator will be resumed with. * @param {boolean} isErr - the flag shows if effect finished with an error * * receives either (command | effect result, false) or (any thrown thing, true) */ function next(arg, isErr) { try { var result; if (isErr) { result = iterator$1.throw(arg); // user handled the error, we can clear bookkept values clear(); } else if (shouldCancel(arg)) { /** getting TASK_CANCEL automatically cancels the main task We can get this value here - By cancelling the parent task manually - By joining a Cancelled task **/ mainTask.status = CANCELLED$1; /** Cancels the current effect; this will propagate the cancellation down to any called tasks **/ next.cancel(); /** If this Generator has a `return` method then invokes it This will jump to the finally block **/ result = func(iterator$1.return) ? iterator$1.return(TASK_CANCEL) : { done: true, value: TASK_CANCEL }; } else if (shouldTerminate(arg)) { // We get TERMINATE flag, i.e. by taking from a channel that ended using `take` (and not `takem` used to trap End of channels) result = func(iterator$1.return) ? iterator$1.return() : { done: true }; } else { result = iterator$1.next(arg); } if (!result.done) { digestEffect(result.value, parentEffectId, next); } else { /** This Generator has ended, terminate the main task and notify the fork queue **/ if (mainTask.status !== CANCELLED$1) { mainTask.status = DONE; } mainTask.cont(result.value); } } catch (error) { if (mainTask.status === CANCELLED$1) { throw error; } mainTask.status = ABORTED; mainTask.cont(error, true); } } function runEffect(effect$$1, effectId, currCb) { /** each effect runner must attach its own logic of cancellation to the provided callback it allows this generator to propagate cancellation downward. ATTENTION! effect runners must setup the cancel logic by setting cb.cancel = [cancelMethod] And the setup must occur before calling the callback This is a sort of inversion of control: called async functions are responsible of completing the flow by calling the provided continuation; while caller functions are responsible for aborting the current flow by calling the attached cancel function Library users can attach their own cancellation logic to promises by defining a promise[CANCEL] method in their returned promises ATTENTION! calling cancel must have no effect on an already completed or cancelled effect **/ if (promise(effect$$1)) { resolvePromise(effect$$1, currCb); } else if (iterator(effect$$1)) { // resolve iterator proc(env, effect$$1, task$$1.context, effectId, meta, /* isRoot */ false, currCb); } else if (effect$$1 && effect$$1[IO]) { var effectRunner = effectRunnerMap[effect$$1.type]; effectRunner(env, effect$$1.payload, currCb, executingContext); } else { // anything else returned as is currCb(effect$$1); } } function digestEffect(effect$$1, parentEffectId, cb$$1, label) { if (label === void 0) { label = ''; } var effectId = nextEffectId(); env.sagaMonitor && env.sagaMonitor.effectTriggered({ effectId: effectId, parentEffectId: parentEffectId, label: label, effect: effect$$1 }); /** completion callback and cancel callback are mutually exclusive We can't cancel an already completed effect And We can't complete an already cancelled effectId **/ var effectSettled; // Completion callback passed to the appropriate effect runner function currCb(res, isErr) { if (effectSettled) { return; } effectSettled = true; cb$$1.cancel = noop; // defensive measure if (env.sagaMonitor) { if (isErr) { env.sagaMonitor.effectRejected(effectId, res); } else { env.sagaMonitor.effectResolved(effectId, res); } } if (isErr) { setCrashedEffect(effect$$1); } cb$$1(res, isErr); } // tracks down the current cancel currCb.cancel = noop; // setup cancellation logic on the parent cb cb$$1.cancel = function () { // prevents cancelling an already completed effect if (effectSettled) { return; } effectSettled = true; currCb.cancel(); // propagates cancel downward currCb.cancel = noop; // defensive measure env.sagaMonitor && env.sagaMonitor.effectCancelled(effectId); }; finalRunEffect(effect$$1, effectId, currCb); } } function runSaga(_ref, saga) { var _ref$channel = _ref.channel, channel$$1 = _ref$channel === void 0 ? stdChannel() : _ref$channel, dispatch = _ref.dispatch, getState = _ref.getState, _ref$context = _ref.context, context = _ref$context === void 0 ? {} : _ref$context, sagaMonitor = _ref.sagaMonitor, effectMiddlewares = _ref.effectMiddlewares, _ref$onError = _ref.onError, onError = _ref$onError === void 0 ? logError : _ref$onError; for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { args[_key - 2] = arguments[_key]; } var iterator$1 = saga.apply(void 0, args); var effectId = nextEffectId(); if (sagaMonitor) { // monitors are expected to have a certain interface, let's fill-in any missing ones sagaMonitor.rootSagaStarted = sagaMonitor.rootSagaStarted || noop; sagaMonitor.effectTriggered = sagaMonitor.effectTriggered || noop; sagaMonitor.effectResolved = sagaMonitor.effectResolved || noop; sagaMonitor.effectRejected = sagaMonitor.effectRejected || noop; sagaMonitor.effectCancelled = sagaMonitor.effectCancelled || noop; sagaMonitor.actionDispatched = sagaMonitor.actionDispatched || noop; sagaMonitor.rootSagaStarted({ effectId: effectId, saga: saga, args: args }); } var finalizeRunEffect; if (effectMiddlewares) { var middleware = compose.apply(void 0, effectMiddlewares); finalizeRunEffect = function finalizeRunEffect(runEffect) { return function (effect$$1, effectId, currCb) { var plainRunEffect = function plainRunEffect(eff) { return runEffect(eff, effectId, currCb); }; return middleware(plainRunEffect)(effect$$1); }; }; } else { finalizeRunEffect = identity; } var env = { channel: channel$$1, dispatch: wrapSagaDispatch(dispatch), getState: getState, sagaMonitor: sagaMonitor, onError: onError, finalizeRunEffect: finalizeRunEffect }; return immediately(function () { var task$$1 = proc(env, iterator$1, context, effectId, getMetaInfo(saga), /* isRoot */ true, noop); if (sagaMonitor) { sagaMonitor.effectResolved(effectId, task$$1); } return task$$1; }); } function sagaMiddlewareFactory(_ref) { if (_ref === void 0) { _ref = {}; } var _ref2 = _ref, _ref2$context = _ref2.context, context = _ref2$context === void 0 ? {} : _ref2$context, _ref2$channel = _ref2.channel, channel$$1 = _ref2$channel === void 0 ? stdChannel() : _ref2$channel, sagaMonitor = _ref2.sagaMonitor, options = _objectWithoutPropertiesLoose(_ref2, ["context", "channel", "sagaMonitor"]); var boundRunSaga; function sagaMiddleware(_ref3) { var getState = _ref3.getState, dispatch = _ref3.dispatch; boundRunSaga = runSaga.bind(null, _extends({}, options, { context: context, channel: channel$$1, dispatch: dispatch, getState: getState, sagaMonitor: sagaMonitor })); return function (next) { return function (action) { if (sagaMonitor && sagaMonitor.actionDispatched) { sagaMonitor.actionDispatched(action); } var result = next(action); // hit reducers channel$$1.put(action); return result; }; }; } sagaMiddleware.run = function () { return boundRunSaga.apply(void 0, arguments); }; sagaMiddleware.setContext = function (props) { assignWithSymbols(context, props); }; return sagaMiddleware; } var justOmit = omit; /* var obj = {a: 3, b: 5, c: 9}; omit(obj, ['a', 'c']); // {b: 5} omit(obj, a, c); // {b: 5} omit(obj, ['a', 'b', 'd']); // {c: 9} omit(obj, ['a', 'a']); // {b: 5, c: 9} */ function omit(obj, remove) { var result = {}; if (typeof remove === 'string') { remove = [].slice.call(arguments, 1); } for (var prop in obj) { if (!obj.hasOwnProperty || obj.hasOwnProperty(prop)) { if (remove.indexOf(prop) === -1) { result[prop] = obj[prop]; } } } return result; } const on = (state = true, action) => { switch (action.type) { case "ON": return true; case "OFF": return false; default: return state; } }; const promoInterval = (state = 120, action) => { switch (action.type) { case "PROMO_INTERVAL_SET": return action.promoInterval; default: return state; } }; const users = (state = { }, action) => { switch (action.type) { case "USER_ENTER": return Object.assign({ }, state, { [action.username]: action.timestamp, }); case "USER_LEAVE": return justOmit(state, action.username); default: return state; } }; const items = (state = { }, action) => { switch (action.type) { case "ITEM_SET": return Object.assign({ }, state, { [action.item]: { price: action.price, banners: action.banners, }, }); default: return state; } }; const performance = (state = null, action) => { switch (action.type) { case "PERFORMANCE_START": return action.item; case "PERFORMANCE_END": return null; default: return state; } }; const queue$1 = (state = [], action) => { switch (action.type) { case "SCHEDULE": return [...state, { item: action.item, username: action.username, note: action.note, }]; case "UNSCHEDULE": return state.filter(s => s.item !== action.item); default: return state; } }; var reducer = combineReducers({ on, promoInterval, users, items, queue: queue$1, performance, }); var done = function done(value) { return { done: true, value: value }; }; var qEnd = {}; function safeName(patternOrChannel) { if (channel(patternOrChannel)) { return 'channel'; } if (stringableFunc(patternOrChannel)) { return String(patternOrChannel); } if (func(patternOrChannel)) { return patternOrChannel.name; } return String(patternOrChannel); } function fsmIterator(fsm, startState, name) { var stateUpdater, errorState, effect$$1, nextState = startState; function next(arg, error) { if (nextState === qEnd) { return done(arg); } if (error && !errorState) { nextState = qEnd; throw error; } else { stateUpdater && stateUpdater(arg); var currentState = error ? fsm[errorState](error) : fsm[nextState](); nextState = currentState.nextState; effect$$1 = currentState.effect; stateUpdater = currentState.stateUpdater; errorState = currentState.errorState; return nextState === qEnd ? done(arg) : effect$$1; } } return makeIterator(next, function (error) { return next(null, error); }, name); } function takeEvery(patternOrChannel, worker) { for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { args[_key - 2] = arguments[_key]; } var yTake = { done: false, value: take(patternOrChannel) }; var yFork = function yFork(ac) { return { done: false, value: fork.apply(void 0, [worker].concat(args, [ac])) }; }; var action, setAction = function setAction(ac) { return action = ac; }; return fsmIterator({ q1: function q1() { return { nextState: 'q2', effect: yTake, stateUpdater: setAction }; }, q2: function q2() { return { nextState: 'q1', effect: yFork(action) }; } }, 'q1', "takeEvery(" + safeName(patternOrChannel) + ", " + worker.name + ")"); } function takeLatest(patternOrChannel, worker) { for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { args[_key - 2] = arguments[_key]; } var yTake = { done: false, value: take(patternOrChannel) }; var yFork = function yFork(ac) { return { done: false, value: fork.apply(void 0, [worker].concat(args, [ac])) }; }; var yCancel = function yCancel(task$$1) { return { done: false, value: cancel(task$$1) }; }; var task$$1, action; var setTask = function setTask(t) { return task$$1 = t; }; var setAction = function setAction(ac) { return action = ac; }; return fsmIterator({ q1: function q1() { return { nextState: 'q2', effect: yTake, stateUpdater: setAction }; }, q2: function q2() { return task$$1 ? { nextState: 'q3', effect: yCancel(task$$1) } : { nextState: 'q1', effect: yFork(action), stateUpdater: setTask }; }, q3: function q3() { return { nextState: 'q1', effect: yFork(action), stateUpdater: setTask }; } }, 'q1', "takeLatest(" + safeName(patternOrChannel) + ", " + worker.name + ")"); } function takeEvery$1(patternOrChannel, worker) { for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { args[_key - 2] = arguments[_key]; } return fork.apply(void 0, [takeEvery, patternOrChannel, worker].concat(args)); } function takeLatest$1(patternOrChannel, worker) { for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { args[_key2 - 2] = arguments[_key2]; } return fork.apply(void 0, [takeLatest, patternOrChannel, worker].concat(args)); } const nbsp = String.fromCharCode(0x00A0); const filterUnique = (value, index, array) => { return array.indexOf(value) === index; }; const reduceFlatten = (cum, arr) => { return [...cum, ...arr]; }; const isOn = (state) => { return state.on; }; const getPromoInterval = (state) => { return state.promoInterval; }; const getUsers = (state) => { return Object.keys(state.users); }; const getItems = (state) => { return Object.keys(state.items); }; const getPrice = (state, item) => { return state.items[item].price; }; const getBanners = (state, item) => { return state.items[item].banners; }; const getItemByPrice = (state, price) => { return getItems(state).find(item => getPrice(state, item) === price) || null; }; const getItemByBanner = (state, banner) => { return getItems(state).find(item => getBanners(state, item).includes(banner)) || null; }; const getAllBanners = (state) => { return getItems(state) .map((item) => getBanners(state, item)) .reduce(reduceFlatten, []); }; const getPerformance = (state) => { return state.performance; }; const getTipCount = (state, item) => { return state.queue.filter(s => s.item === item).length; }; const getTipUsernames = (state, item) => { return state.queue .filter(s => s.item === item && s.username !== null) .map(s => s.username) .filter(filterUnique); }; const getNotes = (state, item, username) => { return state.queue.filter((s) => { return ( s.item === item && s.username === username && s.note ); }).map(s => s.note); }; const getSchedule = (state) => { return state.queue.map(s => s.item).filter(filterUnique).sort((a, b) => { return getTipCount(state, b) - getTipCount(state, a); }); }; const getNext = (state) => { return getSchedule(state)[0] || null; }; const isNext = (state, item) => { return getNext(state) === item; }; const getRandomBanner = (state, rnd) => { const banners = getAllBanners(state); const index = Math.ceil(rnd * banners.length) - 1; return index === -1 ? null : banners[index]; }; // events sort-of const enterUser = (username, timestamp) => { return { type: "USER_ENTER", username, timestamp }; }; const leaveUser = (username, timestamp) => { return { type: "USER_LEAVE", username, timestamp }; }; const receiveTip = (username, amount, message) => { return { type: "TIP_RECEIVE", username, amount, message }; }; // reducer actions const turnOn = () => { return { type: "ON" }; }; const turnOff = () => { return { type: "OFF" }; }; const setPromoInterval = (promoInterval) => { return { type: "PROMO_INTERVAL_SET", promoInterval }; }; const setItem = (item, price, banners = []) => { return { type: "ITEM_SET", item, price, banners }; }; const schedule = (item, username = null, note = null) => { return { type: "SCHEDULE", item, username, note }; }; const unschedule = (item) => { return { type: "UNSCHEDULE", item }; }; const startPerformance = (item) => { return { type: "PERFORMANCE_START", item }; }; const endPerformance = () => { return { type: "PERFORMANCE_END" }; }; // saga actions const sendMenuNotice = (username = null) => { return { type: "MENU_NOTICE_SEND", username }; }; const sendScheduleNotice = (username = null) => { return { type: "SCHEDULE_NOTICE_SEND", username }; }; const sendWelcomeNotice = (username = null) => { return { type: "WELCOME_NOTICE_SEND", username }; }; const sendPromoNotice = (username, banner) => { return { type: "PROMO_NOTICE_SEND", username, banner }; }; // const note = "Type /menu or reload the page to see all available options"; const getMenuLine = (state, item) => { return `${item} (${getPrice(state, item)} tokens)`; }; const getMenuLines = (state) => { return getItems(state).map((item) => getMenuLine(state, item)); }; const getScheduleLine = (state, item) => { const then = isNext(state, item) ? "next" : "then"; const count = getTipCount(state, item); const usernames = getTipUsernames(state, item); if (usernames.length === 0) { return `${nbsp} ... ${then} ${item}`; } else if (count === 1) { return `${nbsp} ... ${then} ${item} (tip by ${usernames[0]})`; } else { return `${nbsp} ... ${then} ${item} (${count} tips by ${usernames.join(", ")})`; } }; const getScheduleLines = (state) => { return getSchedule(state).map((item) => getScheduleLine(state, item)); }; const getMenuNotice = (state) => { return getMenuLines(state).join("\n"); }; const getScheduleNotice = (state) => { const performance = getPerformance(state); if (!performance) { return ["Nothing scheduled"]; } return [performance, ...getScheduleLines(state)].join("\n"); }; const getWelcomeNotice = (state, rnd) => { const banner = getRandomBanner(state, rnd); const menu = getMenuLines(state); const schedule = getScheduleLines(state); const lines = []; if (banner) { lines.push(banner); } lines.push(...menu); if (schedule.length !== 0) { lines.push("-----"); lines.push(getPerformance(state)); lines.push(...schedule); } return lines.join("\n"); }; const getContinueNotice = (state, item, username) => { return `${username} tipped for ${item}`; }; const getNotesNotice = (state, item) => { const lines = []; const usernames = getTipUsernames(state, item); for (const username of usernames) { const notes = getNotes(state, item, username); lines.push(...notes.map(n => `${username}: ${n}`)); } return lines.join("\n"); }; const getPromoNotice = (state, banner) => { const item = getItemByBanner(state, banner); const line = getMenuLine(state, item); return [banner, `${nbsp} ... ${line}`].join("\n"); }; function * loadSettings() { if (cb.settings.advancedSettings) { for (const pair of cb.settings.advancedSettings.split(";")) { const [key, value] = pair.split("="); switch (key) { case "promoInterval": yield put(setPromoInterval(parseInt(value))); break; } } } for (const key of Object.keys(cb.settings)) { if (/^item(\d+)$/.test(key) && cb.settings[key]) { const configMatch = cb.settings[key].match(/^(\d+)--(.+)$/); if (configMatch) { const item = configMatch[2].replace(/:\w+/g, "").trim(); const price = parseInt(configMatch[1]); const banners = configMatch[2].match(/:\w+/g) || []; yield put(setItem(item, price, banners)); } } } } function * performanceSaga() { yield takeEvery$1("PERFORMANCE_START", function * ({ item }) { const notice = yield select(getNotesNotice, item); if (notice) { yield call(cb.sendNotice, notice, cb.room_slug); } yield put(unschedule(item)); }); yield takeLatest$1("PERFORMANCE_END", function * () { const next = yield select(getNext); if (next) { yield put(startPerformance(next)); } }); yield takeEvery$1("TIP_RECEIVE", function * ({ amount, username, message }) { const item = yield select(getItemByPrice, amount); if (item) { const performance = yield select(getPerformance); if (performance === null) { yield put(startPerformance(item)); } else if (performance === item) { const notice = yield select(getContinueNotice, item, username); yield call(cb.sendNotice, notice); } else { yield put(schedule(item, username, message)); } } }); } function * welcomeNoticeSaga() { yield takeEvery$1("WELCOME_NOTICE_SEND", function * ({ username }) { const on = yield select(isOn); if (on) { const rnd = Math.random(); const notice = yield select(getWelcomeNotice, rnd); yield call(cb.sendNotice, notice, username); } }); yield takeEvery$1("USER_ENTER", function * ({ username }) { yield put(sendWelcomeNotice(username)); }); yield put(sendWelcomeNotice()); } function * scheduleNoticeSaga() { yield takeEvery$1("SCHEDULE_NOTICE_SEND", function * ({ username }) { const notice = yield select(getScheduleNotice); yield call(cb.sendNotice, notice, username); }); yield takeEvery$1("UNSCHEDULE", function * () { yield put(sendScheduleNotice()); }); yield takeEvery$1("SCHEDULE", function * () { yield put(sendScheduleNotice()); }); } function * menuNoticeSaga() { yield takeEvery$1("MENU_NOTICE_SEND", function * ({ username }) { const on = yield select(isOn); if (on) { const notice = yield select(getMenuNotice); yield call(cb.sendNotice, notice, username); } }); } function * promoNoticeSaga() { yield takeEvery$1("PROMO_NOTICE_SEND", function * ({ username, banner }) { const notice = yield select(getPromoNotice, banner); yield call(cb.sendNotice, notice, username); }); while (true) { const on = yield select(isOn); if (on) { const users = yield select(getUsers); for (const username of users) { const rnd = Math.random(); const banner = yield select(getRandomBanner, rnd); if (banner) { yield put(sendPromoNotice(username, banner)); } } } const promoInterval = yield select(getPromoInterval); yield delay(promoInterval * 1000); } } function * saga() { yield call(loadSettings); yield fork(performanceSaga); yield fork(welcomeNoticeSaga); yield fork(menuNoticeSaga); yield fork(scheduleNoticeSaga); yield fork(promoNoticeSaga); } const onError = (error, { sagaStack }) => { cb.sendNotice([error.message, error.stack, sagaStack].join("\n\n"), cb.room_slug); }; const sagaMiddleware = sagaMiddlewareFactory({ onError }); const store = createStore(reducer, applyMiddleware(sagaMiddleware)); sagaMiddleware.run(saga); const getState = () => { return store.getState(); }; const dispatch = (action) => { store.dispatch(action); }; (function () { cb["settings_choices"] = []; for (let i = 1; i <= 20; i++) { const id = ("00" + String(i)).slice(-2); cb["settings_choices"].push({ label: `${i}`, name: `item${id}`, type: "str", required: false, }); } cb["settings_choices"].push({ label: "Advanced settings", name: "advancedSettings", type: "str", required: false, }); })(); cb.onMessage((evt) => { const username = evt["user"]; const message = evt["m"]; const mod = evt["is_mod"] || username === cb.room_slug; const cmd = (regexp, fn) => { const m = message.match(regexp); if (m) { fn(...m.slice(1)); evt["X-Spam"] = true; } }; if (mod) { cmd(/^\/schedule (.+)$/, (item) => { dispatch(schedule(item)); }); cmd(/^\/unschedule (.+)$/, (item) => { dispatch(unschedule(item)); }); cmd(/^\/start (.+)$/, (item) => { dispatch(startPerformance(item)); }); cmd(/^\/next$/, () => { dispatch(endPerformance()); }); cmd(/^\/$/, () => { dispatch(endPerformance()); }); cmd(/^\/menu all$/, () => { dispatch(sendMenuNotice()); }); cmd(/^\/on$/, () => { dispatch(turnOn()); }); cmd(/^\/off$/, () => { dispatch(turnOff()); }); cmd(/^\/state$/, () => { cb.sendNotice(JSON.stringify(getState()), username); }); } cmd(/^\/menu$/, () => { dispatch(sendMenuNotice(username)); }); cmd(/^\/tipmenu$/, () => { dispatch(sendMenuNotice(username)); }); cmd(/^\/schedule$/, () => { dispatch(sendScheduleNotice(username)); }); }); cb.onEnter((evt) => { const username = evt["user"]; const timestamp = Date.now(); dispatch(enterUser(username, timestamp)); }); cb.onLeave((evt) => { const username = evt["user"]; const timestamp = Date.now(); dispatch(leaveUser(username, timestamp)); }); cb.onTip((evt) => { const username = evt["from_user"]; const amount = parseInt(evt["amount"]); const message = evt["message"]; dispatch(receiveTip(username, amount, message)); }); }(cb)); }(cb.setTimeout, cb.cancelTimeout));
© Copyright Chaturbate 2011- 2025. All Rights Reserved.