UNPKG

redux-fluorine

Version:

A Redux enhancer to manage groups of actions as observables (agendas)

54 lines (40 loc) 1.24 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = executeAgenda; var _filterActions = require('../actions/filterActions'); var _filterActions2 = _interopRequireDefault(_filterActions); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _ref2() { // NOTE: We don't need to do anything here } function executeAgenda(agenda, store) { var dispatch = store.dispatch; var getState = store.getState; var anchor = getState(); var actions = []; // Subscribe to the agenda and return the subscription function _ref() { dispatch((0, _filterActions2.default)(anchor, actions)); } var sub = agenda.subscribe({ next: function next(action) { // Dispatch action normally and push it to our bucket dispatch(action); actions.push(action); }, error: function error(err) { console.error && console.error(err); // Instruct the reducer wrapper to recompute the state // without any actions inside the `actions` array if (actions.length) { setTimeout(_ref); } }, complete: _ref2 }); return { unsubscribe: sub.unsubscribe.bind(sub) }; }