Skip to content

Commit 78153cb

Browse files
SerkanSipahibrandonroberts
authored andcommitted
fix(store): prevent passing of action creator function to store dispatch and effects (#1914)
Closes #1906
1 parent 878d31c commit 78153cb

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

modules/effects/src/effect_notification.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ export function reportInvalidActions(
3131
}
3232

3333
function isAction(action: any): action is Action {
34-
return action && action.type && typeof action.type === 'string';
34+
return (
35+
typeof action !== 'function' &&
36+
action &&
37+
action.type &&
38+
typeof action.type === 'string'
39+
);
3540
}
3641

3742
function getEffectName({

modules/store/src/actions_subject.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ export class ActionsSubject extends BehaviorSubject<Action>
1313
}
1414

1515
next(action: Action): void {
16-
if (typeof action === 'undefined') {
16+
if (typeof action === 'function') {
17+
throw new TypeError(`
18+
Dispatch expected an object, instead it received a function.
19+
If you're using the createAction function, make sure to invoke the function
20+
before dispatching the action. For example, someAction should be someAction().`);
21+
} else if (typeof action === 'undefined') {
1722
throw new TypeError(`Actions must be objects`);
1823
} else if (typeof action.type === 'undefined') {
1924
throw new TypeError(`Actions must have a type property`);
2025
}
21-
2226
super.next(action);
2327
}
2428

0 commit comments

Comments
 (0)