为什么ngRx平台/特效会触发未分派的操作?

时间:2018-04-26 20:04:50

标签: angular rxjs ngrx-store ngrx-effects ngrx-entity

我很难找到事件发送的地方。但是我注意到只有在初始加载时从服务器编辑已经获取的用户时才会触发GET_USER_SUCCESS

effect.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;
}

0 个答案:

没有答案