-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e464b0
commit c007aa9
Showing
5 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## [`v0.1.0`](https://github.com/alexeyraspopov/selectre/releases/tag/v1.0.0) | ||
|
||
- Initial public version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Selectre | ||
|
||
Tiny time and space efficient state selectors for React, Redux, and more. | ||
|
||
- Selectre is built as a more efficient alternative to | ||
[Reselect](https://github.com/reduxjs/reselect) | ||
- Selectre is designed to work with Redux's `useSelector()` and React's `useSyncExternalStore()` and | ||
ensure the least amount of unnecessary computations for things that don't change. | ||
- Selectre uses very efficient implementation of LRU cache to ensure no overhead in accessing cached | ||
computation results. | ||
- Selectre uses shallow equality by default to help developers avoid shooting themselves in the | ||
foot. | ||
- Selectre caches parametric selectors in the way that allows developers not to use additional | ||
measures to memoize stuff in components. | ||
|
||
```tsx | ||
import { createSelector } from "selectre"; | ||
import { useSelector } from "react-redux"; | ||
|
||
let selectNumberCompletedTodos = createSelector({ | ||
(state) => state.todos, | ||
(todos) => todos.filter(todo => todo.completed).length, | ||
}); | ||
|
||
function CompletedTodosCounter() { | ||
// NOTE: the result of createSelector() is a function | ||
// that provides access to the selector itself | ||
let numberCompletedTodos = useSelector(selectNumberCompletedTodos()); | ||
return <span>{numberCompletedTodos}</span>; | ||
} | ||
``` | ||
|
||
Selectors uniformity is important because it affects the amount of effort needed to eventually add | ||
parameters to a simple selectors. | ||
|
||
```tsx | ||
import { createSelector } from "selectre"; | ||
import { useSelector } from "react-redux"; | ||
|
||
let selectNumberFilteredTodos = createSelector({ | ||
(state) => state.todos, | ||
(_, completed) => completed, | ||
(todos, completed) => todos.filter(todo => todo.completed === completed).length, | ||
}); | ||
|
||
function TodoCounter({ completed }) { | ||
let numberFilteredTodos = useSelector(selectNumberFilteredTodos(completed)); | ||
return <span>{numberFilteredTodos}</span>; | ||
} | ||
``` | ||
|
||
Read full docs [on the homepage](alexeyraspopov.github.io/selectre/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters