diff --git a/packages/toolkit/src/createSlice.ts b/packages/toolkit/src/createSlice.ts index 3076d9f9ed..21816d4753 100644 --- a/packages/toolkit/src/createSlice.ts +++ b/packages/toolkit/src/createSlice.ts @@ -840,33 +840,32 @@ function getType(slice: string, actionKey: string): string { return `${slice}/${actionKey}` } -export const reducerCreator: ReducerCreator = - /*#__PURE__*/ { - type: ReducerType.reducer, - create(caseReducer: CaseReducer) { - return Object.assign( - { - // hack so the wrapping function has the same name as the original - // we need to create a wrapper so the `reducerDefinitionType` is not assigned to the original - [caseReducer.name](...args: Parameters) { - return caseReducer(...args) - }, - }[caseReducer.name], - { - _reducerDefinitionType: ReducerType.reducer, - } as const, - ) - }, - handle({ type, reducerName }, reducer, context) { - context - .addCase(type, reducer as any) - .exposeCaseReducer(reducerName, reducer) - .exposeAction(reducerName, createAction(type)) - }, - } +export const reducerCreator: ReducerCreator = { + type: ReducerType.reducer, + create(caseReducer: CaseReducer) { + return Object.assign( + { + // hack so the wrapping function has the same name as the original + // we need to create a wrapper so the `reducerDefinitionType` is not assigned to the original + [caseReducer.name](...args: Parameters) { + return caseReducer(...args) + }, + }[caseReducer.name], + { + _reducerDefinitionType: ReducerType.reducer, + } as const, + ) + }, + handle({ type, reducerName }, reducer, context) { + context + .addCase(type, reducer as any) + .exposeCaseReducer(reducerName, reducer) + .exposeAction(reducerName, createAction(type)) + }, +} export const preparedReducerCreator: ReducerCreator = - /*#__PURE__*/ { + /*@__PURE__*/ { type: ReducerType.reducerWithPrepare, create(prepare, reducer) { return { @@ -883,54 +882,53 @@ export const preparedReducerCreator: ReducerCreator = - /*#__PURE__*/ { - type: ReducerType.asyncThunk, - create: /* @__PURE__ */ (() => { - function asyncThunk( - payloadCreator: AsyncThunkPayloadCreator, - config: AsyncThunkSliceReducerConfig, - ): AsyncThunkSliceReducerDefinition { - return { - _reducerDefinitionType: ReducerType.asyncThunk, - payloadCreator, - ...config, - } - } - asyncThunk.withTypes = () => asyncThunk - return asyncThunk as AsyncThunkCreator - })(), - handle({ type, reducerName }, definition, context) { - const { payloadCreator, fulfilled, pending, rejected, settled, options } = - definition - const thunk = createAsyncThunk(type, payloadCreator, options as any) - context.exposeAction(reducerName, thunk) - - if (fulfilled) { - context.addCase(thunk.fulfilled, fulfilled) - } - if (pending) { - context.addCase(thunk.pending, pending) - } - if (rejected) { - context.addCase(thunk.rejected, rejected) - } - if (settled) { - context.addMatcher(thunk.settled, settled) +export const asyncThunkCreator: ReducerCreator = { + type: ReducerType.asyncThunk, + create: /* @__PURE__ */ (() => { + function asyncThunk( + payloadCreator: AsyncThunkPayloadCreator, + config: AsyncThunkSliceReducerConfig, + ): AsyncThunkSliceReducerDefinition { + return { + _reducerDefinitionType: ReducerType.asyncThunk, + payloadCreator, + ...config, } + } + asyncThunk.withTypes = () => asyncThunk + return asyncThunk as AsyncThunkCreator + })(), + handle({ type, reducerName }, definition, context) { + const { payloadCreator, fulfilled, pending, rejected, settled, options } = + definition + const thunk = createAsyncThunk(type, payloadCreator, options as any) + context.exposeAction(reducerName, thunk) + + if (fulfilled) { + context.addCase(thunk.fulfilled, fulfilled) + } + if (pending) { + context.addCase(thunk.pending, pending) + } + if (rejected) { + context.addCase(thunk.rejected, rejected) + } + if (settled) { + context.addMatcher(thunk.settled, settled) + } - context.exposeCaseReducer(reducerName, { - fulfilled: fulfilled || noop, - pending: pending || noop, - rejected: rejected || noop, - settled: settled || noop, - }) - }, - } + context.exposeCaseReducer(reducerName, { + fulfilled: fulfilled || noop, + pending: pending || noop, + rejected: rejected || noop, + settled: settled || noop, + }) + }, +} function noop() {} -const isCreatorCallback = /*#__PURE__*/ < +const isCreatorCallback = < State, CreatorMap extends Record, >( @@ -1300,4 +1298,4 @@ function wrapSelector>( * * @public */ -export const createSlice = /*#__PURE__*/ buildCreateSlice() +export const createSlice = /*@__PURE__*/ buildCreateSlice() diff --git a/packages/toolkit/src/entities/slice_creator.ts b/packages/toolkit/src/entities/slice_creator.ts index 1d1de5f3b9..addcd49284 100644 --- a/packages/toolkit/src/entities/slice_creator.ts +++ b/packages/toolkit/src/entities/slice_creator.ts @@ -16,7 +16,7 @@ import type { } from './models' import { capitalize } from './utils' -export const entityMethodsCreatorType = /*#__PURE__*/ Symbol() +export const entityMethodsCreatorType = /*@__PURE__*/ Symbol() type DefaultPlural = Single extends '' ? '' @@ -104,7 +104,7 @@ declare module '@reduxjs/toolkit' { } } -/*#__PURE__*/ export function createEntityMethods< +export function createEntityMethods< T, Id extends EntityId, State = EntityState, @@ -181,7 +181,7 @@ declare module '@reduxjs/toolkit' { export const entityMethodsCreator: ReducerCreator< typeof entityMethodsCreatorType -> = /*#__PURE__*/ { +> = { type: entityMethodsCreatorType, create: createEntityMethods, }