我正在跟踪docs中的缓存示例。 “我的操作”首先查找现有商店,然后再通过const Signin = () => import('@/components/Authenticate/Signin')
{ path: '/signin', component: Signin, beforeEnter: beforeRouteLoggedIn },
调用进行抓取。 http
在我调用http时成功触发,但是从商店返回时不触发。这是我的商店代码
ofActionSuccesful
以及我的组件
@Action(Get)
get(ctx: StateContext<SubmissionStateModel>, action: Get) {
const id = action.payload;
const submissions = ctx.getState().submissions;
const index = submissions.findIndex(submission => parseInt(submission.id, 10) === parseInt(id, 10));
return index > -1
? ctx.dispatch(new GetSuccess(submissions[index]))
: this._submissionService.get(id).pipe(
map(response => {
ctx.patchState({ submissions: [response, ...submissions] });
return ctx.dispatch(new GetSuccess(response));
}),
);
}
答案 0 :(得分:0)
快速更新,我能够解决这一问题。 actions
订阅者必须位于构造函数内部。我正在ngOnInit
中对其进行初始化。最终代码如下:
constructor(
private _actions: Actions,
) {
this._actions
.pipe(
ofActionSuccessful(SubmissionActions.GetSuccess),
takeUntil(this._onDestroy$),
)
.subscribe(action => {
this._store.dispatch(new SubmissionActions.SetActive(action.payload.id));
this.submissionEditForm.patchValue(action.payload);
});
}