반응형
createReducer 함수를 사용할 때 생산을 위해 angular+ngrx 8을 빌드하는 동안 오류가 발생했습니다.
현재 저는 새로운 NgRX 크리에이터 기능으로 Angular + NgRX 8 애플리케이션을 구축하려고 합니다.하지만 생산을 위해 이 제품을 제작할 때 다음과 같은 오류가 나타납니다.
데코레이터에서는 함수 호출이 지원되지 않지만 'createReducer'가 'reducer'로 호출되었습니다.
개발 모드에서는 전혀 문제가 없습니다.
요청 감소기는 다음과 같습니다.
export interface State extends EntityState<Request> {
loading: boolean;
error: any;
}
export const initialState = adapter.getInitialState({
loading: false,
error: null
});
export const reducer = createReducer(
initialState,
on(RequestsActions.loadRequestsSuccess, (state, { requests }) => adapter.addAll(requests, {...state, loading: false})),
on(RequestsActions.loadRequestsFailed, (state, { error }) => ({...state, error, loading: false})),
on(RequestsActions.deleteRequestSuccess, (state, { id }) => adapter.removeOne(id, state))
);
그리고 다른 축소자들과 함께 index.ts 파일로 구성됩니다.
export const reducers = {
requests: reducer
// [...]
}
스토어 모듈은 축소자 맵과 함께 다음과 같이 가져옵니다.
@NgModule({
imports: [
CommonModule,
StoreModule.forFeature('requests', reducers),
EffectsModule.forFeature(effects),
// [...]
]
})
export class RequestsModule {}
무슨 일인지 아십니까?감사합니다!
다음과 같은 함수 호출로 감속기를 래핑해야 합니다.
const yourReducer = createReducer(
initialState,
on(RequestsActions.loadRequestsSuccess, (state, { requests }) => adapter.addAll(requests, {...state, loading: false})),
on(RequestsActions.loadRequestsFailed, (state, { error }) => ({...state, error, loading: false})),
on(RequestsActions.deleteRequestSuccess, (state, { id }) => adapter.removeOne(id, state))
);
export function reducer(state: State | undefined, action: Action) {
return yourReducer(state, action);
}
공식 문서 참조 -
https://ngrx.io/guide/store/reducers#creating-the-reducer-function
언급URL : https://stackoverflow.com/questions/56993101/error-building-angularngrx-8-for-production-when-using-createreducer-function
반응형
'programing' 카테고리의 다른 글
작업 시트에 UI Picker View 및 버튼 추가 - 어떻게? (0) | 2023.06.12 |
---|---|
여러 data.frame을 여러 Excel 워크시트로 쉽게 내보낼 수 있는 방법 (0) | 2023.06.12 |
지리적 근접 공식(스토어 로케이터)으로 인해 결과 누락 (0) | 2023.06.12 |
수직 gem_vline을 클래스 날짜의 x축으로 가져오는 방법은 무엇입니까? (0) | 2023.06.07 |
루비에서 현재 작업 디렉터리의 절대 경로를 얻는 방법은 무엇입니까? (0) | 2023.06.07 |