UNPKG

sententiaregum-flux-container

Version:

The flux implementation of the sententiaregum project based on facebook/flux

58 lines (44 loc) 2.18 kB
/* * This file is part of the Sententiaregum project. * * (c) Maximilian Bosch <maximilian.bosch.27@gmail.com> * (c) Ben Bieler <benjaminbieler2014@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _Dispatcher = require('./dispatcher/Dispatcher'); var _Dispatcher2 = _interopRequireDefault(_Dispatcher); var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant); var _resolveCreator2 = require('./util/resolveCreator'); var _resolveCreator3 = _interopRequireDefault(_resolveCreator2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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 Array.from(arr); } } /** * Executes the action of an action creator to abstract the dispatcher from the public API. * * It takes one action creator and connects it with the dispatcher, so it can do sync or async actions * and publish the payload after that. * * @param {String} eventName The event to execute. * @param {Function} actionCreator The action. * @param {Array} args Argument list. * * @returns {void} */ exports.default = function (eventName, actionCreator) { var _resolveCreator; var args = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2]; (0, _invariant2.default)(typeof actionCreator === 'function', 'The `actionCreator` must be a function that builds the actions.'); // To create the action creator a dispatcher callback is needed. // This callback simply takes the event name and the given payload that is injected into the callback // as argument and delegates it to the `Dispatcher`. (_resolveCreator = (0, _resolveCreator3.default)(actionCreator))[eventName].apply(_resolveCreator, [function (payload) { return _Dispatcher2.default.dispatch(eventName, payload); }].concat(_toConsumableArray(args))); };