Skip to content

Custom reducer creators #3837

Open
Open
@EskiMojo14

Description

@EskiMojo14

courtesy of @phryneas

With the addition of the create callback syntax for createSlice in 2.0, it could be useful to allow custom builders of some fashion to be passed to createSlice (or a function that makes a createSlice function)

creators would need to return a definition which is built immediately when createSlice is called, and then handle that definition by adding any action creators, case reducers, and matchers necessary.

for example, the new create.asyncThunk creator:

  • creates an async thunk
  • attaches the async thunk to .actions
  • adds mappings from any provided pending/fulfilled/rejected case reducers to the corresponding action type
  • adds a matcher if a settled case reducer is provided
  • attaches its case reducers to .caseReducers

type-wise, because the state type is dependent on the individual createSlice call, the only way i could see it working would be with a module augmentation based system like buildCreateApi uses.

this would also be a potential solution for createSlice always pulling in createAsyncThunk for the create.asyncThunk builder - though we are investigating simpler solutions for 2.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions