Skip to content

Commit

Permalink
fix(store): prevent passing of action creator function to store dispa…
Browse files Browse the repository at this point in the history
…tch and effects (#1914)

Closes #1906
  • Loading branch information
SerkanSipahi authored and brandonroberts committed Jun 10, 2019
1 parent 878d31c commit 78153cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion modules/effects/src/effect_notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export function reportInvalidActions(
}

function isAction(action: any): action is Action {
return action && action.type && typeof action.type === 'string';
return (
typeof action !== 'function' &&
action &&
action.type &&
typeof action.type === 'string'
);
}

function getEffectName({
Expand Down
8 changes: 6 additions & 2 deletions modules/store/src/actions_subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ export class ActionsSubject extends BehaviorSubject<Action>
}

next(action: Action): void {
if (typeof action === 'undefined') {
if (typeof action === 'function') {
throw new TypeError(`
Dispatch expected an object, instead it received a function.
If you're using the createAction function, make sure to invoke the function
before dispatching the action. For example, someAction should be someAction().`);
} else if (typeof action === 'undefined') {
throw new TypeError(`Actions must be objects`);
} else if (typeof action.type === 'undefined') {
throw new TypeError(`Actions must have a type property`);
}

super.next(action);
}

Expand Down

0 comments on commit 78153cb

Please sign in to comment.