How to use the reselect.createSelectorCreator 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 mattermost / mattermost-redux / src / utils / helpers.ts View on Github external
//eslint-disable-line prefer-rest-params
            // apply arguments instead of spreading for performance.
            const result = Reflect.apply(func, null, arguments); //eslint-disable-line prefer-rest-params
            if (!shallowEqual(lastResult, result)) {
                lastResult = result;
            }
        }

        lastArgs = arguments; //eslint-disable-line prefer-rest-params
        return lastResult;
    };
}

// Use this selector when you want a shallow comparison of the arguments and you want to memoize the result
// try and use this only when your selector returns an array of ids
export const createIdsSelector = reselect.createSelectorCreator(memoizeResult);

// Use this selector when you want a shallow comparison of the arguments and you don't need to memoize the result
export const createShallowSelector = reselect.createSelectorCreator(reselect.defaultMemoize, shallowEqual as any);

// isMinimumServerVersion will return true if currentVersion is equal to higher or than the
// the provided minimum version. A non-equal major version will ignore minor and dot
// versions, and a non-equal minor version will ignore dot version.
// currentVersion is a string, e.g '4.6.0'
// minMajorVersion, minMinorVersion, minDotVersion are integers
export const isMinimumServerVersion = (currentVersion: string, minMajorVersion = 0, minMinorVersion = 0, minDotVersion = 0): boolean => {
    if (!currentVersion || typeof currentVersion !== 'string') {
        return false;
    }

    const split = currentVersion.split('.');
github Kaniwani / kw-frontend / app / common / oldSelectors.js View on Github external
import { createSelectorCreator, defaultMemoize } from "reselect";
import { isFinite, isEqual } from "lodash";
import { titleCase } from "voca";

import { SRS_RANKS } from 'common/constants';

import groupByRank from 'common/utils/groupByRank';
import dateOrFalse from 'common/utils/dateOrFalse';
import getSrsRankName from 'common/utils/getSrsRankName';
import filterRomajiReadings from 'common/utils/filterRomajiReadings';
import formatSrsCounts from 'common/utils/formatSrsCounts';
import formatUpcomingReviews from 'common/utils/formatUpcomingReviews';

// create a "selector creator" that uses lodash.isEqual instead of a shallow ===
export const createDeepEqualSelector = createSelectorCreator(defaultMemoize, isEqual);

export const selectIdFromMatch = (props) => +props.match.params.id;
export const selectCategoryFromMatch = (props) => props.match.params.category;
export const selectEntities = (state) => state.entities;
export const selectUi = (state) => state.ui;

export const selectUser = (state) => state.user;
export const selectProfile = createDeepEqualSelector(selectUser, (user) => {
  if (!user || !user.profile) {
    return {};
  }
  const { profile } = user;
  return {
    id: profile.id,
    name: profile.name,
    apiKey: profile.apiKey,
github coverhound / active-redux / src / query / utils.js View on Github external
import qs from 'qs';
import { createSelectorCreator, defaultMemoize } from 'reselect';

const isEqual = (a, b) => (
  typeof a === 'string' ?
    a === b :
    JSON.stringify(a) === JSON.stringify(b)
);

const createDeepEqualSelector = createSelectorCreator(
  defaultMemoize,
  isEqual,
);

/**
 * @alias module:active-redux.createQuerySelector
 * @function
 * @example
 *
 * import { createQuerySelector } from 'active-redux';
 * import { Comment } from '@models';
 *
 * const Comment = ({ comment }) =&gt; <p>{comment.body}</p>;
 *
 * // needed in order to have a unique selector per instance of the component
 * const mapStateToProps = () =&gt; {
github nick121212 / fx-schema-form / packages / fx-schema-form-react / src / hocs / data.tsx View on Github external
/**
     * 是否需要当前key对应的meta数据
     */
    meta?: boolean;
    /**
     * 设置当前key下所需要的meta的key值
     */
    metaKeys?: string[];
    /**
     * 是否获取meta的根节点
     */
    treeNode?: boolean;
}

// 自定义选择器创建函数
const fxSelectorCreator: any = createSelectorCreator(defaultMemoize, is);

export const name = "data";
export const hoc = (hocFactory: BaseFactory&gt;) =&gt; {
    return (settings: DataHocSettings = {
        data: true
    }) =&gt; {
        /**
         * 与reduce相关的数据操作
         * 获取formItemData数据
         * 获取formItemMeta数据
         */
        const getItemDataHoc = (parentKeys: string[], rootReducerKey: string[], keys: Array) =&gt; {
            /**
             * 获取FormItemData的数据
             * @param state 当前的state树
             */
github redux-orm / redux-orm / src / redux.js View on Github external
throw new Error(
                "Failed to resolve the current ORM database state. Please pass an ORM instance or an ORM selector as an argument to `createSelector()`."
            );
        } else if (!orm.stateSelector) {
            throw new Error(
                "Failed to resolve the current ORM database state. Please pass an object to the ORM constructor that specifies a `stateSelector` function."
            );
        } else if (typeof orm.stateSelector !== "function") {
            throw new Error(
                `Failed to resolve the current ORM database state. Please pass a function when specifying the ORM's \`stateSelector\`. Received: ${JSON.stringify(
                    orm.stateSelector
                )} of type ${typeof orm.stateSelector}`
            );
        }

        return createSelectorCreator(
            memoize,
            undefined,
            orm
        )([orm.stateSelector, ...inputFuncs], resultArg);
    }

    if (resultArg instanceof ORM) {
        throw new Error(
            "ORM instances cannot be the result function of selectors. You can access your models in the last function that you pass to `createSelector()`."
        );
    }
    if (inputFuncs.length) {
        console.warn(
            "Your input selectors will be ignored: the passed result function does not require any input."
        );
    }
github aGuyNamedJonas / slim-redux-react / dist / index.js View on Github external
var getNotifyingSelectorCreator = function getNotifyingSelectorCreator() {
  return reselect.createSelectorCreator(defaultMemoize);
};
github apache / incubator-annotator / packages / selector / index.js View on Github external
export function createSelectorCreator(memoize, ...memoizeOptions) {
  const createSelector = _createSelectorCreator(memoize, ...memoizeOptions);
  return (...funcs) => {
    const resultFunc = funcs.pop();
    const wrapperFunc = (...args) => {
      const iterable = resultFunc(...args);
      return new AsyncTee(iterable);
    };
    funcs.push(wrapperFunc);
    return createSelector(identity, ...funcs);
  };
}
github joker1007 / blackalbum / src / selectors.js View on Github external
return files.sortBy(f => {return f.ctime}).reverse();
    case RANDOM_ORDER:
      return files.sortBy(f => {return Math.random()});
  }
};


let equalityCheck = (a, b) => {
  if (a && typeof a.equals == "function") {
    return a.equals(b);
  } else {
    return a === b;
  }
};

const createSelector = createSelectorCreator(
  defaultMemoize,
  equalityCheck
);

export const visibleFilesSelector = createSelector(
  filesSelector,
  searchKeywordSelector,
  (files, searchKeyword) => (
    {
      files: visibleFiles(files, searchKeyword),
      searchKeyword: searchKeyword,
    }
  )
);

export const sortFilesSelector = createSelector(
github alphasp / pxview / src / common / selectors / index.js View on Github external
const createUserDetailItemSelector = createSelectorCreator(
  specialMemoize,
  (prev, next) => {
    if (!prev || !next) {
      return false;
    }
    return (
      prev.id === next.id &&
      (prev.user && prev.user.is_followed) ===
        (next.user && next.user.is_followed)
    );
  },
);

const createMuteUserItemsSelector = createSelectorCreator(
  specialMemoize,
  (prev, next) => {
    if (!prev && !next) {
      return false;
    }
    return equals(
      prev,
      next,
      (p, n) => p.id === n.id && p.is_followed === n.is_followed,
    );
  },
);

const createTagItemsSelector = createSelectorCreator(
  specialMemoize,
  (prev, next) => {
github aGuyNamedJonas / slim-redux-react / dist / index.es.js View on Github external
var getNotifyingSelectorCreator = function getNotifyingSelectorCreator() {
  return createSelectorCreator(defaultMemoize);
};