@reduxjs/toolkit#createSelector TypeScript Examples

The following examples show how to use @reduxjs/toolkit#createSelector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts    From frontegg-react with MIT License 7 votes vote down vote up
selectedEvents = createSelector(
  (events?: string[]) => events,
  (events?: string[]) =>
    events?.reduce(
      (acc: { names: string[]; eventKeys: string[] }, curr) => {
        if (/\.\*$/.test(curr)) {
          const val = curr.replace(/\.\*$/, '');
          !acc.names.includes(val) && acc.names.push(val);
        } else if (!acc.eventKeys.includes(curr)) {
          acc.eventKeys.push(curr);
        }
        return acc;
      },
      { names: [], eventKeys: [] }
    )
)
Example #2
Source File: selectors.ts    From moodtracker with MIT License 6 votes vote down vote up
moodIdsByDateSelector = createSelector(
  normalizedMoodsSelector,
  ({ allIds }): { [date: string]: string[] | undefined } => {
    const moodsGroupedByDate: { [date: string]: string[] } = {};

    for (let i = 0; i < allIds.length; i++) {
      const id = allIds[i];
      const key = formatIsoDateInLocalTimezone(new Date(id));
      if (moodsGroupedByDate[key]) moodsGroupedByDate[key].push(id);
      else moodsGroupedByDate[key] = [id];
    }

    return moodsGroupedByDate;
  }
)
Example #3
Source File: hooks.ts    From celo-web-wallet with MIT License 6 votes vote down vote up
balancesWithTokensSelector = createSelector(
  (s: AppState) => s.tokens.byAddress,
  (s: AppState) => s.balances.accountBalances,
  (customTokens, accountBalances) => {
    const allTokens = { ...customTokens, ...NativeTokensByAddress }
    return {
      ...accountBalances,
      tokenAddrToToken: getMergedTokenBalances(allTokens, accountBalances.tokenAddrToValue),
    }
  }
)
Example #4
Source File: selectors.ts    From local-addon-image-optimizer with MIT License 6 votes vote down vote up
uncompressedSiteImages = createSelector(
	selectActiveSite,
	(siteState) =>
		siteState
			? Object.values(siteState.imageData).filter(
				(d) => !d.compressedImageHash && !d.errorMessage,
			)
			: [],
)
Example #5
Source File: nights.ts    From nyxo-app with GNU General Public License v3.0 6 votes vote down vote up
getNightForSelectedDate = createSelector(
  [getNights, getSelectedDate, (state) => state.source.source],
  (nights, selectedDate, tracker) => {
    return nights
      .filter((night) => {
        return night.sourceId === tracker
      })
      .filter((night) => {
        return matchDayAndNight(night.startDate, selectedDate)
      })
  }
)
Example #6
Source File: selectors.ts    From jellyfin-audio-player with MIT License 6 votes vote down vote up
selectDownloadedTracks = (trackIds: EntityId[]) => (
    createSelector(
        selectAllDownloads,
        ({ entities, ids }) => {
            return intersection(trackIds, ids)
                .filter((id) => entities[id]?.isComplete);
        }
    )
)
Example #7
Source File: selectors.ts    From react-boilerplate-cra-template with MIT License 6 votes vote down vote up
selectTheme = createSelector(
  [(state: RootState) => state.theme || initialState],
  theme => {
    if (theme.selected === 'system') {
      return isSystemDark ? themes.dark : themes.light;
    }
    return themes[theme.selected];
  },
)
Example #8
Source File: selectors.ts    From datart with Apache License 2.0 6 votes vote down vote up
makeDataviewTreeSelector = () =>
  createSelector(
    [
      dataviewsSelector,
      (_, getSelectable: (o: ChartDataView) => boolean) => getSelectable,
    ],
    (dataviews, getSelectable) =>
      listToTree(dataviews, null, [ResourceTypes.View], { getSelectable }),
  )
Example #9
Source File: selectors.ts    From TutorBase with MIT License 5 votes vote down vote up
selectClientData = createSelector(
    [selectDomain],
    selectDomain => selectDomain,
)
Example #10
Source File: index.ts    From keycaplendar with MIT License 5 votes vote down vote up
selectCurrentThemeMap = createSelector(
  [selectTheme, selectThemesMap],
  (theme, themesMap) => themesMap[theme] as ThemeMap | undefined
)
Example #11
Source File: account-slice.ts    From lobis-frontend with MIT License 5 votes vote down vote up
getAccountState = createSelector(baseInfo, account => account)
Example #12
Source File: account-slice.ts    From rugenerous-frontend with MIT License 5 votes vote down vote up
getAccountState = createSelector(baseInfo, account => account)
Example #13
Source File: account-slice.ts    From wonderland-frontend with MIT License 5 votes vote down vote up
getAccountState = createSelector(baseInfo, account => account)
Example #14
Source File: selector.ts    From your_spotify with GNU General Public License v3.0 5 votes vote down vote up
selectAccounts = createSelector(selectAdminState, (state) => state.accounts)
Example #15
Source File: selectors.ts    From moodtracker with MIT License 5 votes vote down vote up
normalizedMeditationsSelector = createSelector(
  trackedCategoriesSelector,
  ({ meditations }): NormalizedMeditations => meditations
)
Example #16
Source File: hooks.ts    From celo-web-wallet with MIT License 5 votes vote down vote up
balanceEmptySelector = createSelector(
  (s: AppState) => s.balances.accountBalances,
  (balances) => areBalancesEmpty(balances)
)
Example #17
Source File: selectors.ts    From baidu-pan-downloader with MIT License 5 votes vote down vote up
downloadableSelector = createSelector(
  (store: IStoreState) => store.download.processing,
  (store: IStoreState) => store.interface.maxDownloadCount,
  (processing, maxDownloadCount) => {
    return processing < maxDownloadCount
  }
)
Example #18
Source File: selectors.ts    From local-addon-image-optimizer with MIT License 5 votes vote down vote up
activeSiteID = createSelector(
	() => store.getState(),
	({ activeSiteID }) => activeSiteID,
)
Example #19
Source File: calendar.ts    From nyxo-app with GNU General Public License v3.0 5 votes vote down vote up
getSelectedDate = createSelector(
  (state: RootState) => state.calendar.selectedDay,
  (date) => date
)