How to use the reselect.createSelector 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 Kaniwani / kw-frontend / app / features / user / selectors.js View on Github external
'kanjiSvgDrawSpeed',
    ])
  )
);

export const selectUsername = createSelector(selectUserProfile, getBy('name'));
export const selectApiKey = createSelector(selectUserProfile, getBy('apiKey'));
export const selectUserLevel = createSelector(selectUserProfile, getBy('level', Number));
export const selectOnVacation = createSelector(selectUserProfile, getBy('onVacation', Boolean));

export const selectVacationDate = createSelector(
  selectUserProfile,
  getBy('vacationDate', dateOrFalse)
);

export const selectNextReviewDate = createSelector(
  selectUserProfile,
  // padded with 30 second safety net to ensure server is completely updated when we request new review count
  getBy('nextReviewDate', (date) => (date != null ? addSeconds(date, 30) : false))
);

export const selectFreshUser = createSelector(
  [
    selectNextReviewDate,
    selectLessonsCount,
    selectReviewsCount,
    getBy(['entities', 'reviews'], (x = {}) => Object.keys(x).length),
  ],
  (nextReviewDate, lessonsCount, reviewsCount, reviewEntitiesCount) => !nextReviewDate && lessonsCount && !reviewsCount && !reviewEntitiesCount
);

export const selectLastWkSyncDate = createSelector(
github eoscannon / eoscannon-online-tool / app / containers / LanguageProvider / selectors.js View on Github external
const makeSelectLocale = () =>
  createSelector(selectLanguage, languageState => languageState.get('locale'));
github nypl-spacetime / surveyor / app / containers / Menu / index.js View on Github external
toggleDropdown (event) {
    const shiftKey = event.nativeEvent && event.nativeEvent.shiftKey
    this.setState({
      showDropdown: !this.state.showDropdown,
      shiftKey
    })
  }
}

function mapDispatchToProps (dispatch) {
  return {
    logOut: () => dispatch(logOut())
  }
}

export default connect(createSelector(
  selectLoading(),
  selectOAuth(),
  selectSubmissions(),
  (loading, oauth, submissions) => ({
    loading, oauth, submissions
  })
), mapDispatchToProps)(Menu)
github Vizzuality / gfw / app / javascript / components / widgets-v2 / widgets / forest-change / fires-alerts / selectors.js View on Github external
});

export const getStdDev = createSelector(
  [getMeans, getData],
  (data, rawData) => {
    if (!data) return null;
    return getStdDevData(data, rawData);
  }
);

export const getDates = createSelector([getStdDev], data => {
  if (!data) return null;
  return getDatesData(data);
});

export const parseData = createSelector([getDates, getWeeks], (data, weeks) => {
  if (!data) return null;
  return data.slice(-weeks);
});

export const parseConfig = createSelector([getColors], colors =>
  getChartConfig(
    colors,
    moment()
      .subtract(2, 'w')
      .format('YYYY-MM-DD')
  )
);

