How to use the reselect.defaultMemoize function in reselect

To help you get started, we’ve selected a few 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 vlsergey / WE-Framework / src / core / selectors.js View on Github external
import { createSelector, defaultMemoize } from 'reselect';
import { DEFAULT_LANGUAGES } from 'utils/I18nUtils';

const EMPTY_ARRAY = [];
const EMPTY_OBJECT = {};
const EMPTY_STRING = '';

const labelalikesFromEntity = entityElementName => entity => entity[ entityElementName ] || EMPTY_OBJECT;
const labelsFromEntity = labelalikesFromEntity( 'labels' );
const descriptionsFromEntity = labelalikesFromEntity( 'descriptions' );
const aliasesFromEntity = labelalikesFromEntity( 'aliases' );

/* 3 different instances of the same thing -- since cache size is 1 */
const allLanguagesFromLabels = defaultMemoize( labelalike => Object.keys( labelalike ) );
const allLanguagesFromDescriptions = defaultMemoize( labelalike => Object.keys( labelalike ) );
const allLanguagesFromAliases = defaultMemoize( labelalike => Object.keys( labelalike ) );

export const listLabelalikeLanguages = createSelector(
  entity => allLanguagesFromLabels( labelsFromEntity( entity ) ),
  entity => allLanguagesFromDescriptions( labelsFromEntity( entity ) ),
  entity => allLanguagesFromAliases( labelsFromEntity( entity ) ),
  ( fromLabels, fromDescriptions, fromAliases ) => {
    const result = [ ...DEFAULT_LANGUAGES ];

    const languages = new Set();
    fromLabels.forEach( langCode => languages.add( langCode ) );
    fromDescriptions.forEach( langCode => languages.add( langCode ) );
    fromAliases.forEach( langCode => languages.add( langCode ) );

    // remove DEFAULT_LANGUAGES from set
    result.forEach( langCode => languages.delete( langCode ) );
    const sorted = Array.from( languages );
github envkey / envkey-app / envkey-react / src / lib / env / query.js View on Github external
R.flatten,
    R.uniq,
    R.sort(R.ascend(R.identity))
  )),

  allEntries = defaultMemoize(R.pipe(
    // R.filter(R.complement(R.prop("@@__hidden__"))),
    allKeys,
    R.filter(k => k.indexOf("@@__") != 0)
  )),

  subEnvEntries = (envsWithMeta, subEnvId)=> allEntries({
    [subEnvId]: findSubEnv(subEnvId, envsWithMeta)
  }),

  allSubEnvsSorted = defaultMemoize(R.pipe(
    R.values,
    R.map(R.pipe(
      R.propOr({},"@@__sub__"),
      R.keys
    )),
    R.flatten,
    R.uniq,
    R.sort(R.ascend(R.identity))
  )),

  allEntriesWithSubEnvs = defaultMemoize(envsWithMeta => {
    return R.pipe(
      allSubEnvsSorted,
      R.pipe(
        R.map(subEnvId => (findSubEnv(subEnvId, envsWithMeta))),
        allEntries
github neos / neos-ui / packages / neos-ui-redux-store / src / CR / NodeTypes / index.js View on Github external
constraints: Immutable.fromJS($get('cr.nodeTypes.constraints', state)),
            inheritanceMap: Immutable.fromJS($get('cr.nodeTypes.inheritanceMap', state)),
            groups: Immutable.fromJS($get('cr.nodeTypes.groups', state))
        })
    )
});

//
// selectors
//

const byNameSelector = state => name => $get(['cr', 'nodeTypes', 'byName', name], state);

const subTypesSelector = name => $get(['cr', 'nodeTypes', 'inheritanceMap', 'subTypes', name]);

const isOfTypeSelector = defaultMemoize(
    superTypeName => subTypeName => createSelector(
        [
            subTypesSelector(superTypeName)
        ],
        subTypes => subTypes.indexOf(subTypeName) !== -1
    )
);

