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

fix(Store): Set initial value for state action pair to object #480

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
36 changes: 36 additions & 0 deletions modules/store/spec/modules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,42 @@ describe(`Store Modules`, () => {
});
});

describe(`: With initial state`, () => {
const initialState: RootState = { fruit: 'banana' };
const reducerMap: ActionReducerMap<RootState> = { fruit: rootFruitReducer };
const noopMetaReducer = (r: Function) => (state: any, action: any) => {
return r(state, action);
};

const testWithMetaReducers = (metaReducers: any[]) => () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot(reducerMap, { initialState, metaReducers }),
],
});

store = TestBed.get(Store);
});

it('should have initial state', () => {
store.take(1).subscribe((s: any) => {
expect(s).toEqual(initialState);
});
});
};

describe(
'should add initial state with no meta-reducers',
testWithMetaReducers([])
);

describe(
'should add initial state with registered meta-reducers',
testWithMetaReducers([noopMetaReducer])
);
});

describe(`: Nested`, () => {
@NgModule({
imports: [StoreModule.forFeature('a', featureAReducer)],
Expand Down
2 changes: 1 addition & 1 deletion modules/store/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class State<T> extends BehaviorSubject<any> implements OnDestroy {
const stateAndAction$: Observable<{
state: any;
action: Action;
}> = scan.call(withLatestReducer$, reduceState, initialState);
}> = scan.call(withLatestReducer$, reduceState, { state: initialState });

this.stateSubscription = stateAndAction$.subscribe({
next: ({ state, action }) => {
Expand Down