-
-
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 feature effects action on init (#1305)
Closes #683
- Loading branch information
1 parent
fa21f29
commit 15a4b58
Showing
4 changed files
with
117 additions
and
20 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
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,38 @@ | ||
import { NgModule, Inject, Optional } from '@angular/core'; | ||
import { StoreRootModule, StoreFeatureModule } from '@ngrx/store'; | ||
import { StoreRootModule, StoreFeatureModule, Store } from '@ngrx/store'; | ||
import { EffectsRootModule } from './effects_root_module'; | ||
import { FEATURE_EFFECTS } from './tokens'; | ||
import { getSourceForInstance } from './effects_metadata'; | ||
|
||
export const UPDATE_EFFECTS = '@ngrx/effects/update-effects'; | ||
export type UpdateEffects = { | ||
type: typeof UPDATE_EFFECTS; | ||
effects: string[]; | ||
}; | ||
|
||
@NgModule({}) | ||
export class EffectsFeatureModule { | ||
constructor( | ||
private root: EffectsRootModule, | ||
root: EffectsRootModule, | ||
store: Store<any>, | ||
@Inject(FEATURE_EFFECTS) effectSourceGroups: any[][], | ||
@Optional() storeRootModule: StoreRootModule, | ||
@Optional() storeFeatureModule: StoreFeatureModule | ||
) { | ||
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(<UpdateEffects>{ | ||
type: UPDATE_EFFECTS, | ||
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