//
// Export the selectors
//
export const selectors = {
    byNameSelector,
    subTypesSelector,
    isOfTypeSelector
};
github vlsergey / WE-Framework / src / core / selectors.js View on Github external
const languages = new Set();
    fromLabels.forEach( langCode => languages.add( langCode ) );
    fromDescriptions.forEach( langCode => languages.add( langCode ) );
    fromAliases.forEach( langCode => languages.add( langCode ) );

    // remove DEFAULT_LANGUAGES from set
    result.forEach( langCode => languages.delete( langCode ) );
    const sorted = Array.from( languages );
    sorted.sort();

    sorted.forEach( langCode => result.push( langCode ) );
    return result;
  } );

export const labelFromEntityByLanguage = defaultMemoize( ( entity, language ) => {
  const allLanguages = labelsFromEntity( entity ) || EMPTY_OBJECT;
  return allLanguages[ language ] || EMPTY_OBJECT;
} );
export const labelValue = labelObject => ( labelObject || EMPTY_OBJECT ).value || EMPTY_STRING;

export const descriptionFromEntityByLanguage = defaultMemoize( ( entity, language ) => {
  const allLanguages = descriptionsFromEntity( entity ) || EMPTY_OBJECT;
  return allLanguages[ language ] || EMPTY_OBJECT;
} );
export const descriptionValue = labelObject => ( labelObject || EMPTY_OBJECT ).value || EMPTY_STRING;

export const aliasesFromEntityByLanguage = defaultMemoize( ( entity, language ) => {
  const allLanguages = aliasesFromEntity( entity ) || EMPTY_OBJECT;
  return allLanguages[ language ] || EMPTY_ARRAY;
} );
export const aliasValues = createSelector(
github BetConstruct / spring-front-end-mobile / dev / mobile / containers / prematchCompetitions / index.js View on Github external
const PrematchCompetitions = React.createClass({
    propTypes: {
        selectedSportAlias: PropTypes.string.isRequired,
        timeFilter: PropTypes.number
    },
    render () {
        console.info("rendering preMatch regions list");
        return Template.apply(this); //eslint-disable-line no-undef
    },
    shouldComponentUpdate (nextProps) {
        let currentProps = this.props;
        return nextProps.data.region.length !== currentProps.data.region.length || currentProps.swarmDataKey !== nextProps.swarmDataKey;
    }
});

let createSwarmDataKeySelector = defaultMemoize((sportAlias, timeFilter) => () => getSwarmDataKeyForRequest(getSwarmSubscriptionRequest(sportAlias, timeFilter, true))),
    selectorInstance = {};

/**
 * @name getSelector
 * @description Get prematch selector
 * @param {String} key
 * @return {Function}
 */
function getSelector (key) {
    selectorInstance.key !== key && (selectorInstance.selector = GetCompetitionsDataSelector(key));
    return selectorInstance.selector;
}

function mapStateToProps (state, ownParams) {
    let keySelector = createSwarmDataKeySelector(ownParams.selectedSportAlias, ownParams.timeFilter);
    return {
github vlsergey / WE-Framework / src / components / references / ClaimReferencesEditorContent.js View on Github external
constructor() {
    super( ...arguments );

    this.memoizeLruKeys = defaultMemoize( lru => lru.map( item => item.key ) );

    this.handleReferenceAdd = this.handleReferenceAdd.bind( this );
    this.handleReferenceChange = this.handleReferenceChange.bind( this );

    this.state = {
      lru: getLastRecentlyUsedReferences(),
    };
  }
github vlsergey / WE-Framework / src / core / selectors.js View on Github external
return result;
  } );

export const labelFromEntityByLanguage = defaultMemoize( ( entity, language ) => {
  const allLanguages = labelsFromEntity( entity ) || EMPTY_OBJECT;
  return allLanguages[ language ] || EMPTY_OBJECT;
} );
export const labelValue = labelObject => ( labelObject || EMPTY_OBJECT ).value || EMPTY_STRING;

export const descriptionFromEntityByLanguage = defaultMemoize( ( entity, language ) => {
  const allLanguages = descriptionsFromEntity( entity ) || EMPTY_OBJECT;
  return allLanguages[ language ] || EMPTY_OBJECT;
} );
export const descriptionValue = labelObject => ( labelObject || EMPTY_OBJECT ).value || EMPTY_STRING;

export const aliasesFromEntityByLanguage = defaultMemoize( ( entity, language ) => {
  const allLanguages = aliasesFromEntity( entity ) || EMPTY_OBJECT;
  return allLanguages[ language ] || EMPTY_ARRAY;
} );
export const aliasValues = createSelector(
  aliasObjects => aliasObjects || EMPTY_ARRAY,
  aliasObjects => aliasObjects.map( alias => alias.value )
);
github envkey / envkey-app / envkey-react / src / lib / env / query.js View on Github external
R.map(role => ({
        [role]: R.sortBy(
          R.pipe(R.prop('name'), R.toLower),
          allSubEnvsSorted(R.pick([role], (envsWithMeta || {}))).map(
            subEnvId => {
              const {"@@__name__": name} = findSubEnv(subEnvId, envsWithMeta)
              return {name, id: subEnvId}
            }
          )
        )
      })),
      R.mergeAll
    )(["development", "staging", "production"])
  }),

  hasAnyVal = defaultMemoize(R.pipe(
    R.values,
    R.map(R.values),
    R.flatten,
    R.filter(R.identity),
    R.any(R.prop('val'))
  )),

  subEnvPath = (subEnvId, envsWithMeta)=>{
    for (let environment in envsWithMeta){
      let path = [environment, "@@__sub__", subEnvId]
      if (R.path(path, envsWithMeta)){
        return path
      }
    }
    return []
  },
