In my project, I encounter a scenario where I have multiple effect classes that extend a generic class. However, effects inherited from the generic class are not automatically subscribed to. Instead, manual subscription is required in the constructor of the generic class:
@Injectable()
export class GenericEffects<T extends Action, K> {
action: T;
constructor(
TCreator: { new (): T },
protected actions: Actions,
protected store: Store<K>,
protected route: string
) {
this.action = new TCreator();
--> this.effect1.subscribe(); <---
}
@Effect({ dispatch: false })
effect1 = this.actions.ofType(genericActions.EFFECT_1).pipe(
withLatestFrom(this.store.select<RouterReducerState>('route')),
map(([action, routerState]) => routerState.state.url),
map(url => {
if (url.indexOf(this.route) !== -1 && url.length ===
this.route.length + 1) {
this.store.dispatch(this.action);
}
})
);
}
FeatureEffectsModule:
@Injectable()
export class FeatureEffects extends GenericEffects<
featureActions.WhatEverAction,
fromFeature.State
> {
constructor(
actions: Actions,
store: Store<fromFeature.State>,
private service: FeatureService
) {
super(
featureActions.WhatEverAction,
actions,
store,
'foo'
);
}
}
What could be the reason behind this manual process or what am I missing?