Socket
Socket
Sign inDemoInstall

re-reselect

Package Overview
Dependencies
1
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 3.2.0

src/cache/README.md

6

CHANGELOG.md
# Change log
## 3.2.0
### New Features
- Add `createStructuredCachedSelector`
## 3.1.0

@@ -4,0 +10,0 @@

187

dist/index.js

@@ -43,2 +43,93 @@ (function (global, factory) {

var defaultCacheCreator = FlatObjectCache;
var defaultCacheKeyValidator = function defaultCacheKeyValidator() {
return true;
};
function createCachedSelector() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function (keySelector, options) {
if (options === void 0) {
options = {};
}
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error('[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.');
} // https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
var recomputations = 0;
var resultFunc = funcs.pop();
var dependencies = Array.isArray(funcs[0]) ? funcs[0] : [].concat(funcs);
var resultFuncWithRecomputations = function resultFuncWithRecomputations() {
recomputations++;
return resultFunc.apply(void 0, arguments);
};
funcs.push(resultFuncWithRecomputations);
var cache = options.cacheObject || new defaultCacheCreator();
var selectorCreator = options.selectorCreator || reselect.createSelector;
var isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator; // Application receives this function
var selector = function selector() {
var cacheKey = keySelector.apply(void 0, arguments);
if (isValidCacheKey(cacheKey)) {
var cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator.apply(void 0, funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse.apply(void 0, arguments);
}
console.warn("[re-reselect] Invalid cache key \"" + cacheKey + "\" has been returned by keySelector function.");
return undefined;
}; // Further selector methods
selector.getMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments); // @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments);
cache.remove(cacheKey);
};
selector.clearCache = function () {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = function () {
return recomputations;
};
selector.resetRecomputations = function () {
return recomputations = 0;
};
selector.keySelector = keySelector;
return selector;
};
}
function createStructuredCachedSelector(selectors) {
return reselect.createStructuredSelector(selectors, createCachedSelector);
}
function validateCacheSize(cacheSize) {

@@ -188,3 +279,3 @@ if (cacheSize === undefined) {

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -228,3 +319,3 @@

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -277,3 +368,3 @@

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -288,92 +379,5 @@

var defaultCacheCreator = FlatObjectCache;
var defaultCacheKeyValidator = function defaultCacheKeyValidator() {
return true;
};
function createCachedSelector() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function (keySelector, options) {
if (options === void 0) {
options = {};
}
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error('[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.');
} // https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
var recomputations = 0;
var resultFunc = funcs.pop();
var dependencies = Array.isArray(funcs[0]) ? funcs[0] : funcs.concat();
var resultFuncWithRecomputations = function resultFuncWithRecomputations() {
recomputations++;
return resultFunc.apply(void 0, arguments);
};
funcs.push(resultFuncWithRecomputations);
var cache = options.cacheObject || new defaultCacheCreator();
var selectorCreator = options.selectorCreator || reselect.createSelector;
var isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator; // Application receives this function
var selector = function selector() {
var cacheKey = keySelector.apply(void 0, arguments);
if (isValidCacheKey(cacheKey)) {
var cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator.apply(void 0, funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse.apply(void 0, arguments);
}
console.warn("[re-reselect] Invalid cache key \"" + cacheKey + "\" has been returned by keySelector function.");
return undefined;
}; // Further selector methods
selector.getMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments); // @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments);
cache.remove(cacheKey);
};
selector.clearCache = function () {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = function () {
return recomputations;
};
selector.resetRecomputations = function () {
return recomputations = 0;
};
selector.keySelector = keySelector;
return selector;
};
}
exports.default = createCachedSelector;
exports.createStructuredCachedSelector = createStructuredCachedSelector;
exports.FlatObjectCache = FlatObjectCache;
exports.FlatCacheObject = FlatObjectCache;
exports.FifoObjectCache = FifoObjectCache;

@@ -384,2 +388,3 @@ exports.LruObjectCache = LruObjectCache;

exports.LruMapCache = LruMapCache;
exports.FlatCacheObject = FlatObjectCache;
exports.FifoCacheObject = FifoObjectCache;

@@ -386,0 +391,0 @@ exports.LruCacheObject = LruMapCache;

@@ -1,2 +0,2 @@

import { createSelector } from 'reselect';
import { createSelector, createStructuredSelector } from 'reselect';

