Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
//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('.');
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,
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 }) => <p>{comment.body}</p>;
*
* // needed in order to have a unique selector per instance of the component
* const mapStateToProps = () => {
/**
* 是否需要当前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>) => {
return (settings: DataHocSettings = {
data: true
}) => {
/**
* 与reduce相关的数据操作
* 获取formItemData数据
* 获取formItemMeta数据
*/
const getItemDataHoc = (parentKeys: string[], rootReducerKey: string[], keys: Array) => {
/**
* 获取FormItemData的数据
* @param state 当前的state树
*/
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."
);
}
var getNotifyingSelectorCreator = function getNotifyingSelectorCreator() {
return reselect.createSelectorCreator(defaultMemoize);
};
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);
};
}
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(
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) => {
var getNotifyingSelectorCreator = function getNotifyingSelectorCreator() {
return createSelectorCreator(defaultMemoize);
};