0
我明白了什麼是我們不需要訂閱喜歡觀測的影響,因爲我們沒有消費的結果, 例如像:我如何記錄效果的價值,因爲我們不會向任何地方付費?
const subscribe = source.subscribe(val => console.log(val))
但有可能登錄無需訂閱? 這裏是我的代碼,說我想記錄,addUserStats $效果。
用戶配置文件,effects.ts:
@Injectable()
export class UserProfileEffects {
constructor(
private actions$: Actions,
private userProfileActions: UserProfileActions,
private userProfile: UserProfile,
private auth: Authorization
) { }
@Effect()
updateToken$ = this.actions$
.ofType(UserProfileActions.UPDATE_TOKEN)
.map(action => action.payload)
.map((token: string) => this.auth.accessToken = token)
.switchMap(token => this.userProfile.getStats(true))
.map(response => this.userProfileActions.updateData(response));
@Effect()
addUserStats$ = this.actions$
.ofType(UserProfileActions.UPDATE)
.map(action => action.payload)
.map((data: any) => this.userProfileActions.addStats(data.items));
}
effects.ts:
export default [
NowStatEffects,
UserProfileEffects
];
core.module.ts:
import effects from './effects';
@NgModule({
imports: [
CoreStoreModule,
...effects.map(effect => EffectsModule.run(effect)),
],
declarations: [
],
exports: [
CoreStoreModule,
],
providers: [
...APP_SERVICES
]
})
export class CoreModule {
constructor(@Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
}
使用'。做(的console.log)'。 [This](http://blog.angular-university.io/debug-rxjs/)也可能有用。 – Sasxa
偉大的工作,你可以發佈它作爲答案,如果你有'.map(console.log)'的差異的解釋' – ishandutta2007
@Sasxa你可能想提供它作爲答案:-) – echonax