How to use re-reselect - 10 common examples

To help you get started, we’ve selected a few re-reselect examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github redux-orm / redux-orm / src / redux.js View on Github external
function createSelectorFromSpec(spec) {
    if (spec instanceof MapSelectorSpec) {
        // eslint-disable-next-line no-underscore-dangle
        const parentSelector = createSelectorFromSpec(spec._parent);
        return spec.createResultFunc(parentSelector);
    }
    return createCachedSelector(
        spec.dependencies,
        spec.resultFunc
    )({
        keySelector: spec.keySelector,
        cacheObject: new FlatMapCache(),
        selectorCreator: createSelector, // eslint-disable-line no-use-before-define
    });
}
github redux-orm / redux-orm / src / redux.js View on Github external
function createSelectorFromSpec(spec) {
    if (spec instanceof MapSelectorSpec) {
        // eslint-disable-next-line no-underscore-dangle
        const parentSelector = createSelectorFromSpec(spec._parent);
        return spec.createResultFunc(parentSelector);
    }
    return createCachedSelector(
        spec.dependencies,
        spec.resultFunc
    )({
        keySelector: spec.keySelector,
        cacheObject: new FlatMapCache(),
        selectorCreator: createSelector, // eslint-disable-line no-use-before-define
    });
}
github AugurProject / augur / packages / augur-ui / src / modules / orders / selectors / filled-orders.ts View on Github external
}

function selectMarketsDataStateMarket(state, marketId) {
  return selectMarketInfosState(state)[marketId];
}

function selectMarketTradingHistoryStateMarket(state, marketId) {
  return selectMarketTradingHistoryState(state)[marketId];
}

export default function(marketId) {
  if (!marketId) return [];
  return selectUserFilledOrders(store.getState(), marketId);
}

export const selectUserFilledOrders = createCachedSelector(
  selectMarketTradingHistoryStateMarket,
  selectLoginAccountAddress,
  selectMarketsDataStateMarket,
  selectUserOpenOrders,
  (marketTradeHistory, accountId, marketInfos, openOrders) => {
    if (
      !marketTradeHistory ||
      marketTradeHistory.length < 1 ||
      marketInfos === undefined
    ) {
      return [];
    }

    const tradesCreatedOrFilledByThisAccount = marketTradeHistory.filter(
      (trade) => isSameAddress(trade.creator, accountId) || isSameAddress(trade.filler, accountId),
    );
github RoboPhred / oni-duplicity / src / services / oni-save / components / AbstractPlanet / state-props.ts View on Github external
import createCachedSelector from "re-reselect";
import { find } from "lodash-es";

import { AppState, createStructuredSelector } from "@/state";

import { spaceManagerSelector } from "../../selectors/space-manager";

import { AbstractPlanetProps } from "./props";

const planetIdSelector = (_: AppState, props: AbstractPlanetProps) =>
  props.planetId;

const planetSelector = createCachedSelector(
  spaceManagerSelector,
  planetIdSelector,
  (spaceManager, planetId) => {
    if (!spaceManager) {
      return null;
    }

    const planet = find(spaceManager.destinations, x => x.id === planetId);
    return planet || null;
  }
)(planetIdSelector);

const mapStateToProps = createStructuredSelector({
  planet: planetSelector
});
github Brigad / redux-rest-easy / src / internals / selectors / generateResourceSelectors.js View on Github external
) => {
  const resource = resourceSelector(state, resourceName);

  if (resource) {
    return !(applyDenormalizer && denormalizer)
      ? `${!!(applyDenormalizer && denormalizer)}-${getResourceHash(
          state,
          resourceName,
        )}`
      : `${!!(applyDenormalizer && denormalizer)}-${getResourcesHash(state)}`;
  }

  return getEmptyResourceHash();
};

const getResource = createCachedSelector(
  resourcesSelector,
  resourceSelector,
  applyDenormalizerSelector,
  denormalizerSelector,
  getResourceSelector,
)(getResourceResolver, getReReselectOptions());

const getResourceById = (
  state,
  resourceName,
  resourceId,
  applyDenormalizer,
  denormalizer,
) => {
  const resource
    = state.resources
github RoboPhred / oni-duplicity / src / pages / SaveEditor / components / fields / connect-field / derived-state.tsx View on Github external
import createCachedSelector from "re-reselect";

import { get } from "lodash-es";

import { AppState } from "@/state";

import oniSave from "@/selectors/oni-save";

import { EditorFieldProps } from "./props";

const itemPathSelector = (_: AppState, props: EditorFieldProps) => props.path;

const cacheKeyGenerator = (_: AppState, props: EditorFieldProps) =>
  props.path.join(".");

const itemValue = createCachedSelector(
  itemPathSelector,
  oniSave,
  (path, oniSave) => {
    if (path.length === 0) {
      return oniSave;
    }
    return get(oniSave, path);
  }
)(cacheKeyGenerator);

function mapStateToProps(state: AppState, props: EditorFieldProps) {
  return {
    value: itemValue(state, props)
  };
}
export type StateProps = ReturnType;
github Brigad / redux-rest-easy / src / internals / selectors / generateActionSelectors.js View on Github external
)
          .map(
            resourceKey =>
              `${getPayloadIdsHash(
                state,
                normalizedURL,
                resourceKey,
              )}-${getResourceHash(state, resourceKey)}`,
          )
          .join('--')}`;
  }

  return getEmptyResourceHash();
};

const getRequestResource = createCachedSelector(
  resourcesSelector,
  resourceSelector,
  payloadIdsSelector,
  applyDenormalizerSelector,
  denormalizerSelector,
  getRequestResourceSelector,
)(getRequestResourceResolver, getReReselectOptions());

const getRequestMetadata = (state, normalizedURL) =>
  state.requests
  && state.requests[normalizedURL]
  && state.requests[normalizedURL].metadata
    ? state.requests[normalizedURL].metadata
    : {};

const isPerformingRequest = (state, normalizedURL) =>
github GuLinux / AstroPhoto-Plus / frontend / src / Settings / selectors.js View on Github external
export const getSettings = state => state.settings;
export const getCurrentSettings = state => getSettings(state).current;

export const getCurrentSetting = (state, {setting}) => get(getCurrentSettings(state), setting);

const getCommands = state => state.commands;

const getAstrometryIsDownloading = state => state.settings.astrometry.isDownloading;

export const getServerName = state => get(state, 'settings.current.server_name', '');
export const getAutoguiderEngine = state => get(state, 'settings.current.autoguider_engine', 'off');


const settingSelectorKey = (state, {setting}) => setting;
export const getSettingSelector = createCachedSelector(getCurrentSetting, (currentValue) => ({
    currentValue,
}))(settingSelectorKey);


export const getCheckboxSettingSelector = createCachedSelector(getCurrentSetting, (currentValue) => {
    const checked = (currentValue || 0) !== 0
    return { checked };
})(settingSelectorKey);

export const settingsSelector = createSelector([
    getSettings,
    getBackendVersion,
    getFrontendVersion,
    getCommands,
    getAstrometryIsDownloading,
    getCurrentCatalogs,

re-reselect

Enhance Reselect selectors with deeper memoization and cache management

MIT
Latest version published 9 months ago

Package Health Score

76 / 100
Full package analysis