{"name":"reselect","version":"2.0.3","keywords":["react","redux"],"author":{"name":"Martijn Faassen"},"license":"MIT","_id":"reselect@2.0.3","maintainers":[{"name":"faassen","email":"faassen@startifact.com"},{"name":"ellbee","email":"l_bannard@yahoo.co.uk"}],"contributors":[{"name":"Martijn Faassen"},{"name":"Lee Bannard"},{"name":"Robert Binna"},{"name":"Philip Spitzlinger"},{"name":"Alex Guerra"},{"name":"ryanatkn"},{"name":"Adam Royle"},{"name":"Christian Schuhmann"},{"name":"Jason Huang"},{"name":"Daniel Barreto"},{"name":"Mihail Diordiev"},{"name":"Daniela Borges"},{"name":"C. T. Lin"},{"name":"SpainTrain"},{"name":"Mark Dalgleish"},{"name":"Brian Ng"}],"homepage":"https://github.com/rackt/reselect#readme","bugs":{"url":"https://github.com/rackt/reselect/issues"},"dist":{"shasum":"cab04c867cf67381dcbe86f3be3caa1831b89259","tarball":"http://registry-npm.ywwl.com/reselect/download/reselect-2.0.3.tgz","integrity":"sha512-DekWFWOjvaqx2s9IRUkp5nscvYG5d1BkQKpItVZHYjjSQTMuxFRSZcjJpKyAkcxl13/feA5z4WV3k5/QnyIuxQ==","signatures":[{"sig":"MEQCIH5T7th3sZVPOCFz90L8QLobFoUwZG/Dv7Yv0c67LE6kAiA4EeXjIrifO0wKlUTOVVn7ttpy3Bhd37SGzLy/KXDucw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"size":14309,"noattachment":false,"key":"/reselect/-/reselect-2.0.3.tgz"},"main":"lib/index.js","_from":".","files":["lib","src","README.md","LICENSE","package.json"],"_shasum":"cab04c867cf67381dcbe86f3be3caa1831b89259","gitHead":"244ba5b908e04d94308fcba2e6513c3bf5cb10c3","scripts":{"lint":"eslint src test","test":"NODE_ENV=test mocha --compilers js:babel/register --recursive","compile":"babel --loose es6.modules -d lib/ src/","test:cov":"babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive","prepublish":"npm run compile"},"_npmUser":{"name":"ellbee","email":"l_bannard@yahoo.co.uk"},"repository":{"url":"git+https://github.com/rackt/reselect.git","type":"git"},"_npmVersion":"3.5.3","description":"Selectors for Redux.","directories":{},"jsnext:main":"src/index.js","_nodeVersion":"5.5.0","devDependencies":{"chai":"^3.0.0","babel":"^5.5.8","mocha":"^2.2.5","eslint":"^1.5","isparta":"^3.0.3","coveralls":"^2.11.4","babel-core":"^5.6.15","codecov.io":"^0.1.6","babel-eslint":"^4.1.3","lodash.memoize":"^3.0.4","eslint-config-rackt":"1.0.0","eslint-plugin-react":"^3.5.1"},"_npmOperationalInternal":{"tmp":"tmp/reselect-2.0.3.tgz_1454358228465_0.7160679153166711","host":"packages-8-eu.internal.npmjs.com"},"readme":"# Reselect\r\n\r\n[![npm package][npm-badge]][npm][![Coveralls][coveralls-badge]][coveralls][![GitHub Workflow Status][build-badge]][build]![TypeScript][typescript-badge]\r\n\r\nA library for creating memoized \"selector\" functions. Commonly used with Redux, but usable with any plain JS immutable data as well.\r\n\r\n- Selectors can compute derived data, allowing [Redux] to store the minimal possible state.\r\n- Selectors are efficient. A selector is not recomputed unless one of its arguments changes.\r\n- Selectors are composable. They can be used as input to other selectors.\r\n\r\nThe **Redux docs usage page on [Deriving Data with Selectors](https://redux.js.org/usage/deriving-data-selectors)** covers the purpose and motivation for selectors, why memoized selectors are useful, typical Reselect usage patterns, and using selectors with [React-Redux].\r\n\r\n## Installation\r\n\r\n### Redux Toolkit\r\n\r\nWhile Reselect is not exclusive to [Redux], it is already included by default in [the official Redux Toolkit package](https://redux-toolkit.js.org) - no further installation needed.\r\n\r\n```ts\r\nimport { createSelector } from '@reduxjs/toolkit'\r\n```\r\n\r\n### Standalone\r\n\r\nFor standalone usage, install the `reselect` package:\r\n\r\n```bash\r\n# NPM\r\nnpm install reselect\r\n\r\n# Yarn\r\nyarn add reselect\r\n```\r\n\r\n---\r\n\r\n## Documentation\r\n\r\nThe Reselect docs are available at **https://reselect.js.org**, and include usage guides and API references:\r\n\r\n- [**Introduction**](#https://reselect.js.org/introduction/getting-started)\r\n- [**How Does Reselect Work?**](#https://reselect.js.org/introduction/how-does-reselect-work)\r\n- **API Reference**:\r\n  - **[`createSelector`]**\r\n  - **[`createSelectorCreator`]**\r\n  - **[`createStructuredSelector`]**\r\n  - [**Development-Only Stability Checks**](#https://reselect.js.org/api/development-only-stability-checks)\r\n  - **[`lruMemoize`]**\r\n  - **[`weakMapMemoize`]**\r\n- [**FAQ**](#https://reselect.js.org/FAQ)\r\n\r\n## Basic Usage\r\n\r\nReselect exports a [`createSelector`] API, which generates memoized selector functions. [`createSelector`] accepts one or more [input selectors], which extract values from arguments, and a [result function] function that receives the extracted values and should return a derived value. If the generated [output selector] is called multiple times, the output will only be recalculated when the extracted values have changed.\r\n\r\nYou can play around with the following **example** in [this CodeSandbox](https://codesandbox.io/s/reselect-example-g3k9gf?file=/src/index.js):\r\n\r\n```ts\r\nimport { createSelector } from 'reselect'\r\n\r\ninterface RootState {\r\n  todos: { id: number; completed: boolean }[]\r\n  alerts: { id: number; read: boolean }[]\r\n}\r\n\r\nconst state: RootState = {\r\n  todos: [\r\n    { id: 0, completed: false },\r\n    { id: 1, completed: true }\r\n  ],\r\n  alerts: [\r\n    { id: 0, read: false },\r\n    { id: 1, read: true }\r\n  ]\r\n}\r\n\r\nconst selectCompletedTodos = (state: RootState) => {\r\n  console.log('selector ran')\r\n  return state.todos.filter(todo => todo.completed === true)\r\n}\r\n\r\nselectCompletedTodos(state) // selector ran\r\nselectCompletedTodos(state) // selector ran\r\nselectCompletedTodos(state) // selector ran\r\n\r\nconst memoizedSelectCompletedTodos = createSelector(\r\n  [(state: RootState) => state.todos],\r\n  todos => {\r\n    console.log('memoized selector ran')\r\n    return todos.filter(todo => todo.completed === true)\r\n  }\r\n)\r\n\r\nmemoizedSelectCompletedTodos(state) // memoized selector ran\r\nmemoizedSelectCompletedTodos(state)\r\nmemoizedSelectCompletedTodos(state)\r\n\r\nconsole.log(selectCompletedTodos(state) === selectCompletedTodos(state)) //=> false\r\n\r\nconsole.log(\r\n  memoizedSelectCompletedTodos(state) === memoizedSelectCompletedTodos(state)\r\n) //=> true\r\n```\r\n\r\nAs you can see from the example above, `memoizedSelectCompletedTodos` does not run the second or third time, but we still get the same return value as last time.\r\n\r\nIn addition to skipping unnecessary recalculations, `memoizedSelectCompletedTodos` returns the existing result reference if there is no recalculation. This is important for libraries like [React-Redux] or [React] that often rely on reference equality checks to optimize UI updates.\r\n\r\n---\r\n\r\n## Terminology\r\n\r\n- <a name=\"selector-function\"></a>[**Selector Function**](#selector-function): A function that accepts one or more JavaScript values as arguments, and derives a result. When used with [Redux], the first argument is typically the entire Redux store state.\r\n- <a name=\"input-selectors\"></a>[**input selectors**](#input-selectors): Basic selector functions used as building blocks for creating a memoized selector. They are passed as the first argument(s) to [`createSelector`], and are called with all selector arguments. They are responsible for extracting and providing necessary values to the [result function].\r\n- <a name=\"output-selector\"></a>[**Output Selector**](#output-selector): The actual memoized selectors created by [`createSelector`].\r\n- <a name=\"result-function\"></a>[**Result Function**](#result-function): The function that comes after the [input selectors]. It takes the [input selectors]' return values as arguments and returns a result.\r\n- <a name=\"dependencies\"></a>[**`Dependencies`**](#dependencies): Same as [input selectors]. They are what the [output selector] \"depends\" on.\r\n\r\nThe below example serves as a visual aid:\r\n\r\n```ts\r\nconst outputSelector = createSelector(\r\n  [inputSelector1, inputSelector2, inputSelector3], // synonymous with `dependencies`.\r\n  resultFunc // Result function\r\n)\r\n```\r\n\r\n---\r\n\r\n## What's New in 5.0.0?\r\n\r\nVersion 5.0.0 introduces several new features and improvements:\r\n\r\n- **Customization Enhancements**:\r\n\r\n  - Added the ability to pass an options object to [`createSelectorCreator`], allowing for customized `memoize` and `argsMemoize` functions, alongside their respective options (`memoizeOptions` and `argsMemoizeOptions`).\r\n  - The [`createSelector`] function now supports direct customization of `memoize` and `argsMemoize` within its options object.\r\n\r\n- **Memoization Functions**:\r\n\r\n  - Introduced new experimental memoization functions: `weakMapMemoize` and `unstable_autotrackMemoize`.\r\n  - Incorporated `memoize` and `argsMemoize` into the [output selector fields] for debugging purposes.\r\n\r\n- **TypeScript Support and Performance**:\r\n\r\n  - Discontinued support for TypeScript versions below 4.7, aligning with modern TypeScript features.\r\n  - Significantly improved TypeScript performance for nesting [output selectors][output selector]. The nesting limit has increased from approximately 8 to around 30 [output selectors][output selector], greatly reducing the occurrence of the infamous `Type instantiation is excessively deep and possibly infinite` error.\r\n\r\n- **Selector API Enhancements**:\r\n\r\n  - Removed the second overload of `createStructuredSelector` due to its susceptibility to runtime errors.\r\n\r\n- **Additional Functionalities**:\r\n\r\n  - Added `dependencyRecomputations` and `resetDependencyRecomputations` to the [output selector fields]. These additions provide greater control and insight over [input selectors], complementing the new `argsMemoize` API.\r\n  - Introduced `inputStabilityCheck`, a development tool that runs the [input selectors] twice using the same arguments and triggers a warning If they return differing results for the same call.\r\n  - Introduced `identityFunctionCheck`, a development tool that checks to see if the [result function] returns its own input.\r\n\r\nThese updates aim to enhance flexibility, performance, and developer experience. For detailed usage and examples, refer to the updated documentation sections for each feature.\r\n\r\n- **Breaking Changes**:\r\n\r\n  - Removed `ParametricSelector` and `OutputParametricSelector` types. Their functionalities are now integrated into `Selector` and `OutputSelector` respectively, which inherently support additional parameters.\r\n\r\n<div align=\"right\">[ <a href=\"installation\">↑ Back to top ↑</a> ]</div>\r\n\r\n---\r\n\r\n## License\r\n\r\nMIT\r\n\r\n## References\r\n\r\n<details><summary><b>Click to Expand</b></summary>\r\n\r\nOriginally inspired by getters in [NuclearJS](https://github.com/optimizely/nuclear-js.git), [subscriptions](https://github.com/Day8/re-frame#just-a-read-only-cursor) in [re-frame](https://github.com/Day8/re-frame) and this [proposal](https://github.com/reduxjs/redux/pull/169) from [speedskater](https://github.com/speedskater).\r\n\r\n[typescript-badge]: https://img.shields.io/badge/TypeScript-v4%2E7%2B-007ACC?style=for-the-badge&logo=TypeScript&logoColor=black&labelColor=blue&color=gray\r\n[build-badge]: https://img.shields.io/github/actions/workflow/status/reduxjs/reselect/build-and-test-types.yml?branch=master&style=for-the-badge\r\n[build]: https://github.com/reduxjs/reselect/actions/workflows/build-and-test-types.yml\r\n[npm-badge]: https://img.shields.io/npm/v/reselect.svg?style=for-the-badge\r\n[npm]: https://www.npmjs.org/package/reselect\r\n[coveralls-badge]: https://img.shields.io/coveralls/reduxjs/reselect/master.svg?style=for-the-badge\r\n[coveralls]: https://coveralls.io/github/reduxjs/reselect\r\n\r\n<!-- External Links -->\r\n\r\n[Redux]: https://redux.js.org 'Redux'\r\n[React]: https://react.dev 'React'\r\n[React-Redux]: https://react-redux.js.org 'React-Redux'\r\n\r\n<!-- Internal Links -->\r\n\r\n[selector]: #selector-function 'Selector Function'\r\n[input selectors]: #input-selectors 'Input Selectors'\r\n[output selector]: #output-selector 'Output Selector'\r\n[result function]: #result-function 'Result Function'\r\n[output selector fields]: https://reselect.js.org/api/createSelector#output-selector-fields 'Output Selector Fields'\r\n[`createSelector`]: https://reselect.js.org/api/createSelector 'createSelector'\r\n[`createSelectorCreator`]: https://reselect.js.org/api/createSelectorCreator 'createSelectorCreator'\r\n[`lruMemoize`]: https://reselect.js.org/api/lruMemoize 'lruMemoize'\r\n[`weakMapMemoize`]: https://reselect.js.org/api/weakMapMemoize 'weakMapMemoize'\r\n[`createStructuredSelector`]: https://reselect.js.org/api/createStructuredSelector 'createStructuredSelector'\r\n\r\n</details>\r\n","publish_time":1454358231129,"_cnpm_publish_time":1454358231129,"dist-tags":{"alpha":"5.0.0-alpha.2","beta":"5.0.0-beta.1","latest":"5.3.0","next":"5.0.0-rc.0","rc":"5.0.0-rc.1","rc1":"3.0.0-beta.1"}}