Skip to content

Commit

Permalink
Stop passing a function to store.dipatch and stop effect e.g. pipe(ma…
Browse files Browse the repository at this point in the history
…p(...)) that is returns a function ngrx#1906
  • Loading branch information
SerkanSipahi committed Jun 4, 2019
1 parent 81eca76 commit 0ee7e1f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions modules/effects/src/effects_runner.ts
Expand Up @@ -3,6 +3,8 @@ import { Store } from '@ngrx/store';
import { Subscription } from 'rxjs';

import { EffectSources } from './effect_sources';
import { tap } from 'rxjs/operators';
import { throwErrorOnInvalidAction } from '../../../modules/store/src/actions_subject';

@Injectable()
export class EffectsRunner implements OnDestroy {
Expand All @@ -17,6 +19,7 @@ export class EffectsRunner implements OnDestroy {
if (!this.effectsSubscription) {
this.effectsSubscription = this.effectSources
.toActions()
.pipe(tap(action => throwErrorOnInvalidAction(action)))
.subscribe(this.store);
}
}
Expand Down
19 changes: 13 additions & 6 deletions modules/store/src/actions_subject.ts
Expand Up @@ -5,6 +5,18 @@ import { Action } from './models';

export const INIT = '@ngrx/store/init' as '@ngrx/store/init';

export const throwErrorOnInvalidAction = (action: Action) => {
if (typeof action === 'undefined') {
throw new TypeError(`Actions must be objects`);
} else if (typeof action === 'function') {
throw new TypeError(`
Actions as function are not now allowed.
Make sure your action is called e.g someAction()`);
} else if (typeof action.type === 'undefined') {
throw new TypeError(`Actions must have a type property`);
}
};

@Injectable()
export class ActionsSubject extends BehaviorSubject<Action>
implements OnDestroy {
Expand All @@ -13,12 +25,7 @@ export class ActionsSubject extends BehaviorSubject<Action>
}

next(action: Action): void {
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`);
}

throwErrorOnInvalidAction(action);
super.next(action);
}

Expand Down

0 comments on commit 0ee7e1f

Please sign in to comment.