@@ -39,2 +39,93 @@ function isStringOrNumber(value) {

var defaultCacheCreator = FlatObjectCache;
var defaultCacheKeyValidator = function defaultCacheKeyValidator() {
return true;
};
function createCachedSelector() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function (keySelector, options) {
if (options === void 0) {
options = {};
}
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error('[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.');
} // https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
var recomputations = 0;
var resultFunc = funcs.pop();
var dependencies = Array.isArray(funcs[0]) ? funcs[0] : [].concat(funcs);
var resultFuncWithRecomputations = function resultFuncWithRecomputations() {
recomputations++;
return resultFunc.apply(void 0, arguments);
};
funcs.push(resultFuncWithRecomputations);
var cache = options.cacheObject || new defaultCacheCreator();
var selectorCreator = options.selectorCreator || createSelector;
var isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator; // Application receives this function
var selector = function selector() {
var cacheKey = keySelector.apply(void 0, arguments);
if (isValidCacheKey(cacheKey)) {
var cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator.apply(void 0, funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse.apply(void 0, arguments);
}
console.warn("[re-reselect] Invalid cache key \"" + cacheKey + "\" has been returned by keySelector function.");
return undefined;
}; // Further selector methods
selector.getMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments); // @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments);
cache.remove(cacheKey);
};
selector.clearCache = function () {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = function () {
return recomputations;
};
selector.resetRecomputations = function () {
return recomputations = 0;
};
selector.keySelector = keySelector;
return selector;
};
}
function createStructuredCachedSelector(selectors) {
return createStructuredSelector(selectors, createCachedSelector);
}
function validateCacheSize(cacheSize) {

@@ -184,3 +275,3 @@ if (cacheSize === undefined) {

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -224,3 +315,3 @@

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -273,3 +364,3 @@

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -284,91 +375,4 @@

var defaultCacheCreator = FlatObjectCache;
var defaultCacheKeyValidator = function defaultCacheKeyValidator() {
return true;
};
function createCachedSelector() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function (keySelector, options) {
if (options === void 0) {
options = {};
}
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error('[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.');
} // https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
var recomputations = 0;
var resultFunc = funcs.pop();
var dependencies = Array.isArray(funcs[0]) ? funcs[0] : funcs.concat();
var resultFuncWithRecomputations = function resultFuncWithRecomputations() {
recomputations++;
return resultFunc.apply(void 0, arguments);
};
funcs.push(resultFuncWithRecomputations);
var cache = options.cacheObject || new defaultCacheCreator();
var selectorCreator = options.selectorCreator || createSelector;
var isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator; // Application receives this function
var selector = function selector() {
var cacheKey = keySelector.apply(void 0, arguments);
if (isValidCacheKey(cacheKey)) {
var cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator.apply(void 0, funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse.apply(void 0, arguments);
}
console.warn("[re-reselect] Invalid cache key \"" + cacheKey + "\" has been returned by keySelector function.");
return undefined;
}; // Further selector methods
selector.getMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments); // @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments);
cache.remove(cacheKey);
};
selector.clearCache = function () {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = function () {
return recomputations;
};
selector.resetRecomputations = function () {
return recomputations = 0;
};
selector.keySelector = keySelector;
return selector;
};
}
export default createCachedSelector;
export { FlatObjectCache, FlatObjectCache as FlatCacheObject, FifoObjectCache, LruObjectCache, FlatMapCache, FifoMapCache, LruMapCache, FifoObjectCache as FifoCacheObject, LruMapCache as LruCacheObject };
export { createStructuredCachedSelector, FlatObjectCache, FifoObjectCache, LruObjectCache, FlatMapCache, FifoMapCache, LruMapCache, FlatObjectCache as FlatCacheObject, FifoObjectCache as FifoCacheObject, LruMapCache as LruCacheObject };
//# sourceMappingURL=index.js.map

@@ -43,2 +43,93 @@ 'use strict';

var defaultCacheCreator = FlatObjectCache;
var defaultCacheKeyValidator = function defaultCacheKeyValidator() {
return true;
};
function createCachedSelector() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function (keySelector, options) {
if (options === void 0) {
options = {};
}
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error('[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.');
} // https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
var recomputations = 0;
var resultFunc = funcs.pop();
var dependencies = Array.isArray(funcs[0]) ? funcs[0] : [].concat(funcs);
var resultFuncWithRecomputations = function resultFuncWithRecomputations() {
recomputations++;
return resultFunc.apply(void 0, arguments);
};
funcs.push(resultFuncWithRecomputations);
var cache = options.cacheObject || new defaultCacheCreator();
var selectorCreator = options.selectorCreator || reselect.createSelector;
var isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator; // Application receives this function
var selector = function selector() {
var cacheKey = keySelector.apply(void 0, arguments);
if (isValidCacheKey(cacheKey)) {
var cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator.apply(void 0, funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse.apply(void 0, arguments);
}
console.warn("[re-reselect] Invalid cache key \"" + cacheKey + "\" has been returned by keySelector function.");
return undefined;
}; // Further selector methods
selector.getMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments); // @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments);
cache.remove(cacheKey);
};
selector.clearCache = function () {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = function () {
return recomputations;
};
selector.resetRecomputations = function () {
return recomputations = 0;
};
selector.keySelector = keySelector;
return selector;
};
}
function createStructuredCachedSelector(selectors) {
return reselect.createStructuredSelector(selectors, createCachedSelector);
}
function validateCacheSize(cacheSize) {

@@ -188,3 +279,3 @@ if (cacheSize === undefined) {

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -228,3 +319,3 @@

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -277,3 +368,3 @@

_proto.remove = function remove(key) {
this._cache.delete(key);
this._cache["delete"](key);
};

@@ -288,92 +379,5 @@

var defaultCacheCreator = FlatObjectCache;
var defaultCacheKeyValidator = function defaultCacheKeyValidator() {
return true;
};
function createCachedSelector() {
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
funcs[_key] = arguments[_key];
}
return function (keySelector, options) {
if (options === void 0) {
options = {};
}
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error('[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.');
} // https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
var recomputations = 0;
var resultFunc = funcs.pop();
var dependencies = Array.isArray(funcs[0]) ? funcs[0] : funcs.concat();
var resultFuncWithRecomputations = function resultFuncWithRecomputations() {
recomputations++;
return resultFunc.apply(void 0, arguments);
};
funcs.push(resultFuncWithRecomputations);
var cache = options.cacheObject || new defaultCacheCreator();
var selectorCreator = options.selectorCreator || reselect.createSelector;
var isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator; // Application receives this function
var selector = function selector() {
var cacheKey = keySelector.apply(void 0, arguments);
if (isValidCacheKey(cacheKey)) {
var cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator.apply(void 0, funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse.apply(void 0, arguments);
}
console.warn("[re-reselect] Invalid cache key \"" + cacheKey + "\" has been returned by keySelector function.");
return undefined;
}; // Further selector methods
selector.getMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments); // @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = function () {
var cacheKey = keySelector.apply(void 0, arguments);
cache.remove(cacheKey);
};
selector.clearCache = function () {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = function () {
return recomputations;
};
selector.resetRecomputations = function () {
return recomputations = 0;
};
selector.keySelector = keySelector;
return selector;
};
}
exports.default = createCachedSelector;
exports.createStructuredCachedSelector = createStructuredCachedSelector;
exports.FlatObjectCache = FlatObjectCache;
exports.FlatCacheObject = FlatObjectCache;
exports.FifoObjectCache = FifoObjectCache;

