Посмотрел в Интернете и не могу найти пример использования import produce, {Draft} from "immer";
с ngrx on()
. Самое близкое, что я могу найти: неполное решение по: https://github.com/immerjs/immer/issues/252
import produce, { Draft } from 'immer';
import { ActionCreator, createReducer, on } from '@ngrx/store';
import { ActionType, FunctionWithParametersType } from '@ngrx/store/src/models';
function produceOn<Type extends string, C extends FunctionWithParametersType<any, object>, State>(
actionType: ActionCreator<Type, C>,
callback: (draft: Draft<State>, action: ActionType<ActionCreator<Type, C>>) => any,
) {
return on(actionType, (state: State, action): State => produce(state, (draft) => callback(draft, action)));
}
// Usage:
const featureReducer = createReducer(
initialState,
produceOn(action, (draft, action) => {
// TODO STUFF
}
);
export function reducer(state = initialState, action) {
return featureReducer(state, action);
}
не знаю, как отключить функцию on () с помощью immer с помощью ngrx 8
Sean.