export const parseSentence = createSelector(
  [parseData, getColors, getActiveData, getSentences, getDataset],
  (data, colors, activeData, sentence, dataset) => {
github shopgate / pwa / libraries / commerce / reviews / selectors / index.js View on Github external
export const getReviewsTotalCount = createSelector(
  getCollectionForCurrentBaseProduct,
  (collection) => {
    if (!collection || !collection.hasOwnProperty('totalReviewCount')) {
      return null;
    }

    return collection.totalReviewCount;
  }
);
/**
 * Retrieves the total number of currently fetched reviews for a current product.
 * @param {Object} state The current application state.
 * @return {number|null} The current number of fetched reviews.
 */
export const getCurrentReviewCount = createSelector(
  getCollectionForCurrentBaseProduct,
  (collection) => {
    if (!collection || !collection.reviews) {
      return null;
    }

    return collection.reviews.length;
  }
);

/**
 * Retrieves the information if reviews are currently fetched.
 * @param {Object} state The current application state.
 * @return {bool} The boolean information if reviews are currently being fetched.
 */
export const getReviewsFetchingState = createSelector(
github elastic / kibana / x-pack / legacy / plugins / graph / public / state_management / fields.ts View on Github external
return newFieldMap;
  })
  .case(updateFieldProperties, (fields, { fieldName, fieldProperties }) => {
    return { ...fields, [fieldName]: { ...fields[fieldName], ...fieldProperties } };
  })
  .case(selectField, (fields, fieldName) => {
    return { ...fields, [fieldName]: { ...fields[fieldName], selected: true } };
  })
  .case(deselectField, (fields, fieldName) => {
    return { ...fields, [fieldName]: { ...fields[fieldName], selected: false } };
  })
  .build();

export const fieldMapSelector = (state: GraphState) => state.fields;
export const fieldsSelector = createSelector(
  fieldMapSelector,
  fields => Object.values(fields)
);
export const selectedFieldsSelector = createSelector(
  fieldsSelector,
  fields => fields.filter(field => field.selected)
);
export const liveResponseFieldsSelector = createSelector(
  selectedFieldsSelector,
  fields => fields.filter(field => field.hopSize && field.hopSize > 0)
);
export const hasFieldsSelector = createSelector(
  selectedFieldsSelector,
  fields => fields.length > 0
);
github resource-watch / resource-watch / components / collection-list-aside / collection-list-aside-selector.js View on Github external
import { createSelector } from 'reselect';

const getCollections = state => state.user.collections.items;
const getTab = state => state.routes.query.tab;

const parseTabCollections = (collections, tab) =>
  collections.map(collection => ({
    id: collection.id,
    label: collection.attributes.name,
    value: collection.id,
    route: 'myrw',
    params: { tab, subtab: collection.id }
  }));

export const getParsedCollections = createSelector([getCollections, getTab], parseTabCollections);

export default { getParsedCollections };
github pluto-net / scinapse-web-client / app / selectors / getConfiguration.tsx View on Github external
import { createSelector } from 'reselect';
import { AppState } from '../reducers';

export const getMemoizedConfiguration = createSelector([(state: AppState) => state.configuration], configuration => {
  return configuration;
});
github OasisDEX / oasis-react / src / store / selectors / offers.js View on Github external
const canOfferBeCancelled = createSelector(
  (rootState, offerId) => {
    if (offerId) {
      const foundOffer = findOffer(offerId, rootState);
      if (foundOffer && foundOffer.offer && foundOffer.offer.status !== OFFER_STATUS_INACTIVE) {
        return foundOffer.offer.owner.toString() === accounts.defaultAccount(rootState).toString();
      } else {
        return false;
      }
    }
  },
  canCancel => Boolean(canCancel)
);

const reSyncOffersSet = createSelector(
  offers,
  s => s.get('reSyncOffersSet')
);

export default {
  state: offers,
  offersInitialized,
  loadingBuyOffers,
  loadingSellOffers,
  activeTradingPairBuyOffers,
  activeTradingPairSellOffers,
  activeTradingPairBuyOfferCount,
  activeTradingPairSellOfferCount,
  activeTradingPairOffersInitialLoadPending,
  activeTradingPairOffersInitiallyLoaded,
  activeTradingPairOffersInitialLoadStatus,
github PulseTile / PulseTile-React-Core / src / components / containers / Main / selectors.js View on Github external
import { createSelector } from 'reselect';
import _ from 'lodash/fp';

const sidebarVisibilitySelector = ({ isSidebarVisible }) => isSidebarVisible;
const userAccountSelector = ({ userAccount }) => userAccount;

const sidebarAndUserSelector = createSelector(
  sidebarVisibilitySelector,
  userAccountSelector,
  (isSidebarVisible, userAccount) => ({ isSidebarVisible, userAccount })
);

const mainSelector = createSelector(
  ({ patientsSummaries }) => patientsSummaries,
  (state, props) => _.getOr(null, 'match.params.userId', props),
  (patientSummeriesParams) => {
    return ({ patientSummeriesParams })
  }
);

export { sidebarAndUserSelector, mainSelector };