我正在尝试实现授权功能,但无法发挥作用。操作被调度,但效果永远不会触发,经过大量调试后,我发现状态实际上没有被添加到存储中。
我基本上创建了一个身份验证模块,并在其中将功能注册到商店:
export const AUTHENTICATION_PROVIDED_CONFIG = new InjectionToken('providedConfig');
@NgModule()
export class AuthenticationModule {
constructor(private store: Store) {
this.store.pipe(select(state => state))
.subscribe(state => {
console.log('Current store state - AUTHENTICATION MODULE:', state);
});
}
static forRoot(config: AuthenticationConfig) {
return {
ngModule: AuthenticationModule,
imports:[
EffectsModule.forFeature(authenticationEffects),
// I also tried doing forFeature(featurekey, reducer).
StoreModule.forFeature(fromAuthentication.authenticationFeature),
],
providers: [
AuthenticationFacadeService,
{
provide: AUTHENTICATION_PROVIDED_CONFIG,
useValue: config,
},
{
provide: HTTP_INTERCEPTORS,
useClass: AuthenticationInterceptor,
multi: true,
},
]
}
}
}
这个authenticationModule然后被导入到我的AppModule中:
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
EffectsModule.forRoot([]),
StoreModule.forRoot(reducers),
AuthenticationModule.forRoot(authenticationConfig),
StoreRouterConnectingModule.forRoot({
stateKey: 'router'
}),
StoreDevtoolsModule.instrument({ maxAge: 25, logOnly: !isDevMode() }),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {
constructor(private store: Store) {
this.store.pipe(select(state => state))
.subscribe(state => {
console.log('Current store state - APP MODULE:', state);
});
}
}
如您所见,我向每个模块的构造函数添加了一些记录器。这是他们记录的内容:
据我了解,授权功能密钥应该出现在这些日志上,对吧?
我还检查了 redux DevTools,我的操作确实被调度,但效果从未被触发: