Почему платформа / эффекты ngRx запускают не отправленные действия? - PullRequest
0 голосов
/ 26 апреля 2018

Мне было трудно выяснить, откуда отправляются события. Но я заметил, что 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)))
            );
    })
);

В моем редукторе.ц:

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