为什么 Ngrx-Effects 不在继承的泛型中自动订阅 class

Why aren't Ngrx-Effects subscribed automatically in a inherited generic class

我的项目中有几个效果 classes,它们由通用 class 扩展。从通用 class 继承的所有效果都不会自动订阅。相反,我必须在通用 class 的构造函数中手动订阅 effect/observable:

    @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'
        );
      }
    }

我错过了什么或者我必须手动执行此操作的原因是什么?

由于效果在非通用版本中触发,我不会考虑订阅通用版本的基础 class 构造函数。我发现在派生的 class 中重新声明效果是有效的,所以我接受这种代码重复。在您自己的示例中,我添加了 1 行:

@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'
    );
  }

  @Effect()  effect1;      //   <---   like this

}