Skip to content

Commit ecf1ebf

Browse files
brandonrobertsMikeRyanDev
authored andcommitted
fix(Devtools): Ensure Store is loaded eagerly (#801)
Closes #624,#741
1 parent 0e5d209 commit ecf1ebf

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { NgModule } from '@angular/core';
2+
import { TestBed } from '@angular/core/testing';
3+
import { StoreModule, Store, ActionsSubject } from '@ngrx/store';
4+
import { StoreDevtoolsModule, StoreDevtools } from '@ngrx/store-devtools';
5+
6+
describe('Devtools Integration', () => {
7+
let store: Store<any>;
8+
9+
@NgModule({
10+
imports: [StoreModule.forFeature('a', (state: any, action: any) => state)],
11+
})
12+
class EagerFeatureModule {}
13+
14+
@NgModule({
15+
imports: [
16+
StoreModule.forRoot({}),
17+
EagerFeatureModule,
18+
StoreDevtoolsModule.instrument(),
19+
],
20+
})
21+
class RootModule {}
22+
23+
beforeEach(() => {
24+
TestBed.configureTestingModule({
25+
imports: [RootModule],
26+
});
27+
});
28+
29+
it('should load the store eagerly', () => {
30+
let error = false;
31+
32+
try {
33+
let store = TestBed.get(Store);
34+
store.subscribe();
35+
} catch (e) {
36+
error = true;
37+
}
38+
39+
expect(error).toBeFalsy();
40+
});
41+
});

modules/store/src/store_module.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ import {
4141
ScannedActionsSubject,
4242
} from './scanned_actions_subject';
4343
import { STATE_PROVIDERS } from './state';
44-
import { STORE_PROVIDERS } from './store';
44+
import { STORE_PROVIDERS, Store } from './store';
4545

4646
@NgModule({})
4747
export class StoreRootModule {
4848
constructor(
4949
actions$: ActionsSubject,
5050
reducer$: ReducerObservable,
51-
scannedActions$: ScannedActionsSubject
51+
scannedActions$: ScannedActionsSubject,
52+
store: Store<any>
5253
) {}
5354
}
5455

@@ -57,7 +58,8 @@ export class StoreFeatureModule implements OnDestroy {
5758
constructor(
5859
@Inject(STORE_FEATURES) private features: StoreFeature<any, any>[],
5960
@Inject(FEATURE_REDUCERS) private featureReducers: ActionReducerMap<any>[],
60-
private reducerManager: ReducerManager
61+
private reducerManager: ReducerManager,
62+
root: StoreRootModule
6163
) {
6264
features
6365
.map((feature, index) => {

0 commit comments

Comments
 (0)