Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #58 from szimek/throw-error-on-undefined-action-name
Browse files Browse the repository at this point in the history
Throw an error when actionName param in Dispatcher#dispatch is falsy
  • Loading branch information
mridgway committed Mar 9, 2015
2 parents 669a372 + 488138c commit 72b85a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ module.exports = function () {
* @throws {Error} if store has handler registered that does not exist
*/
Dispatcher.prototype.dispatch = function dispatch(actionName, payload) {
if (!actionName) {
throw new Error('actionName parameter `' + actionName + '` is invalid.');
}

if (this.currentAction) {
throw new Error('Cannot call dispatch while another dispatch is executing. Attempted to execute \'' + actionName + '\' but \'' + this.currentAction.name + '\' is already executing.');
}
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/lib/Dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ describe('Dispatchr', function () {
dispatcher.dispatch('DELAY', {});
});

it('should throw if a dispatch called with falsy actionName parameter', function () {
var context = {test: 'test'},
dispatcher = new Dispatcher(context);

expect(function () {
dispatcher.dispatch(undefined, {
dispatcher: dispatcher
});
}).to.throw();
});

it('should throw if a dispatch called within dispatch', function () {
var context = {test: 'test'},
dispatcher = new Dispatcher(context);
Expand Down

0 comments on commit 72b85a8

Please sign in to comment.