UNPKG

kilto

Version:

A state management system with easy async and low boilerplate.

37 lines (27 loc) 1.63 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; exports.default = bindActions; var _mapObjectToObject = require('./util/mapObjectToObject'); var _mapObjectToObject2 = _interopRequireDefault(_mapObjectToObject); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // This function automatically binds the actions of the second argument to dispatch. // This function does not bind the third argument, those are expected to call dispatch themselves, // allowing you to use this function even if not every single action can be auto-bound. function bindActions(dispatch, actions) { var preBoundActions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; if (typeof dispatch !== 'function' || (typeof actions === 'undefined' ? 'undefined' : _typeof(actions)) !== 'object' || actions === null) { throw new Error('Make sure you pass dispatch FIRST To bindActions.'); } var result = (0, _mapObjectToObject2.default)(actions, function (name, fn) { return [name, function () { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return dispatch.apply(undefined, [fn].concat(args)); }]; }); return Object.assign({}, result, preBoundActions); }