-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Effects): dispatch init feature effects action on init
- Loading branch information
1 parent
ba8d300
commit 0e4cdd2
Showing
3 changed files
with
94 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
import { NgModule, Inject, Optional } from '@angular/core'; | ||
import { StoreRootModule, StoreFeatureModule } from '@ngrx/store'; | ||
import { NgModule, Inject } from '@angular/core'; | ||
import { Store } from '@ngrx/store'; | ||
import { EffectsRootModule } from './effects_root_module'; | ||
import { FEATURE_EFFECTS } from './tokens'; | ||
import { getSourceForInstance } from './effects_metadata'; | ||
|
||
export const FEATURE_EFFECTS_INIT = '@ngrx/feature-effects/init'; | ||
export type FeatureEffectsInit = { | ||
type: typeof FEATURE_EFFECTS_INIT; | ||
effects: string[]; | ||
}; | ||
|
||
@NgModule({}) | ||
export class EffectsFeatureModule { | ||
constructor( | ||
private root: EffectsRootModule, | ||
@Inject(FEATURE_EFFECTS) effectSourceGroups: any[][], | ||
@Optional() storeRootModule: StoreRootModule, | ||
@Optional() storeFeatureModule: StoreFeatureModule | ||
root: EffectsRootModule, | ||
store: Store<any>, | ||
@Inject(FEATURE_EFFECTS) effectSourceGroups: any[][] | ||
) { | ||
effectSourceGroups.forEach(group => | ||
group.forEach(effectSourceInstance => | ||
root.addEffects(effectSourceInstance) | ||
) | ||
); | ||
effectSourceGroups.forEach(group => { | ||
let effectSourceNames: string[] = []; | ||
|
||
group.forEach(effectSourceInstance => { | ||
root.addEffects(effectSourceInstance); | ||
|
||
const { constructor } = getSourceForInstance(effectSourceInstance); | ||
effectSourceNames.push(constructor.name); | ||
}); | ||
|
||
store.dispatch(<FeatureEffectsInit>{ | ||
type: FEATURE_EFFECTS_INIT, | ||
effects: effectSourceNames, | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters