{"id":22206574,"url":"https://github.com/alexeyraspopov/selectre","last_synced_at":"2025-07-27T07:32:27.679Z","repository":{"id":65493826,"uuid":"430835738","full_name":"alexeyraspopov/selectre","owner":"alexeyraspopov","description":"Time \u0026 Space Efficient State Selectors","archived":false,"fork":false,"pushed_at":"2021-12-29T20:23:04.000Z","size":49,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-01T03:34:18.198Z","etag":null,"topics":["memoization","react","redux","selector"],"latest_commit_sha":null,"homepage":"https://selectre.js.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexeyraspopov.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-22T19:17:14.000Z","updated_at":"2022-02-16T02:30:50.000Z","dependencies_parsed_at":"2023-01-25T21:15:18.841Z","dependency_job_id":null,"html_url":"https://github.com/alexeyraspopov/selectre","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyraspopov%2Fselectre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyraspopov%2Fselectre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyraspopov%2Fselectre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexeyraspopov%2Fselectre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexeyraspopov","download_url":"https://codeload.github.com/alexeyraspopov/selectre/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227777712,"owners_count":17818455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["memoization","react","redux","selector"],"created_at":"2024-12-02T18:15:27.623Z","updated_at":"2024-12-02T18:15:28.666Z","avatar_url":"https://github.com/alexeyraspopov.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Selectre\n\n    npm install selectre\n\nTiny time and space efficient state selectors for React, Redux, and more.\n\n- Selectre is built as a more efficient alternative to\n  [Reselect](https://github.com/reduxjs/reselect)\n- Selectre is designed to work with Redux's `useSelector()` and React's `useSyncExternalStore()` and\n  ensure the least amount of unnecessary computations for things that don't change.\n- Selectre uses very efficient implementation of LRU cache to ensure no overhead in accessing cached\n  computation results.\n- Selectre uses shallow equality by default to help developers avoid shooting themselves in the\n  foot.\n- Selectre caches parametric selectors in the way that allows developers not to use additional\n  measures to memoize stuff in components.\n\n## Creating and using selectors\n\n```tsx\nimport { createSelector } from \"selectre\";\nimport { useSelector } from \"react-redux\";\n\nlet selectNumberCompletedTodos = createSelector(\n  (state) =\u003e state.todos,\n  (todos) =\u003e todos.filter((todo) =\u003e todo.completed).length,\n);\n\nfunction CompletedTodosCounter() {\n  let numberCompletedTodos = useSelector(selectNumberCompletedTodos());\n  return \u003cspan\u003e{numberCompletedTodos}\u003c/span\u003e;\n}\n```\n\nSelectors uniformity is important because it affects the amount of effort needed to eventually add\nparameters to a simple selectors.\n\n```tsx\nimport { createSelector } from \"selectre\";\nimport { useSelector } from \"react-redux\";\n\nlet selectNumberFilteredTodos = createSelector(\n  (state) =\u003e state.todos,\n  (_, completed) =\u003e completed,\n  (todos, completed) =\u003e todos.filter((todo) =\u003e todo.completed === completed).length,\n);\n\nfunction TodoCounter({ completed }) {\n  let numberFilteredTodos = useSelector(selectNumberFilteredTodos(completed));\n  return \u003cspan\u003e{numberFilteredTodos}\u003c/span\u003e;\n}\n```\n\n```typescript\nlet selectNumberCompletedTodos = createSelector(\n  (state) =\u003e state.todos,\n  (_, completed) =\u003e completed,\n  (todos, completed) =\u003e todos.filter((todo) =\u003e todo.completed === completed).length,\n  // isInputEqual for comparing inputs, isOutputEqual for the output\n  { isInputEqual: Object.is },\n);\n```\n\n## Using Selectre with React's `useSyncExternaStore()`\n\n```javascript\nimport { useSyncExternalStoreWithSelector } from \"use-sync-external-store/with-selector\";\n\nfunction useSelector(selector) {\n  // TODO\n}\n```\n\n## Credits\n\n- The intent and main API is similar and based on [Reselect](https://github.com/reduxjs/reselect)\n- LRU cache implementation is based on\n  [Guillaume Plique's article about LRU cache and using typed arrays to implement Doubly-Linked Lists](https://yomguithereal.github.io/posts/lru-cache)\n  (GitHub: [@Yomguithereal](https://github.com/Yomguithereal), Twitter:\n  [@Yomguithereal](https://twitter.com/Yomguithereal))\n- Cache key's hash function implementation is based on\n  [Immutable.js `hashCode()`](https://github.com/immutable-js/immutable-js/blob/4d0e9819e509861d0f16a64a4fc0bfdc892563f9/src/Hash.js)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexeyraspopov%2Fselectre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexeyraspopov%2Fselectre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexeyraspopov%2Fselectre/lists"}