本文整理匯總了TypeScript中@ngrx/store.createSelector函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createSelector函數的具體用法?TypeScript createSelector怎麽用?TypeScript createSelector使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了createSelector函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: setCollectionSelectors
function createHeroSidekickSelector$(heroId: number): Observable<Sidekick> {
const { selectHeroMap, selectSidekickMap } = setCollectionSelectors();
const selectHero = createSelector(selectHeroMap, heroes => heroes[heroId]);
const selectSideKick = createSelector(selectHero, selectSidekickMap, (hero, sidekicks) => {
const sidekickId = hero && hero.sidekickFk;
return sidekicks[sidekickId];
});
return store.select(selectSideKick);
}
示例2: it
it('should recursively release ancestor selectors', () => {
const grandparent = createSelector([incrementOne], a => a);
const parent = createSelector([grandparent], a => a);
const child = createSelector([parent], a => a);
spyOn(grandparent, 'release').and.callThrough();
spyOn(parent, 'release').and.callThrough();
child.release();
expect(grandparent.release).toHaveBeenCalled();
expect(parent.release).toHaveBeenCalled();
});
示例3: getSelectors
function getSelectors(
selectState?: (state: any) => EntityState<T>
): EntitySelectors<T, any> {
const selectIds = (state: any) => state.ids;
const selectEntities = (state: EntityState<T>) => state.entities;
const selectAll = createSelector(
selectIds,
selectEntities,
(ids: T[], entities: Dictionary<T>): any =>
ids.map((id: any) => (entities as any)[id])
);
const selectTotal = createSelector(selectIds, ids => ids.length);
if (!selectState) {
return {
selectIds,
selectEntities,
selectAll,
selectTotal,
};
}
return {
selectIds: createSelector(selectState, selectIds),
selectEntities: createSelector(selectState, selectEntities),
selectAll: createSelector(selectState, selectAll),
selectTotal: createSelector(selectState, selectTotal),
};
}