本文整理汇总了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),
};
}