当我使用文件A中定义的createSelector
在文件B中执行Selector
时,我几次遇到以下错误...显然是Selector
中定义的undefined
文件A尚未实例化,我收到Error: Selector creators expect all input-selectors to be functions, instead received the following types: [function, undefined] at getDependencies
(http://localhost:3000/index.js:47281:11) [<root>] at Object.createSelector
(http://localhost:3000/index.js:47299:24) [<root>] at Object.<anonymous>
(http://localhost:3000/index.js:170074:45) [<root>] at __webpack_require__
(http://localhost:3000/index.js:20:30) [<root>] at Object.<anonymous>
(http://localhost:3000/index.js:112827:10) [<root>] at __webpack_require__
(http://localhost:3000/index.js:20:30) [<root>] at Object.<anonymous>
(http://localhost:3000/index.js:112838:20) [<root>] at __webpack_require__
(http://localhost:3000/index.js:20:30) [<root>] at Object.<anonymous>
(http://localhost:3000/index.js:85408:17) [<root>] at __webpack_require__
(http://localhost:3000/index.js:20:30) [<root>] at Object.<anonymous>
(http://localhost:3000/index.js:113264:18) [<root>] at __webpack_require__
(http://localhost:3000/index.js:20:30) [<root>] at Object.<anonymous>
(http://localhost:3000/index.js:28456:10) [<root>] at __webpack_require__
(http://localhost:3000/index.js:20:30) [<root>]
引用错误...
export interface State {
accounts?: IDenormalizedAccount[];
id?: AccountID;
}
由于我曾经遇到过这种情况,我的想法是其他人会有类似的问题,但搜索stackoverflow和互联网并没有产生任何有意义的东西......这让我相信我还没有另一个根本的误解......
档案状态(商店/帐户)
import * as reportStore from 'Store/report';
const rootExtractor: (applicationState: ApplicationStates) => accountStore.State = (applicationState: ApplicationStates) => {
if (!applicationState.account) {
throw new Error('Account state was null or undefined within the application ngrx store');
}
return applicationState.account;
};
export const accountsExtractor: (state: accountStore.State) => IDenormalizedAccount[] = (state: accountStore.State) => !!state.accounts ? state.accounts : [];
export const accountsSelector = createSelector(rootExtractor, accountsExtractor);
export const reportAccountsExtractor: (accounts: IDenormalizedAccount[], id: ReportID) => IDenormalizedAccount[] = (accounts: IDenormalizedAccount[], id: ReportID): IDenormalizedAccount[] => !!id ? accounts.filter((account: IDenormalizedAccount) => id === account.reportId) : [];
export const reportAccountsSelector: Selector<any, IDenormalizedAccount[]> = createSelector(accountsSelector, reportStore.reportIdSelector, reportAccountsExtractor);
文件A选择器(商店/帐户)
export interface State {
reports: Report[];
id?: ReportID;
}
文件B状态(存储/报告)
const rootExtractor: (applicationState: ApplicationStates) => reportStore.State = (applicationState: ApplicationStates) => {
if (!applicationState.report) {
throw new Error('Report state was null or undefined within the application ngrx store');
}
return applicationState.report;
};
export const reportIdExtractor: (state: reportStore.State) => ReportID = (state: reportStore.State): ReportID => !!state.id ? state.id : undefined;
export const reportIdSelector: Selector<any, ReportID> = createSelector(rootExtractor, reportIdExtractor);
文件B选择器(存储/报告)
reportStore.reportIdSelector
undefined
(在显示的最后一行)当createSelector
用来实例化reportAccountsSelector
在过去,我已经在&#34; root&#34;之间移动或复制了一些州。在我的商店中的对象,但这不是干的 - 所以,为什么我的方法失败并且是否有更好的(正确的)方法来处理我想从应用商店的其他部分访问状态的情况?