example application provided by NgRx에 대한 코드를 검토하고있었습니다. 예제 응용 프로그램의 각 감속기 함수가 해당 감속기에 대한 State
인터페이스에 의해 입력 된 반환 값을 가지고있는 것으로 나타났습니다. (나는 오렌 Farhi에 의해 Reactive Programming with Angular and NgRx 제목 NgRx에 대한 책을 읽고 있었다, 나중에상태 vs ActionReducer <State> as NgRx reducer 반환 유형
export interface State {
ids: string[];
entities: { [id: string]: Book };
selectedBookId: string | null;
}
export const initialState: State = {
ids: [],
entities: {},
selectedBookId: null,
};
export function reducer(
state = initialState,
action: book.Actions | collection.Actions
): State {
및 감속기 함수의 일반적인 신체 구조를 보여주는 코드 건너 온 : 예를 들어, 책 감속기는 다음과 같은 코드가 있습니다 .
export interface SomeInterface {
items: Item[],
filter: string
}
let initialState: SomeInterface = {
items: [],
filter: ''
}
export function MyReducer (
state: SomeInterface = initialState,
action: Action
): ActionReducer<SomeInterface> {
: 24-25 페이지에) 일반적인 구조에 대한 코드는이 경우 SomeInterface
보다는 State
불리는 타입 파라미터()로 State
으로 ActionReducer
가 입력되는 것으로 감속기 함수의 리턴 값을 나타낸다 왜 하나의 코드 샘플은 State와 다른 코드 샘플을 사용합니까? 감속기 함수의 반환 값에 대한 유형 매개 변수로 State가있는 ActionReducer를 사용합니까? 왜 다른 사람보다이 기능 서명 중 하나를 선택하겠습니까? 각각의 목적은 무엇입니까?
이 책은 NgRx 2.2.1 용으로 작성되었지만 예제 응용 프로그램은 최신 버전의 NgRx (버전 4.1.1) 용입니다. 반환 유형의 차이는 NgRx의 차이로 간단히 설명 할 수 없다고 생각합니다. NgRx의 최신 버전에는 ActionReducer도 있습니다.
감사합니다.
사용 정의이 [* * medium blog **] (https://medium.com/@aravindfz/setting-up-storemodule-in-ngrx-4-0-b7c60732aa64) ngrx-4.0을 설정하십시오. – Aravind