* Usage: * registerAction('someAction', 'someEvent', function () { ... }); * registerAction('someAction', function () { ... }); * registerAction( * {type: 'someAction', event: 'someEvent', update: 'updateView'}, * function () { ... } * ); * * @param {(string|Object)} actionInfo * @p
(actionInfo, eventName, action)
| 29332 | * @param {Function} action |
| 29333 | */ |
| 29334 | function registerAction(actionInfo, eventName, action) { |
| 29335 | if (typeof eventName === 'function') { |
| 29336 | action = eventName; |
| 29337 | eventName = ''; |
| 29338 | } |
| 29339 | var actionType = isObject(actionInfo) |
| 29340 | ? actionInfo.type |
| 29341 | : ([actionInfo, actionInfo = { |
| 29342 | event: eventName |
| 29343 | }][0]); |
| 29344 | |
| 29345 | // Event name is all lowercase |
| 29346 | actionInfo.event = (actionInfo.event || actionType).toLowerCase(); |
| 29347 | eventName = actionInfo.event; |
| 29348 | |
| 29349 | // Validate action type and event name. |
| 29350 | assert(ACTION_REG.test(actionType) && ACTION_REG.test(eventName)); |
| 29351 | |
| 29352 | if (!actions[actionType]) { |
| 29353 | actions[actionType] = {action: action, actionInfo: actionInfo}; |
| 29354 | } |
| 29355 | eventActionMap[eventName] = actionType; |
| 29356 | } |
| 29357 | |
| 29358 | /** |
| 29359 | * @param {string} type |
no test coverage detected