Skip to content

Commit

Permalink
fix(Store): Set initial value for state action pair to object (#480)
Browse files Browse the repository at this point in the history
Closes #477
  • Loading branch information
brandonroberts authored and MikeRyanDev committed Oct 14, 2017
1 parent 838ba17 commit 100a8ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
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

0 comments on commit 100a8ef

Please sign in to comment.