Angular NGRX为什么减速器对从效应中发出的动作不作出反应?
NGRX实现的一个功能包括 两个动作Angular NGRX为什么减速器对从效应中发出的动作不作出反应?,angular,typescript,rxjs,ngrx,Angular,Typescript,Rxjs,Ngrx,NGRX实现的一个功能包括 两个动作 export class UpdateWordListAction implements Action { static readonly TYPE = 'UPDATE_WORD_LIST'; readonly type = "UPDATE_WORD_LIST"; constructor() {}; } export class WordListLoadedSuccessAction implements Acti
export class UpdateWordListAction implements Action {
static readonly TYPE = 'UPDATE_WORD_LIST';
readonly type = "UPDATE_WORD_LIST";
constructor() {};
}
export class WordListLoadedSuccessAction implements Action {
readonly words: Word[];
static readonly TYPE = 'WORD_LIST_LOADED_SUCCESS';
readonly type = "WORD_LIST_LOADED_SUCCESS";
constructor(words: Word[]) {};
}
客户端
this.store.dispatch(new UpdateWordListAction());
@Effect()
testEffect$ = this.actions$.pipe(
ofType(UpdateWordListAction.TYPE),
tap(console.log), // Runtime: UpdateWordListAction {type: "UPDATE_WORD_LIST"}
switchMap(() => this.wordService.getWordList()),
tap(console.log), // Runtime: (2) [{…}, {…}]
map(words => new WordListLoadedSuccessAction(words)),
catchError(() => EMPTY));
效果
this.store.dispatch(new UpdateWordListAction());
@Effect()
testEffect$ = this.actions$.pipe(
ofType(UpdateWordListAction.TYPE),
tap(console.log), // Runtime: UpdateWordListAction {type: "UPDATE_WORD_LIST"}
switchMap(() => this.wordService.getWordList()),
tap(console.log), // Runtime: (2) [{…}, {…}]
map(words => new WordListLoadedSuccessAction(words)),
catchError(() => EMPTY));
和减速器
export const reducers = combineReducers<AppState, any>({
words(state = initialAppState.words, action: WordListLoadedSuccessAction) {
console.log(action); // Never reached!
return action.words;
}
});
导出常量减速机=组合减速机({
words(state=initialAppState.words,action:wordListedSuccessAction){
console.log(操作);//从未到达!
返回动作。单词;
}
});
我不明白这个减速机为什么不工作。请帮助找出问题所在。您不使用现代NgRx方法(如
createAction
和createReducer
)的任何原因?后者允许您在上使用,以方便操作减速器的设置。您的减速器是否已在相应的模块中注册?