reselect#createSelector TypeScript Examples

The following examples show how to use reselect#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: inspectorSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
getReplayEnabled = createSelector([getActiveDescriptors], (selected) => {

	if (selected.length < 1) {
		return false;
	}
	if (selected.some(item => item.originalReference.data.some(subitem => subitem.content.value === "reply" || subitem.content.value === "dispatch"))) {
		return false;
	}
	return true;
})
Example #2
Source File: selector.ts    From multisig-react with MIT License 6 votes vote down vote up
extendedSafeTokensSelector = createSelector(
  safeActiveTokensSelector,
  safeBalancesSelector,
  tokensSelector,
  safeEthAsTokenSelector,
  (safeTokens, balances, tokensList, ethAsToken): List<Token> => {
    const extendedTokens = Map<string, Token>().withMutations((map) => {
      safeTokens.forEach((tokenAddress) => {
        const baseToken = tokensList.get(tokenAddress)
        const tokenBalance = balances?.get(tokenAddress)

        if (baseToken) {
          map.set(tokenAddress, baseToken.set('balance', tokenBalance || '0'))
        }
      })
    })

    if (ethAsToken) {
      return extendedTokens.set(ethAsToken.address, ethAsToken).toList()
    }

    return extendedTokens.toList()
  },
)
Example #3
Source File: inspectorSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
getActiveDescriptorOriginalReference = createSelector([getActiveDescriptors, getAutoActiveDescriptor], (selected, autoActive) => {
	if (selected.length > 1) {
		return "Select 1 descriptor";
	} else if (selected.length === 1) {
		return JSON.stringify(selected[0].originalReference, null, 3);
	} else if (autoActive) {
		return JSON.stringify(autoActive.originalReference, null, 3);
	} else {
		return "Add some descriptor";
	}
})
Example #4
Source File: selector.ts    From multisig-react with MIT License 6 votes vote down vote up
safeKnownCoins = createSelector(
  tokensSelector,
  safeEthAsTokenSelector,
  (safeTokens, nativeCoinAsToken): List<Token> => {
    if (nativeCoinAsToken) {
      return safeTokens.set(nativeCoinAsToken.address, nativeCoinAsToken).toList()
    }

    return safeTokens.toList()
  },
)
Example #5
Source File: selectors.ts    From anthem with Apache License 2.0 6 votes vote down vote up
i18nSelector = createSelector(i18nLocale, locale => {
  const catalog = getCatalogFromLocale(locale);
  const fns = {
    t: createTranslationMethodFromLocale(catalog),
    tString: createStringTranslationMethodFromLocale(catalog),
  };

  return {
    locale,
    ...fns,
  };
})
Example #6
Source File: inspectorSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
getAutoSelectedUUIDs = createSelector([getAutoActiveDescriptor, getSecondaryAutoActiveDescriptor,getModeTabID], (first,second,mode) => {
	const f = first?.id;
	const s = (mode==="difference") ? second?.id : null;
	const result: string[] = [];
	if (f) { result.push(f); }
	if (s) { result.push(s); }
	
	return result;
})
Example #7
Source File: selector.ts    From multisig-react with MIT License 6 votes vote down vote up
modulesTransactionsBySafeSelector = createSelector(
  moduleTransactionsSelector,
  safeParamAddressFromStateSelector,
  (moduleTransactions, safeAddress): ModuleTxServiceModel[] => {
    // no module tx for the current safe so far
    if (!moduleTransactions || !safeAddress || !moduleTransactions[safeAddress]) {
      return []
    }

    return moduleTransactions[safeAddress]
  },
)
Example #8
Source File: queries.ts    From anthem with Apache License 2.0 6 votes vote down vote up
graphqlSelector = createSelector(
  [addressSelector, networkSelector, fiatSelector, transactionsPageSelectors],
  (address, network, fiat, startingPage) => {
    return {
      fiat,
      address,
      startingPage,
      network: network.name,
      networkDefinition: network,
      currency: network.cryptoCompareTicker,
    };
  },
)
Example #9
Source File: inspectorSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
getAddAllowed = createSelector([getActiveTargetReference], s => { 
	if (s) {
		if (s.type === "generator") {
			return true;
		}
		if (s.type === "listener") {
			return false;
		}
		for (const key in s.data) {
			// eslint-disable-next-line @typescript-eslint/no-explicit-any
			if ((s.data as any)[key] === "undefined") {
				return false;
			}
		}
		return true;
	}
	return false;
})
Example #10
Source File: selectors.ts    From che-dashboard-next with Eclipse Public License 2.0 6 votes vote down vote up
selectMetadataFiltered = createSelector(
  selectState,
  selectFilterTokens,
  selectMetadata,
  (state, filterTokens, metadata) => {
    if (filterTokens.length === 0) {
      return metadata;
    }
    return metadata.filter(meta => matches(meta, filterTokens));
  }
)
Example #11
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeBlacklistedAssetsSelector = createSelector(
  safeSelector,
  (safe): Set<string> => {
    if (!safe) {
      return Set()
    }

    return safe.blacklistedAssets
  },
)
Example #12
Source File: atnSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
selectedSets = createSelector([
	all,
	getSelectedItemsSet,
], (s,sets) => {
	const res: (IActionSetUUID)[] = [];
	
	sets.forEach(set => {
		const found = s.data.find((r => r.__uuid__ === set[0]));
		if (found) {
			res.push(found);			
		}
	});

	return res;
})
Example #13
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeActiveAssetsSelector = createSelector(
  safeSelector,
  (safe): Set<string> => {
    if (!safe) {
      return Set()
    }
    return safe.activeAssets
  },
)
Example #14
Source File: selectors.ts    From che-dashboard-next with Eclipse Public License 2.0 6 votes vote down vote up
selectWorkspaceByQualifiedName = createSelector(
  selectState,
  selectAllWorkspaces,
  (state, allWorkspaces) => {
    if (!allWorkspaces) {
      return null;
    }
    return allWorkspaces.find(workspace =>
      workspace.namespace === state.namespace && workspace.devfile.metadata.name === state.workspaceName);
  }
)
Example #15
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeSelector = createSelector(
  safesMapSelector,
  safeParamAddressFromStateSelector,
  (safes: SafesMap, address: string): SafeRecord | undefined => {
    if (!address) {
      return undefined
    }
    const checksumed = checksumAddress(address)
    return safes.get(checksumed)
  },
)
Example #16
Source File: selectors.ts    From che-dashboard-next with Eclipse Public License 2.0 6 votes vote down vote up
selectRecentWorkspaces = createSelector(
  selectRecentNumber,
  selectAllWorkspacesSortedByTime,
  (recentNumber, workspacesSortedByTime) => {
    if (!workspacesSortedByTime) {
      return null;
    }

    return workspacesSortedByTime.slice(0, recentNumber);
  }
)
Example #17
Source File: canvas-strategies.tsx    From utopia with MIT License 6 votes vote down vote up
getApplicableStrategiesSelector = createSelector(
  (store: EditorStorePatched): InteractionCanvasState => {
    return {
      selectedElements: store.editor.selectedViews,
      projectContents: store.editor.projectContents,
      openFile: store.editor.canvas.openFile?.filename,
      scale: store.editor.canvas.scale,
      canvasOffset: store.editor.canvas.roundedCanvasOffset,
    }
  },
  (store: EditorStorePatched) => store.editor.canvas.interactionSession,
  (store: EditorStorePatched) => store.editor.jsxMetadata,
  (store: EditorStorePatched) => store.editor.allElementProps,
  (
    canvasState: InteractionCanvasState,
    interactionSession: InteractionSession | null,
    metadata: ElementInstanceMetadataMap,
    allElementProps: AllElementProps,
  ): Array<CanvasStrategy> => {
    return getApplicableStrategies(
      RegisteredCanvasStrategies,
      canvasState,
      interactionSession,
      metadata,
      allElementProps,
    )
  },
)
Example #18
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeIncomingTransactionsSelector = createSelector(
  incomingTransactionsSelector,
  safeParamAddressFromStateSelector,
  (incomingTransactions, address) => {
    if (!incomingTransactions) {
      return List([])
    }

    if (!address) {
      return List([])
    }

    return incomingTransactions.get(address, List([]))
  },
)
Example #19
Source File: simulationSelectors.ts    From nosgestesclimat-site with MIT License 6 votes vote down vote up
objectifsSelector = createSelector([configSelector], (config) => {
	const primaryObjectifs = (config.objectifs ?? ([] as any))
		.map((obj: DottedName | { objectifs: Array<DottedName> }) =>
			typeof obj === 'string' ? [obj] : obj.objectifs
		)
		.flat()

	const objectifs = [...primaryObjectifs, ...(config['objectifs cachés'] ?? [])]
	return objectifs
})
Example #20
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeTransactionsSelector = createSelector(
  transactionsSelector,
  safeParamAddressFromStateSelector,
  (transactions, address) => {
    if (!transactions) {
      return List([])
    }

    if (!address) {
      return List([])
    }

    return transactions.get(address, List([]))
  },
)
Example #21
Source File: atnSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
selectedActions = createSelector([
	all,
	getSelectedItemsAction,
], (s,actions) => {
	const res: (IActionItemUUID)[] = [];
	
	actions.forEach(item => {
		const found = s.data.find((r => r.__uuid__ === item[0]));
		const found2 = found?.actionItems?.find((r => r.__uuid__ === item[1]));
		if (found2) {
			res.push(found2);			
		}
	});

	return res;
})
Example #22
Source File: DownloadingTab.tsx    From baidu-pan-downloader with MIT License 6 votes vote down vote up
mapStoreToProps = (store: IStoreState) => ({
  fsIdList: createSelector(
    (store: IStoreState) => store.download.downloadItems,
    (allDownloads) =>
      Object.keys(allDownloads)
        .sort((a) => (allDownloads[a].status === StatusTypes.downloading ? -1 : 1))
        .filter((fsId) => [StatusTypes.downloading, StatusTypes.inQueued].includes(allDownloads[fsId].status))
  )(store),
})
Example #23
Source File: atnSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
selectedCommands = createSelector([
	all,
	getSelectedItemsCommand,
], (s,commands) => {
	const res: (IActionCommandUUID)[] = [];
	
	commands.forEach(item => {
		const found = s.data.find((r => r.__uuid__ === item[0]));
		const found2 = found?.actionItems?.find((r => r.__uuid__ === item[1]));
		const found3 = found2?.commands?.find((r => r.__uuid__ === item[2]));
		if (found3) {
			res.push(found3);			
		}
	});

	return res;
})
Example #24
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeFiatBalancesTotalSelector = createSelector(
  safeFiatBalancesListSelector,
  currencyRateSelector,
  (currencyBalances, currencyRate): string | null => {
    if (!currencyBalances) return '0'
    if (!currencyRate) return null

    const totalInBaseCurrency = currencyBalances.reduce((total, balanceCurrencyRecord) => {
      return total.plus(balanceCurrencyRecord.balanceInBaseCurrency)
    }, new BigNumber(0))

    return totalInBaseCurrency.times(currencyRate).toFixed(2)
  },
)
Example #25
Source File: inspectorDiffSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
getRightTreeDiff  = createSelector([getSelectedDescriptors,getDiffPath,getSecondaryAutoActiveDescriptor],(t,diffPath,autoDesc)=>{
	const path = cloneDeep(diffPath);
	//path.shift();
	let data:any = cloneDeep(t?.[1]?.originalData ?? autoDesc?.originalData);
	for (const part of path) {
		data = (data)?.[part];
	}
	return data;
})
Example #26
Source File: selectors.ts    From firebase-tools-ui with Apache License 2.0 6 votes vote down vote up
getFilteredUsers = createSelector(
  getUsers,
  getFilter,
  (users: AuthUser[], filter: string) => {
    if (!filter) {
      return users;
    }
    return users.filter((u) => {
      return [u.localId, u.displayName, u.email || '', u.phoneNumber || '']
        .join('\n')
        .toLocaleUpperCase()
        .includes(filter.toLocaleUpperCase());
    });
  }
)
Example #27
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
safeActiveSelectorMap = createSelector(
  activeNftAssetsListSelector,
  (activeAssets): NFTAssets => {
    return activeAssets.reduce((acc, asset) => {
      acc[asset.address] = asset
      return acc
    }, {})
  },
)
Example #28
Source File: inspectorDOMSelectors.ts    From alchemist with MIT License 6 votes vote down vote up
getTreeDomInstance = createSelector([getTreeDom], (t) => {
	if (t.ref) {
		let sub:any = GetDOM.getDom(t.ref);
		
		const paths = t.path;
		for (const part of paths) {
			sub = (sub)?.[part];
		}
		return sub;	
	}
})
Example #29
Source File: index.ts    From multisig-react with MIT License 6 votes vote down vote up
activeNftAssetsListSelector = createSelector(
  nftAssetsListSelector,
  safeActiveAssetsSelector,
  availableNftAssetsAddresses,
  (assets, activeAssetsList, availableNftAssetsAddresses): NFTAsset[] => {
    return assets
      .filter(({ address }) => activeAssetsList.has(address))
      .filter(({ address }) => availableNftAssetsAddresses.includes(address))
  },
)