Skip to content

Commit 100a8ef

Browse files
brandonrobertsMikeRyanDev
authored andcommitted
fix(Store): Set initial value for state action pair to object (#480)
Closes #477
1 parent 838ba17 commit 100a8ef

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

modules/store/spec/modules.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,42 @@ describe(`Store Modules`, () => {
119119
});
120120
});
121121

122+
describe(`: With initial state`, () => {
123+
const initialState: RootState = { fruit: 'banana' };
124+
const reducerMap: ActionReducerMap<RootState> = { fruit: rootFruitReducer };
125+
const noopMetaReducer = (r: Function) => (state: any, action: any) => {
126+
return r(state, action);
127+
};
128+
129+
const testWithMetaReducers = (metaReducers: any[]) => () => {
130+
beforeEach(() => {
131+
TestBed.configureTestingModule({
132+
imports: [
133+
StoreModule.forRoot(reducerMap, { initialState, metaReducers }),
134+
],
135+
});
136+
137+
store = TestBed.get(Store);
138+
});
139+
140+
it('should have initial state', () => {
141+
store.take(1).subscribe((s: any) => {
142+
expect(s).toEqual(initialState);
143+
});
144+
});
145+
};
146+
147+
describe(
148+
'should add initial state with no meta-reducers',
149+
testWithMetaReducers([])
150+
);
151+
152+
describe(
153+
'should add initial state with registered meta-reducers',
154+
testWithMetaReducers([noopMetaReducer])
155+
);
156+
});
157+
122158
describe(`: Nested`, () => {
123159
@NgModule({
124160
imports: [StoreModule.forFeature('a', featureAReducer)],

modules/store/src/state.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class State<T> extends BehaviorSubject<any> implements OnDestroy {
3535
const stateAndAction$: Observable<{
3636
state: any;
3737
action: Action;
38-
}> = scan.call(withLatestReducer$, reduceState, initialState);
38+
}> = scan.call(withLatestReducer$, reduceState, { state: initialState });
3939

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

0 commit comments

Comments
 (0)