sententiaregum-flux-container
Version:
The flux implementation of the sententiaregum project based on facebook/flux
56 lines (43 loc) • 1.71 kB
JavaScript
/*
* 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.
*/
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _invariant = require('invariant');
var _invariant2 = _interopRequireDefault(_invariant);
var _Dispatcher = require('../dispatcher/Dispatcher');
var _Dispatcher2 = _interopRequireDefault(_Dispatcher);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Util which connects the event hub to the dispatcher.
*
* @param {Object.<Object>} eventData The event configuration.
* @param {Array.<String>} oldTokens The old event tokens.
*
* @returns {Object.<String>} Key-value list from event to dispatch token.
* @private This is part of the internal API and should not be used directly!
*/
exports.default = function (eventData) {
var oldTokens = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var tokens = {};
oldTokens.forEach(function (token) {
return _Dispatcher2.default.removeListener(token);
});
// handle event data and build tokens
Object.keys(eventData).forEach(function (name) {
var config = eventData[name];
(0, _invariant2.default)(typeof config['function'] !== 'undefined', 'Required property "function" missing in event config!');
tokens[name] = _Dispatcher2.default.addListener(name, function (payload) {
return config.function(payload);
}, config.dependencies);
});
return tokens;
};