@@ -384,4 +388,5 @@ exports.LruObjectCache = LruObjectCache;

exports.LruMapCache = LruMapCache;
exports.FlatCacheObject = FlatObjectCache;
exports.FifoCacheObject = FifoObjectCache;
exports.LruCacheObject = LruMapCache;
//# sourceMappingURL=index.js.map
{
"name": "re-reselect",
"version": "3.1.0",
"version": "3.2.0",
"description": "Enhance Reselect selectors with deeper memoization and cache management",

@@ -54,10 +54,9 @@ "main": "lib/index.js",

"devDependencies": {
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"all-contributors-cli": "^6.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.6.0",
"coveralls": "^3.0.2",
"@babel/core": "^7.4.5",
"@babel/preset-env": "^7.4.5",
"all-contributors-cli": "^6.6.1",
"babel-jest": "^24.8.0",
"coveralls": "^3.0.4",
"husky": "^1.1.2",
"jest": "^23.6.0",
"jest": "^24.8.0",
"lint-staged": "^7.3.0",

@@ -73,2 +72,5 @@ "prettier": "^1.16.2",

"jest": {
"moduleFileExtensions": [
"js"
],
"coverageReporters": [

@@ -75,0 +77,0 @@ "text",

@@ -61,39 +61,17 @@ # Re-reselect

- [Re-reselect](#re-reselect)
- [Table of contents](#table-of-contents)
- [Installation](#installation)
- [Why? + example](#why--example)
- [Re-reselect solution](#re-reselect-solution)
- [Other viable solutions](#other-viable-solutions)
- [1- Declare a different selector for each different call](#1--declare-a-different-selector-for-each-different-call)
- [2- Declare a `makeGetPieceOfData` selector factory as explained in Reselect docs](#2--declare-a-makegetpieceofdata-selector-factory-as-explained-in-reselect-docs)
- [3- Wrap your `makeGetPieceOfData` selector factory into a memoizer function and call the returning memoized selector](#3--wrap-your-makegetpieceofdata-selector-factory-into-a-memoizer-function-and-call-the-returning-memoized-selector)
- [Examples](#examples)
- [FAQ](#faq)
- [How do I wrap my existing selector with re-reselect?](#how-do-i-wrap-my-existing-selector-with-re-reselect)
- [How do I use multiple inputs to set the cacheKey?](#how-do-i-use-multiple-inputs-to-set-the-cachekey)
- [How do I limit the cache size?](#how-do-i-limit-the-cache-size)
- [How to share a selector across multiple components while passing in props and retaining memoization?](#how-to-share-a-selector-across-multiple-components-while-passing-in-props-and-retaining-memoization)
- [How do I test a re-reselect selector?](#how-do-i-test-a-re-reselect-selector)
- [Testing `reselect` selectors stored in the cache](#testing-reselect-selectors-stored-in-the-cache)
- [API](#api)
- [reReselect([reselect's createSelector arguments])(keySelector, { cacheObject, selectorCreator })](#rereselectreselects-createselector-argumentskeyselector--cacheobject-selectorcreator-)
- [keySelector](#keyselector)
- [options.cacheObject](#optionscacheobject)
- [Custom cache strategy object](#custom-cache-strategy-object)
- [options.selectorCreator](#optionsselectorcreator)
- [Returns](#returns)
- [reReselectInstance(selectorArguments)](#rereselectinstanceselectorarguments)
- [reReselectInstance`.getMatchingSelector(selectorArguments)`](#rereselectinstancegetmatchingselectorselectorarguments)
- [reReselectInstance`.removeMatchingSelector(selectorArguments)`](#rereselectinstanceremovematchingselectorselectorarguments)
- [reReselectInstance`.cache`](#rereselectinstancecache)
- [reReselectInstance`.clearCache()`](#rereselectinstanceclearcache)
- [reReselectInstance`.dependencies`](#rereselectinstancedependencies)
- [reReselectInstance`.resultFunc`](#rereselectinstanceresultfunc)
- [reReselectInstance`.recomputations()`](#rereselectinstancerecomputations)
- [reReselectInstance`.resetRecomputations()`](#rereselectinstanceresetrecomputations)
- [reReselectInstance`.keySelector`](#rereselectinstancekeyselector)
- [About re-reselect](#about-re-reselect)
- [Todo's](#todos)
- [Contributors](#contributors)
- [Installation](#installation)
- [Why? + example](#why--example)
- [re-reselect solution](#re-reselect-solution)
- [Other viable solutions](#other-viable-solutions)
- [Examples](#examples)
- [FAQ](#faq)
- [API](#api)
- [`createCachedSelector`](#createCachedSelector)
- [`createStructuredCachedSelector`](#createStructuredCachedSelector)
- [keySelector](#keyselector)
- [options](#options)
- [selector instance][selector-instance-docs]
- [About re-reselect](#about-re-reselect)
- [Todo's](#todos)
- [Contributors](#contributors)

@@ -103,4 +81,4 @@ ## Installation

```console
npm install reselect
npm install re-reselect
npm install reselect -S
npm install re-reselect -S
```

@@ -122,3 +100,3 @@

### Re-reselect solution
### re-reselect solution

@@ -129,3 +107,3 @@ `re-reselect` selectors keep a **cache of `reselect` selectors** and store/retrieve them by `cacheKey`.

`cacheKey` is by default a `string` or `number` but can be anything depending on the chosen cache strategy (see [`cacheObject` option](#optionscacheobject)).
`cacheKey` is by default a `string` or `number` but can be anything depending on the chosen cache strategy (see [cache objects docs][cache-objects-docs]).

@@ -164,3 +142,3 @@ `cacheKey` is the output of `keySelector`, declared at selector initialization.

**Re-reselect** stays completely optional and consumes **your installed reselect** module (`reselect` is declared as **peer dependency**).
**re-reselect** stays completely optional and consumes **your installed reselect** module (`reselect` is declared as **peer dependency**).

@@ -265,3 +243,3 @@ ### Other viable solutions

Use a `cacheObject` which provides that feature by supplying a [`cacheObject` option](#optionscacheobject).
Use a `cacheObject` which provides that feature by supplying a [`cacheObject` option](#options).

@@ -323,123 +301,107 @@ You can also write **your own cache strategy**!

`Re-reselect` exposes its **cached selector creator** as **default export**.
### createCachedSelector
<!-- prettier-ignore -->
```js
import reReselect from 're-reselect';
// or:
import createCachedSelector from 're-reselect';
createCachedSelector(
// ...reselect's `createSelector` arguments
)(
keySelector,
{ options }
)
```
### reReselect([reselect's createSelector arguments])(keySelector, { cacheObject, selectorCreator })
**createCachedSelector** accepts the same arguments as reselect's [`createSelector`][reselect-create-selector] and returns a new function which accepts **2 arguments**:
**Re-reselect** accepts reselect's original [`createSelector` arguments][reselect-create-selector] and returns a new function which accepts **2 arguments**:
- `keySelector`
- `options { cacheObject, selectorCreator }` _(optional)_
- `{ options }` _(optional)_
#### keySelector
**Returns** a [selector instance][selector-instance-docs].
`keySelector` is a custom function receiving the same arguments as your selectors (and `inputSelectors`) and **returning a `cacheKey`**.
### createStructuredCachedSelector
`cacheKey` is **by default a `string` or `number`** but can be anything depending on the chosen cache strategy (see [`cacheObject` option](#optionscacheobject)).
<!-- prettier-ignore -->
```js
import { createStructuredCachedSelector } from 're-reselect';
The `keySelector` idea comes from [Lodash's .memoize][lodash-memoize].
createStructuredCachedSelector(
// ...reselect's `createStructuredSelector` arguments
)(
keySelector,
{ options }
)
```
#### options.cacheObject
**createStructuredCachedSelector** accepts the same arguments as reselect's [`createStructuredSelector`][reselect-create-structured-selector] and returns a new function which accepts **2 arguments**:
An optional custom [strategy object][docs-strategy-object] to handle the caching behaviour.
- `keySelector`
- `{ options }` _(optional)_
Default cache: `FlatObjectCache`.
**Returns** a [selector instance][selector-instance-docs].
`re-reselect` provides **6 ready to use cache object constructors**:
### `keySelector`
| name | accepted cacheKey | type | storage |
| :-----------------------------------------------: | :---------------: | :-----------------------------------: | :----------------------------: |
| [`FlatObjectCache`](src/cache/FlatObjectCache.js) | `number` `string` | flat unlimited | JS object |
| [`FifoObjectCache`](src/cache/FifoObjectCache.js) | `number` `string` | [first in first out][docs-fifo-cache] | JS object |
| [`LruObjectCache`](src/cache/LruObjectCache.js) | `number` `string` | [least recently used][docs-lru-cache] | JS object |
| [`FlatMapCache`](src/cache/FlatMapCache.js) | any | flat unlimited | [Map object][docs-mozilla-map] |
| [`FifoMapCache`](src/cache/FifoMapCache.js) | any | [first in first out][docs-fifo-cache] | [Map object][docs-mozilla-map] |
| [`LruMapCache`](src/cache/LruMapCache.js) | any | [least recently used][docs-lru-cache] | [Map object][docs-mozilla-map] |
`keySelector` is a custom function receiving the same arguments as your selectors (and `inputSelectors`) and **returning a `cacheKey`**.
<!-- prettier-ignore -->
```js
import createCachedSelector, {LruObjectCache, LruMapCache} from 're-reselect';
`cacheKey` is **by default a `string` or `number`** but can be anything depending on the chosen cache strategy (see [`cacheObject` option](#optionscacheobject)).
createCachedSelector(
// ...
)(
keySelector,
{
cacheObject: new LruObjectCache({cacheSize: 5}),
// or:
// cacheObject: new LruMapCache({cacheSize: 5}),
}
);
```
The `keySelector` idea comes from [Lodash's .memoize][lodash-memoize].
**[*]ObjectCache** strategy objects treat `cacheKey` of type `number` like strings, since they are used as arguments of JS objects.
### `options`
**[*]MapCache** strategy objects needs a **Map objects polyfill** in order to use them on non-supporting browsers.
`options` is an optional object with the following properties:
##### Custom cache strategy object
#### `cacheObject`
You can provide **any kind of cache strategy**. Declare a JS object adhering to the following interface:
Default: `FlatObjectCache`
```ts
interface ICacheObject {
set(key: any, selectorFn: any): void;
get(key: any): any;
remove(key: any): void;
clear(): void;
isValidCacheKey?(key: any): boolean; // optional
}
```
An optional custom **cache strategy object** to handle the caching behaviour.
#### options.selectorCreator
Read more about [re-reselect's custom cache here](cache-objects-docs).
#### `selectorCreator`
An optional function describing a [custom selectors][reselect-create-selector-creator]. By default it uses `reselect`'s `createSelector`.
#### Returns
### Selector instance
(Function): a `reReselectInstance` selector ready to be used **like a normal reselect selector**.
A selector function providing the same API as a **standard reselect selectors**.
### reReselectInstance(selectorArguments)
Retrieve data for given arguments.
> The followings are advanced methods and you won't need them for basic usage!
### reReselectInstance`.getMatchingSelector(selectorArguments)`
#### selector`.getMatchingSelector(selectorArguments)`
Retrieve the selector responding to the given arguments.
### reReselectInstance`.removeMatchingSelector(selectorArguments)`
#### selector`.removeMatchingSelector(selectorArguments)`
Remove from the cache the selector responding to the given arguments.
### reReselectInstance`.cache`
#### selector`.cache`
Get cacheObject instance being used by the selector (for advanced caching operations like [this](https://github.com/toomuchdesign/re-reselect/issues/40)).
### reReselectInstance`.clearCache()`
#### selector`.clearCache()`
Clear whole `reReselectInstance` cache.
Clear whole `selector` cache.
### reReselectInstance`.dependencies`
#### selector`.dependencies`
Get an array containing the provided `inputSelectors`. Refer to relevant discussion on [Reselect repo][reselect-test-selectors-dependencies].
### reReselectInstance`.resultFunc`
#### selector`.resultFunc`
Get `resultFunc` for easily [testing composed selectors][reselect-test-selectors].
### reReselectInstance`.recomputations()`
#### selector`.recomputations()`
Return the number of times the selector's result function has been recomputed.
### reReselectInstance`.resetRecomputations()`
#### selector`.resetRecomputations()`
Reset `recomputations` count.
### reReselectInstance`.keySelector`
#### selector`.keySelector`

@@ -450,3 +412,3 @@ Get `keySelector` for utility compositions or testing.

- [Re-reselect your whole redux state](https://patrickdesjardins.com/blog/re-reselect-your-whole-redux-state)
- [re-reselect your whole redux state](https://patrickdesjardins.com/blog/re-reselect-your-whole-redux-state)
- [Understanding reselect and re-reselect](http://alexnitta.com/understanding-reselect-and-re-reselect/)

@@ -471,3 +433,3 @@ - [Advanced Redux patterns: selectors](https://blog.brainsandbeards.com/advanced-redux-patterns-selectors-cb9f88381d74)

<!-- prettier-ignore -->
<table><tr><td align="center"><a href="http://www.andreacarraro.it"><img src="https://avatars3.githubusercontent.com/u/4573549?v=4" width="100px;" alt="Andrea Carraro"/><br /><sub><b>Andrea Carraro</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=toomuchdesign" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=toomuchdesign" title="Documentation">📖</a> <a href="#infra-toomuchdesign" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=toomuchdesign" title="Tests">⚠️</a> <a href="#review-toomuchdesign" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://github.com/xsburg"><img src="https://avatars2.githubusercontent.com/u/830824?v=4" width="100px;" alt="Stepan Burguchev"/><br /><sub><b>Stepan Burguchev</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=xsburg" title="Code">💻</a> <a href="#review-xsburg" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=xsburg" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/sgrishchenko"><img src="https://avatars3.githubusercontent.com/u/15995890?v=4" width="100px;" alt="Sergei Grishchenko"/><br /><sub><b>Sergei Grishchenko</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=sgrishchenko" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=sgrishchenko" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/Andarist"><img src="https://avatars2.githubusercontent.com/u/9800850?v=4" width="100px;" alt="Mateusz Burzyński"/><br /><sub><b>Mateusz Burzyński</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=Andarist" title="Code">💻</a> <a href="#infra-Andarist" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td><td align="center"><a href="https://olslash.github.io/"><img src="https://avatars3.githubusercontent.com/u/693493?v=4" width="100px;" alt="Mitch Robb"/><br /><sub><b>Mitch Robb</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=olslash" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=olslash" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/rufman"><img src="https://avatars3.githubusercontent.com/u/1128559?v=4" width="100px;" alt="Stephane Rufer"/><br /><sub><b>Stephane Rufer</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=rufman" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=rufman" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/spiffysparrow"><img src="https://avatars0.githubusercontent.com/u/2788860?v=4" width="100px;" alt="Tracy Mullen"/><br /><sub><b>Tracy Mullen</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=spiffysparrow" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=spiffysparrow" title="Tests">⚠️</a></td></tr><tr><td align="center"><a href="https://www.skc.name"><img src="https://avatars1.githubusercontent.com/u/4211838?v=4" width="100px;" alt="Sushain Cherivirala"/><br /><sub><b>Sushain Cherivirala</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=sushain97" title="Code">💻</a></td><td align="center"><a href="https://twitter.com/MaoStevemao"><img src="https://avatars0.githubusercontent.com/u/6316590?v=4" width="100px;" alt="Steve Mao"/><br /><sub><b>Steve Mao</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=stevemao" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/Dante-101"><img src="https://avatars2.githubusercontent.com/u/1428826?v=4" width="100px;" alt="Gaurav Lahoti"/><br /><sub><b>Gaurav Lahoti</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/issues?q=author%3ADante-101" title="Bug reports">🐛</a></td><td align="center"><a href="http://lon.im"><img src="https://avatars3.githubusercontent.com/u/13602053?v=4" width="100px;" alt="Lon"/><br /><sub><b>Lon</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/issues?q=author%3Acnlon" title="Bug reports">🐛</a></td><td align="center"><a href="https://github.com/bratushka"><img src="https://avatars2.githubusercontent.com/u/5492495?v=4" width="100px;" alt="bratushka"/><br /><sub><b>bratushka</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=bratushka" title="Code">💻</a></td><td align="center"><a href="https://andrz.me"><img src="https://avatars3.githubusercontent.com/u/615381?v=4" width="100px;" alt="Anders D. Johnson"/><br /><sub><b>Anders D. Johnson</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=AndersDJohnson" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/wormyy"><img src="https://avatars3.githubusercontent.com/u/8556724?v=4" width="100px;" alt="Július Retzer"/><br /><sub><b>Július Retzer</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=wormyy" title="Documentation">📖</a></td></tr><tr><td align="center"><a href="https://github.com/maartenschumacher"><img src="https://avatars3.githubusercontent.com/u/10407025?v=4" width="100px;" alt="Maarten Schumacher"/><br /><sub><b>Maarten Schumacher</b></sub></a><br /><a href="#ideas-maartenschumacher" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/alexanderjarvis"><img src="https://avatars2.githubusercontent.com/u/664238?v=4" width="100px;" alt="Alexander Jarvis"/><br /><sub><b>Alexander Jarvis</b></sub></a><br /><a href="#ideas-alexanderjarvis" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/greggb"><img src="https://avatars1.githubusercontent.com/u/514026?v=4" width="100px;" alt="Gregg B"/><br /><sub><b>Gregg B</b></sub></a><br /><a href="#example-greggb" title="Examples">💡</a></td><td align="center"><a href="http://ianobermiller.com"><img src="https://avatars0.githubusercontent.com/u/897931?v=4" width="100px;" alt="Ian Obermiller"/><br /><sub><b>Ian Obermiller</b></sub></a><br /><a href="#review-ianobermiller" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://github.com/lukyth"><img src="https://avatars3.githubusercontent.com/u/7040242?v=4" width="100px;" alt="Kanitkorn Sujautra"/><br /><sub><b>Kanitkorn Sujautra</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=lukyth" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/suark"><img src="https://avatars2.githubusercontent.com/u/6233440?v=4" width="100px;" alt="Brian Kraus"/><br /><sub><b>Brian Kraus</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=suark" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/el-dav"><img src="https://avatars1.githubusercontent.com/u/7252227?v=4" width="100px;" alt="el-dav"/><br /><sub><b>el-dav</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/issues?q=author%3Ael-dav" title="Bug reports">🐛</a></td></tr><tr><td align="center"><a href="https://augustin-riedinger.fr"><img src="https://avatars3.githubusercontent.com/u/1970156?v=4" width="100px;" alt="Augustin Riedinger"/><br /><sub><b>Augustin Riedinger</b></sub></a><br /><a href="#ideas-augnustin" title="Ideas, Planning, & Feedback">🤔</a></td></tr></table>
<table><tr><td align="center"><a href="http://www.andreacarraro.it"><img src="https://avatars3.githubusercontent.com/u/4573549?v=4" width="100px;" alt="Andrea Carraro"/><br /><sub><b>Andrea Carraro</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=toomuchdesign" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=toomuchdesign" title="Documentation">📖</a> <a href="#infra-toomuchdesign" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=toomuchdesign" title="Tests">⚠️</a> <a href="#review-toomuchdesign" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://github.com/xsburg"><img src="https://avatars2.githubusercontent.com/u/830824?v=4" width="100px;" alt="Stepan Burguchev"/><br /><sub><b>Stepan Burguchev</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=xsburg" title="Code">💻</a> <a href="#review-xsburg" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=xsburg" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/sgrishchenko"><img src="https://avatars3.githubusercontent.com/u/15995890?v=4" width="100px;" alt="Sergei Grishchenko"/><br /><sub><b>Sergei Grishchenko</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=sgrishchenko" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=sgrishchenko" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/Andarist"><img src="https://avatars2.githubusercontent.com/u/9800850?v=4" width="100px;" alt="Mateusz Burzyński"/><br /><sub><b>Mateusz Burzyński</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=Andarist" title="Code">💻</a> <a href="#infra-Andarist" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td><td align="center"><a href="https://olslash.github.io/"><img src="https://avatars3.githubusercontent.com/u/693493?v=4" width="100px;" alt="Mitch Robb"/><br /><sub><b>Mitch Robb</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=olslash" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=olslash" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/rufman"><img src="https://avatars3.githubusercontent.com/u/1128559?v=4" width="100px;" alt="Stephane Rufer"/><br /><sub><b>Stephane Rufer</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=rufman" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=rufman" title="Tests">⚠️</a></td><td align="center"><a href="https://github.com/spiffysparrow"><img src="https://avatars0.githubusercontent.com/u/2788860?v=4" width="100px;" alt="Tracy Mullen"/><br /><sub><b>Tracy Mullen</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=spiffysparrow" title="Code">💻</a> <a href="https://github.com/toomuchdesign/re-reselect/commits?author=spiffysparrow" title="Tests">⚠️</a></td></tr><tr><td align="center"><a href="https://www.skc.name"><img src="https://avatars1.githubusercontent.com/u/4211838?v=4" width="100px;" alt="Sushain Cherivirala"/><br /><sub><b>Sushain Cherivirala</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=sushain97" title="Code">💻</a></td><td align="center"><a href="https://twitter.com/MaoStevemao"><img src="https://avatars0.githubusercontent.com/u/6316590?v=4" width="100px;" alt="Steve Mao"/><br /><sub><b>Steve Mao</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=stevemao" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/Dante-101"><img src="https://avatars2.githubusercontent.com/u/1428826?v=4" width="100px;" alt="Gaurav Lahoti"/><br /><sub><b>Gaurav Lahoti</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/issues?q=author%3ADante-101" title="Bug reports">🐛</a></td><td align="center"><a href="http://lon.im"><img src="https://avatars3.githubusercontent.com/u/13602053?v=4" width="100px;" alt="Lon"/><br /><sub><b>Lon</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/issues?q=author%3Acnlon" title="Bug reports">🐛</a></td><td align="center"><a href="https://github.com/bratushka"><img src="https://avatars2.githubusercontent.com/u/5492495?v=4" width="100px;" alt="bratushka"/><br /><sub><b>bratushka</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=bratushka" title="Code">💻</a></td><td align="center"><a href="https://andrz.me"><img src="https://avatars3.githubusercontent.com/u/615381?v=4" width="100px;" alt="Anders D. Johnson"/><br /><sub><b>Anders D. Johnson</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=AndersDJohnson" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/wormyy"><img src="https://avatars3.githubusercontent.com/u/8556724?v=4" width="100px;" alt="Július Retzer"/><br /><sub><b>Július Retzer</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=wormyy" title="Documentation">📖</a></td></tr><tr><td align="center"><a href="https://github.com/maartenschumacher"><img src="https://avatars3.githubusercontent.com/u/10407025?v=4" width="100px;" alt="Maarten Schumacher"/><br /><sub><b>Maarten Schumacher</b></sub></a><br /><a href="#ideas-maartenschumacher" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/alexanderjarvis"><img src="https://avatars2.githubusercontent.com/u/664238?v=4" width="100px;" alt="Alexander Jarvis"/><br /><sub><b>Alexander Jarvis</b></sub></a><br /><a href="#ideas-alexanderjarvis" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/greggb"><img src="https://avatars1.githubusercontent.com/u/514026?v=4" width="100px;" alt="Gregg B"/><br /><sub><b>Gregg B</b></sub></a><br /><a href="#example-greggb" title="Examples">💡</a></td><td align="center"><a href="http://ianobermiller.com"><img src="https://avatars0.githubusercontent.com/u/897931?v=4" width="100px;" alt="Ian Obermiller"/><br /><sub><b>Ian Obermiller</b></sub></a><br /><a href="#review-ianobermiller" title="Reviewed Pull Requests">👀</a></td><td align="center"><a href="https://github.com/lukyth"><img src="https://avatars3.githubusercontent.com/u/7040242?v=4" width="100px;" alt="Kanitkorn Sujautra"/><br /><sub><b>Kanitkorn Sujautra</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=lukyth" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/suark"><img src="https://avatars2.githubusercontent.com/u/6233440?v=4" width="100px;" alt="Brian Kraus"/><br /><sub><b>Brian Kraus</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/commits?author=suark" title="Documentation">📖</a></td><td align="center"><a href="https://github.com/el-dav"><img src="https://avatars1.githubusercontent.com/u/7252227?v=4" width="100px;" alt="el-dav"/><br /><sub><b>el-dav</b></sub></a><br /><a href="https://github.com/toomuchdesign/re-reselect/issues?q=author%3Ael-dav" title="Bug reports">🐛</a></td></tr><tr><td align="center"><a href="https://augustin-riedinger.fr"><img src="https://avatars3.githubusercontent.com/u/1970156?v=4" width="100px;" alt="Augustin Riedinger"/><br /><sub><b>Augustin Riedinger</b></sub></a><br /><a href="#ideas-augnustin" title="Ideas, Planning, & Feedback">🤔</a></td><td align="center"><a href="https://github.com/RichardForrester"><img src="https://avatars0.githubusercontent.com/u/12902182?v=4" width="100px;" alt="RichardForrester"/><br /><sub><b>RichardForrester</b></sub></a><br /><a href="#ideas-RichardForrester" title="Ideas, Planning, & Feedback">🤔</a></td></tr></table>

@@ -482,2 +444,3 @@ <!-- ALL-CONTRIBUTORS-LIST:END -->

[reselect-create-selector]: https://github.com/reactjs/reselect/tree/v4.0.0#createselectorinputselectors--inputselectors-resultfunc
[reselect-create-structured-selector]: https://github.com/reduxjs/reselect/tree/v4.0.0#createstructuredselectorinputselectors-selectorcreator--createselector
[reselect-create-selector-creator]: https://github.com/reactjs/reselect/tree/v4.0.0#createselectorcreatormemoize-memoizeoptions

@@ -496,6 +459,4 @@ [lodash-memoize]: https://lodash.com/docs/4.17.4#memoize

[example-3]: examples/3-cache-api-calls.md
[docs-fifo-cache]: https://en.wikipedia.org/wiki/Cache_replacement_policies#First_In_First_Out_.28FIFO.29
[docs-lru-cache]: https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29
[docs-mozilla-map]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map
[docs-strategy-object]: https://sourcemaking.com/design_patterns/strategy
[selector-instance-docs]: #selector-instance
[cache-objects-docs]: src/cache#readme
[docs-all-contributors]: https://github.com/kentcdodds/all-contributors#emoji-key

@@ -1,87 +0,10 @@

import {createSelector} from 'reselect';
import FlatObjectCache from './cache/FlatObjectCache';
import createCachedSelector from './createCachedSelector';
export default createCachedSelector;
const defaultCacheCreator = FlatObjectCache;
const defaultCacheKeyValidator = () => true;
export {
default as createStructuredCachedSelector,
} from './createStructuredCachedSelector';
function createCachedSelector(...funcs) {
return (keySelector, options = {}) => {
// @NOTE Versions 0.x/1.x accepted "options" as a function
if (typeof options === 'function') {
throw new Error(
'[re-reselect] Second argument "options" must be an object. Please use "options.selectorCreator" to provide a custom selectorCreator.'
);
}
// https://github.com/reduxjs/reselect/blob/v4.0.0/src/index.js#L54
let recomputations = 0;
const resultFunc = funcs.pop();
const dependencies = Array.isArray(funcs[0]) ? funcs[0] : [...funcs];
const resultFuncWithRecomputations = (...args) => {
recomputations++;
return resultFunc(...args);
};
funcs.push(resultFuncWithRecomputations);
const cache = options.cacheObject || new defaultCacheCreator();
const selectorCreator = options.selectorCreator || createSelector;
const isValidCacheKey = cache.isValidCacheKey || defaultCacheKeyValidator;
// Application receives this function
const selector = function(...args) {
const cacheKey = keySelector(...args);
if (isValidCacheKey(cacheKey)) {
let cacheResponse = cache.get(cacheKey);
if (cacheResponse === undefined) {
cacheResponse = selectorCreator(...funcs);
cache.set(cacheKey, cacheResponse);
}
return cacheResponse(...args);
}
console.warn(
`[re-reselect] Invalid cache key "${cacheKey}" has been returned by keySelector function.`
);
return undefined;
};
// Further selector methods
selector.getMatchingSelector = (...args) => {
const cacheKey = keySelector(...args);
// @NOTE It might update cache hit count in LRU-like caches
return cache.get(cacheKey);
};
selector.removeMatchingSelector = (...args) => {
const cacheKey = keySelector(...args);
cache.remove(cacheKey);
};
selector.clearCache = () => {
cache.clear();
};
selector.resultFunc = resultFunc;
selector.dependencies = dependencies;
selector.cache = cache;
selector.recomputations = () => recomputations;
selector.resetRecomputations = () => (recomputations = 0);
selector.keySelector = keySelector;
return selector;
};
}
export default createCachedSelector;
// Cache objects
export {FlatObjectCache};
export {default as FlatObjectCache} from './cache/FlatObjectCache';
export {default as FifoObjectCache} from './cache/FifoObjectCache';

@@ -95,4 +18,4 @@ export {default as LruObjectCache} from './cache/LruObjectCache';

// @TODO remove in next major release
export {FlatObjectCache as FlatCacheObject};
export {default as FlatCacheObject} from './cache/FlatObjectCache';
export {default as FifoCacheObject} from './cache/FifoObjectCache';
export {default as LruCacheObject} from './cache/LruMapCache';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc