0

我很难找出事件是从哪里分派的。但我注意到GET_USER_SUCCESS只有当您在初始加载时编辑已经从服务器获取的用户时才会触发。

效果.ts:

//Get users
this.getUsers$ = this.actions$.pipe(
    ofType(GET_USERS),
    switchMap(() =>
        this.service.getUsers()
            .pipe(
                map((users) => new GetUsersSuccess(users)),
                catchError(error => of(new GetUserFail(error)))
            )
    )
);

//Update a newly created user
this.updateUser = this.actions$.pipe(
    ofType(UPDATE_USER),
    map((action: any) => action.payload),
    switchMap(form => {
        return this.service.updateUser(user)
            .pipe(                              map((user) => new UpdateUserSuccess(user)),
                catchError(error => of(new UpdateUserFail(error)))
            );
    })
);

在我的 reducer.ts 中:

switch (action.type) {
    case CREATE_USER_SUCESS:
        return adapter.addOne(action.payload, state);

    case GET_USER_SUCCESS:
    return adapter.addAll(action.payload, state); -->Getting fired

    case UPDATE_USER_SUCCESS:
        return adapter.updateOne({
            id: action.payload.id,
            changes: action.payload
        }, state);
    default:
        return state;
}
4

0 回答 0