Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
201 views
in Technique[技术] by (71.8m points)

Import proper NGRX Effects based on config in angular application

I am trying to create one library for three similar but still different applications. I managed to push config with APP name and API endpoint through forRoot and it looks like this:

import { ModuleWithProviders, NgModule } from '@angular/core';

export interface appConfig {
  apiUrl: string;
  appName: string;
}

@NgModule({
  declarations: [],
  exports: []
})
export class TestModule{
  static forRoot(config: appConfig): ModuleWithProviders<TestModule> {
    console.log(config);
    return {
      ngModule: TestModule
    };
  }
}

But now I have three different files with NGRX effects for each application. I am doing something like this and it works but...:

const effects = [TestEffects, TestEffects1, TestEffects2];
EffectsModule.forFeature(effects)

I wonder if there is a way to use/import only effects that are needed - based on appName for example. So if we are in appA then use only TestEffects, if we are using appB then use TestEffects1 etc...

I can do conditions inside the effects file itself but maybe there is a better way? Or maybe my idea is stupid so please let me know.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...