redux-toolkit icon indicating copy to clipboard operation
redux-toolkit copied to clipboard

experiment: additional arguments into `selectState`

Open phryneas opened this issue 4 years ago • 4 comments

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);

phryneas avatar Apr 09 '21 15:04 phryneas

Deploy preview for redux-starter-kit-docs ready!

Built with commit 3f094d3c49021d3b094cdb6bcb4a052927069af1

https://deploy-preview-990--redux-starter-kit-docs.netlify.app

netlify[bot] avatar Apr 09 '21 15:04 netlify[bot]

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

codesandbox-ci[bot] avatar Apr 09 '21 15:04 codesandbox-ci[bot]

Hmm. This still something that's necessary with Reselect 4.1?

markerikson avatar Jul 03 '22 01:07 markerikson

Eh, I don't feel this is critical for 1.9.

markerikson avatar Aug 21 '22 22:08 markerikson