Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add with-reselect package (#7)
* Core functionality for Reselect utils * Begin docs * Upgrade devDependencies * Add CONTRIBUTING.md
- Loading branch information
Showing
9 changed files
with
703 additions
and
515 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
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,70 @@ | ||
# Contributing | ||
|
||
Thanks for your interest in Dynamic Selectors! You are very welcome to contribute. | ||
|
||
By contributing to Dynamic Selectors, you agree to abide by the [code of conduct](./CODE_OF_CONDUCT.md). | ||
|
||
## Reporting Bugs and Asking Questions | ||
|
||
Before opening an issue, please search the [issue tracker](https://github.com/spautz/dynamic-selectors/issues) | ||
to make sure your issue hasn't already been reported. | ||
|
||
### New Features and Ideas | ||
|
||
If you are proposing a new feature, make sure to [open an issue](https://github.com/spautz/dynamic-selectors/issues/new/choose) | ||
to discuss your idea and make sure it is inline with the project goals. | ||
|
||
## Setup and Development | ||
|
||
1. Fork this repository to your own GitHub account and clone it to your local device: | ||
|
||
``` | ||
git clone https://github.com/your-name/dynamic-selectors.git | ||
cd dynamic-selectors | ||
git remote add upstream https://github.com/spautz/dynamic-selectors.git | ||
``` | ||
|
||
2. Install the dependencies and ensure everything runs properly: | ||
|
||
``` | ||
yarn install | ||
yarn all | ||
``` | ||
|
||
3. Create a new topic branch: | ||
|
||
``` | ||
git checkout -b my-topic-branch | ||
``` | ||
|
||
4. To test your local dev version of `@dynamic-selectors/with-reselect` in other projects, [Yalc](https://github.com/whitecolor/yalc) | ||
is an excellent tool. | ||
|
||
5. After you have made your changes, submit a pull request. Issues and pull requests are monitored, and you should receive a reply. | ||
|
||
## Code and Project Standards | ||
|
||
Eslint, Typescript, and Prettier enforce most code standards. A pre-push hook will validate the project against those standards. | ||
|
||
Running `yarn test` will check the code against unit tests and generate a code coverage report (in `coverage/`). | ||
This project's goal is to be near 100% code coverage. | ||
|
||
Running `yarn all` will check _everything_: tests, code standards, and all packages' builds. | ||
Your pull request is more likely to be accepted if this passes for your branch. | ||
|
||
## Overall Process | ||
|
||
In general, the contribution workflow looks like this: | ||
|
||
1. Open a new issue in the [Issue tracker](https://github.com/spautz/dynamic-selectors/issues). | ||
2. Fork the repo and set up your local development environment. | ||
3. Make changes in a branch in your fork. | ||
4. Make sure all tests pass and there are no errors. | ||
5. Submit a [pull request](https://github.com/spautz/dynamic-selectors/pulls), referencing any issues it addresses. | ||
|
||
Please try to keep your pull request focused in scope and avoid including unrelated commits. | ||
|
||
After you have submitted your pull request, we'll try to get back to you as soon as possible. We may suggest some | ||
changes or improvements. | ||
|
||
Thank you for contributing! |
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
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,34 @@ | ||
import { createDynamicSelector, DynamicSelectorInnerFn } from '@dynamic-selectors/core'; | ||
import { Selector } from 'reselect'; | ||
|
||
/** | ||
* Wraps a Reselect selector in a new function, which can be passed to createDynamicSelector() | ||
*/ | ||
const wrapReselect = <StateType = any, ReturnType = any>( | ||
reselectSelectorFn: Selector<StateType, ReturnType>, | ||
): DynamicSelectorInnerFn<ReturnType> => { | ||
const innerFn: DynamicSelectorInnerFn = (getState) => { | ||
return reselectSelectorFn(getState(null)); | ||
}; | ||
|
||
innerFn.displayName = reselectSelectorFn.name; | ||
return innerFn; | ||
}; | ||
|
||
/** | ||
* For convenience, a helper that wraps the Reselect selector and passes it to createDynamicSelector, in a single step. | ||
* | ||
* If you make your own selector creator (via `dynamicSelectorForState`), you would create a similar "create..." | ||
* function around it. | ||
*/ | ||
const createDynamicSelectorFromReselect = <StateType = any, ReturnType = any>( | ||
reselectSelectorFn: Selector<StateType, ReturnType>, | ||
dynamicSelectorOptions: Parameters<typeof createDynamicSelector>[1], | ||
) => { | ||
return createDynamicSelector<ReturnType>( | ||
wrapReselect(reselectSelectorFn), | ||
dynamicSelectorOptions, | ||
); | ||
}; | ||
|
||
export { wrapReselect, createDynamicSelectorFromReselect }; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export default {}; | ||
export * from './dynamicSelectorFromReselect'; | ||
export * from './reselectSelectorFromDynamic'; |
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,10 @@ | ||
import { DynamicSelectorArgsWithoutState, DynamicSelectorFn } from '@dynamic-selectors/core'; | ||
|
||
const createReselectSelectorFromDynamic = <StateType = any, ReturnType = any>( | ||
dynamicSelectorFn: DynamicSelectorFn<ReturnType>, | ||
...paramsAndOtherArgs: DynamicSelectorArgsWithoutState | ||
) => { | ||
return (state: StateType) => dynamicSelectorFn(state, ...paramsAndOtherArgs); | ||
}; | ||
|
||
export { createReselectSelectorFromDynamic }; |
Oops, something went wrong.