github envkey / envkey-app / envkey-react / src / selectors / env_selectors.js View on Github external
getEnvUpdateId = R.curry((id, state) => {
    return db.path("envUpdateId", id)(state)
  }),

  getSelectedParentEnvUpdateId = state =>{
    return getEnvUpdateId(getSelectedObjectId(state), state)
  },

  getLastAddedEntry = (parentId, state)=> db.path("lastAddedEntry", parentId)(state),

  getAppEnvironmentsAccessible = db.path("appEnvironmentsAccessible"),

  getAppEnvironmentsAssignable = db.path("appEnvironmentsAssignable"),

  getEnvsWithMetaWithPending = defaultMemoize(R.curry((parentType, parentId, state)=>{
    const parent = getObject(parentType, parentId, state),
          pendingActions = getAllEnvActionsPending(parentId, state)

    return pendingActions.reduce(transformEnv, parent.envsWithMeta)
  })),

  getEnvsWithMetaWithPendingWithImports = defaultMemoize(R.curry((parentType, parentId, state)=>{
    const envsWithMeta = getEnvsWithMetaWithPending(parentType, parentId, state),
          pendingActions = getImportActionsPending(parentId, state)

    return pendingActions.reduce(transformEnv, envsWithMeta)
  })),

  getHasPendingEnvsWithMeta = R.curry((id, state)=> {
    return Boolean(R.path(["envsPending", id], state))
  }),
github Emurgo / yoroi-mobile / src / crypto / chain.js View on Github external
type AsyncAddressFilter = (addresses: Array) => Promise>

type Addresses = Array

const _addressToIdxSelector = (addresses: Array) =>
  _.fromPairs(addresses.map((addr, i) => [addr, i]))

export class AddressChain {
  _addresses: Addresses = []
  _addressGenerator: AddressGenerator
  _blockSize: number
  _gapLimit: number
  _isInitialized: boolean = false
  _subscriptions: Array<(Addresses) => mixed> = []
  _addressToIdxSelector: (Addresses) => Dict = defaultMemoize(
    _addressToIdxSelector,
  )

  constructor(
    addressGenerator: AddressGenerator,
    blockSize: number = CONFIG.WALLET.DISCOVERY_BLOCK_SIZE,
    gapLimit: number = CONFIG.WALLET.DISCOVERY_GAP_SIZE,
  ) {
    assert.assert(blockSize > gapLimit, 'Block size needs to be > gap limit')

    this._addressGenerator = addressGenerator
    this._blockSize = blockSize
    this._gapLimit = gapLimit
  }

  toJSON() {