redux-toolkit
redux-toolkit copied to clipboard
experiment: additional arguments into `selectState`
As requested by Daniel in chat.
It's not a lot of code, so it could be discussion-worthy.
Essentially, the idea is to be able to pass additional args into the selectors created by the entityAdapter.
Actually, this is currently already possible for everything except selectById due to how reselect works - but not supported by the types.
Example:
import { createEntityAdapter } from "@reduxjs/toolkit";
const adapter = createEntityAdapter();
export const { selectAll: getComponents } = adapter.getSelectors(
// @ts-ignore
(state, containerId) => state.page.containers[containerId].components
);
let components = adapter.getInitialState();
components = adapter.addOne(components, { id: 1, foo: "bar" });
const state = {
page: {
containers: [undefined, undefined, { components }]
}
};
//@ts-ignore
const x = getComponents(state, 2);
Deploy preview for redux-starter-kit-docs ready!
Built with commit 3f094d3c49021d3b094cdb6bcb4a052927069af1
https://deploy-preview-990--redux-starter-kit-docs.netlify.app
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 3f094d3c49021d3b094cdb6bcb4a052927069af1:
| Sandbox | Source |
|---|---|
| Vanilla | Configuration |
| Vanilla Typescript | Configuration |
| rsk-github-issues-example | Configuration |
Hmm. This still something that's necessary with Reselect 4.1?
Eh, I don't feel this is critical for 1.9.