當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript store.createSelector函數代碼示例

本文整理匯總了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);
 }
開發者ID:RajeevSingh273,項目名稱:angular-ngrx-data,代碼行數:9,代碼來源:related-entity-selectors.spec.ts

示例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();
    });
開發者ID:WinGood,項目名稱:platform,代碼行數:12,代碼來源:selector.spec.ts

示例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),
    };
  }
開發者ID:AlexChar,項目名稱:platform,代碼行數:30,代碼來源:state_selectors.ts


注:本文中的@ngrx/store.createSelector函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。