Ngrx如何摆脱选择器中的类型
Ngrx how to get rid of type in selector
效果class我有这个代码
withLatestFrom(this.store.pipe(select(selectSettings))),
tap(([action, settings]) => {
console.log('settings', settings);
/*
print {lang:'en',theme:'dark', type: "[Settings Page] Change Language"}
instead of simply {lang:'en',theme:'dark'}
*/
this.localStorageService.setItem(SETTINGS_KEY, settings);
}
我想知道如何摆脱它
为什么会有这个额外的 属性,谢谢
检查您的 [Settings Page] Change Language
减速器。貌似写错了,把自己的类型加到state
这可能正在发生
const changeLanguage = createActions('[Settings Page] Change Language', props<{ lang: string }>())
on(changeLanguage, (state, action) => {
...state,
...action // Action object is { lang: 'eng', type: '[Settings Page] Change Language' }
});
// correct version
on(changeLanguage, (state, { lang }) => {
...state,
lang
// lang: action.lang - if you don't spread the action object
});
效果class我有这个代码
withLatestFrom(this.store.pipe(select(selectSettings))),
tap(([action, settings]) => {
console.log('settings', settings);
/*
print {lang:'en',theme:'dark', type: "[Settings Page] Change Language"}
instead of simply {lang:'en',theme:'dark'}
*/
this.localStorageService.setItem(SETTINGS_KEY, settings);
}
我想知道如何摆脱它 为什么会有这个额外的 属性,谢谢
检查您的 [Settings Page] Change Language
减速器。貌似写错了,把自己的类型加到state
这可能正在发生
const changeLanguage = createActions('[Settings Page] Change Language', props<{ lang: string }>())
on(changeLanguage, (state, action) => {
...state,
...action // Action object is { lang: 'eng', type: '[Settings Page] Change Language' }
});
// correct version
on(changeLanguage, (state, { lang }) => {
...state,
lang
// lang: action.lang - if you don't spread the action object
});