Skip to content

Commit

Permalink
remove requirement for create to be a function
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Jun 14, 2024
1 parent 62e96d5 commit a12524a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions docs/usage/custom-slice-creators.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ Typically a creator will return a [single reducer definition](#single-definition

### Creator definitions

A creator definition contains the actual runtime logic for that creator. It's an object with a `type` property, a `create` method, and an optional `handle` method.
A creator definition contains the actual runtime logic for that creator. It's an object with a `type` property, a `create` value (typically a function or set of functions), and an optional `handle` method.

It's passed to [`buildCreateSlice`](../api/createSlice#buildcreateslice) as part of the `creators` object, and the name used when calling `buildCreateSlice` will be the key the creator is nested under in the `create` object.

Expand Down Expand Up @@ -413,9 +413,9 @@ const reducerCreator: ReducerCreator<typeof reducerCreatorType> = {

#### `create`

The `create` method is the function that will be attached to the `create` object, before it's passed to the `reducers` callback.
The `create` value will be attached to the `create` object, before it's passed to the `reducers` callback.

Because it's a function, the `this` value will be the final `create` object when called (assuming a `create.creator()` call). It also could have additional methods attached.
If it's a function, the `this` value will be the final `create` object when called (assuming a `create.creator()` call). It also could have additional methods attached, or be an object with methods.

See the [Further examples](#further-examples) section for some examples of these.

Expand Down Expand Up @@ -605,7 +605,7 @@ The `ReducerCreatorEntry<Create, Exposes>` utility has two type parameters:

#### `Create`

The signature of the `create` method of the creator definition.
The type of the `create` value of the creator definition (typically a function signature).

:::caution `CaseReducers`

Expand Down
6 changes: 3 additions & 3 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export interface ReducerDefinition<
}

export type ReducerCreatorEntry<
Create extends (...args: any[]) => any,
Create,
Exposes extends {
actions?: Record<string, unknown>
caseReducers?: Record<string, unknown>
Expand Down Expand Up @@ -160,14 +160,14 @@ export type ReducerCreators<
} & {
[CreatorName in keyof CreatorMap as SliceReducerCreators<
State,
any,
never,
Name,
ReducerPath
>[CreatorMap[CreatorName]]['create'] extends never
? never
: CreatorName]: SliceReducerCreators<
State,
any,
never,
Name,
ReducerPath
>[CreatorMap[CreatorName]]['create']
Expand Down

0 comments on commit a12524a

Please sign in to comment.