Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update upstream #33

Merged
merged 1 commit into from
Oct 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions modules/effects/spec/effects_root_module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { TestBed } from '@angular/core/testing';
import {
Store,
StoreModule,
ActionReducer,
MetaReducer,
Action,
INIT,
} from '@ngrx/store';
import { ROOT_EFFECTS_INIT } from '../src/effects_root_module';
import { EffectsModule } from '../src/effects_module';

describe('Effects Root Module', () => {
const foo = 'foo';
const reducer = jasmine.createSpy('reducer').and.returnValue(foo);

beforeEach(() => {
reducer.calls.reset();
});

it('dispatches the root effects init action', () => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ reducer }, { initialState: { reducer: foo } }),
EffectsModule.forRoot([]),
],
});

const store = TestBed.get(Store);

expect(reducer).toHaveBeenCalledWith(foo, {
type: INIT,
});
expect(reducer).toHaveBeenCalledWith(foo, {
type: ROOT_EFFECTS_INIT,
});
});

it("doesn't dispatch the root effects init action when EffectsModule isn't used", () => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({ reducer }, { initialState: { reducer: foo } }),
],
});

const store = TestBed.get(Store);

expect(reducer).toHaveBeenCalledWith(foo, {
type: INIT,
});
expect(reducer).not.toHaveBeenCalledWith(foo, {
type: ROOT_EFFECTS_INIT,
});
});
});
7 changes: 6 additions & 1 deletion modules/effects/src/effects_root_module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { NgModule, Inject, Optional } from '@angular/core';
import { StoreModule } from '@ngrx/store';
import { StoreModule, Store } from '@ngrx/store';
import { EffectsRunner } from './effects_runner';
import { EffectSources } from './effect_sources';
import { ROOT_EFFECTS } from './tokens';

export const ROOT_EFFECTS_INIT = '@ngrx/effects/init';

@NgModule({})
export class EffectsRootModule {
constructor(
private sources: EffectSources,
runner: EffectsRunner,
store: Store<any>,
@Inject(ROOT_EFFECTS) rootEffects: any[],
@Optional() storeModule: StoreModule
) {
Expand All @@ -17,6 +20,8 @@ export class EffectsRootModule {
rootEffects.forEach(effectSourceInstance =>
sources.addEffects(effectSourceInstance)
);

store.dispatch({ type: ROOT_EFFECTS_INIT });
}

addEffects(effectSourceInstance: any) {
Expand Down
1 change: 1 addition & 0 deletions modules/effects/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export { EffectSources } from './effect_sources';
export { OnRunEffects } from './on_run_effects';
export { toPayload } from './util';
export { EffectNotification } from './effect_notification';
export { ROOT_EFFECTS_INIT } from './effects_root_module';