Skip to content

Commit ad96041

Browse files
committed
feat!: rename RootState type to ApiRootState
1 parent affa29d commit ad96041

12 files changed

Lines changed: 54 additions & 42 deletions

File tree

packages/toolkit/src/query/core/apiState.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,19 @@ export type MutationState<D extends EndpointDefinitions> = {
370370
[requestId: string]: MutationSubState<D[string]> | undefined
371371
}
372372

373-
export type RootState<
373+
/**
374+
* Get the root state type for an RTK Query API slice.
375+
*
376+
* **Note**: This type was previously named **`RootState`**.
377+
*
378+
* @template Definitions - Endpoint definitions for the API.
379+
* @template TagTypes - Tag types used by the API.
380+
* @template ReducerPath - The **`reducerPath`** key the API reducer is mounted under.
381+
*
382+
* @since 3.0.0
383+
* @public
384+
*/
385+
export type ApiRootState<
374386
Definitions extends EndpointDefinitions,
375387
TagTypes extends string,
376388
ReducerPath extends string,

packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
DefinitionType,
1010
} from '../../endpointDefinitions'
1111
import { isAnyQueryDefinition } from '../../endpointDefinitions'
12-
import type { QueryCacheKey, RootState } from '../apiState'
12+
import type { QueryCacheKey, ApiRootState } from '../apiState'
1313
import type {
1414
MutationResultSelectorResult,
1515
QueryResultSelectorResult,
@@ -78,7 +78,7 @@ type LifecycleApi<ReducerPath extends string = string> = {
7878
/**
7979
* A method to get the current state
8080
*/
81-
getState(): RootState<any, any, ReducerPath>
81+
getState(): ApiRootState<any, any, ReducerPath>
8282
/**
8383
* `extra` as provided as `thunk.extraArgument` to the `configureStore` `getDefaultMiddleware` option.
8484
*/

packages/toolkit/src/query/core/buildMiddleware/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
EndpointDefinitions,
99
FullTagDescription,
1010
} from '../../endpointDefinitions'
11-
import type { QueryStatus, QuerySubState, RootState } from '../apiState'
11+
import type { QueryStatus, QuerySubState, ApiRootState } from '../apiState'
1212
import type { QueryThunkArg } from '../buildThunks'
1313
import { createAction, isAction } from '../rtkImports'
1414
import { buildBatchedActionsHandler } from './batchActions'
@@ -68,7 +68,7 @@ export function buildMiddleware<
6868

6969
const middleware: Middleware<
7070
{},
71-
RootState<Definitions, string, ReducerPath>,
71+
ApiRootState<Definitions, string, ReducerPath>,
7272
ThunkDispatch<any, any, UnknownAction>
7373
> = (mwApi) => {
7474
let initialized = false

packages/toolkit/src/query/core/buildMiddleware/types.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type {
1616
import type {
1717
QueryStatus,
1818
QuerySubState,
19-
RootState,
19+
ApiRootState,
2020
SubscriptionInternalState,
2121
SubscriptionState,
2222
} from '../apiState'
@@ -83,7 +83,7 @@ export interface BuildMiddlewareInput<
8383

8484
export type SubMiddlewareApi = MiddlewareAPI<
8585
ThunkDispatch<any, any, UnknownAction>,
86-
RootState<EndpointDefinitions, string, string>
86+
ApiRootState<EndpointDefinitions, string, string>
8787
>
8888

8989
export interface BuildSubMiddlewareInput
@@ -99,15 +99,15 @@ export interface BuildSubMiddlewareInput
9999
selectors: AllSelectors
100100
mwApi: MiddlewareAPI<
101101
ThunkDispatch<any, any, UnknownAction>,
102-
RootState<EndpointDefinitions, string, string>
102+
ApiRootState<EndpointDefinitions, string, string>
103103
>
104104
}
105105

106106
export type SubMiddlewareBuilder = (
107107
input: BuildSubMiddlewareInput,
108108
) => Middleware<
109109
{},
110-
RootState<EndpointDefinitions, string, string>,
110+
ApiRootState<EndpointDefinitions, string, string>,
111111
ThunkDispatch<any, any, UnknownAction>
112112
>
113113

@@ -116,7 +116,7 @@ type MwNext = Parameters<ReturnType<Middleware>>[0]
116116
export type ApiMiddlewareInternalHandler<Return = void> = (
117117
action: Action,
118118
mwApi: SubMiddlewareApi & { next: MwNext },
119-
prevState: RootState<EndpointDefinitions, string, string>,
119+
prevState: ApiRootState<EndpointDefinitions, string, string>,
120120
) => Return
121121

122122
export type InternalHandlerBuilder<ReturnType = void> = (

packages/toolkit/src/query/core/buildSelectors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import type {
2323
QueryState,
2424
QuerySubState,
2525
RequestStatusFlags,
26-
RootState as _RootState,
26+
ApiRootState as _RootState,
2727
QueryStatus,
2828
} from './apiState'
2929
import { STATUS_UNINITIALIZED, getRequestStatusFlags } from './apiState'

packages/toolkit/src/query/core/buildThunks.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
import { HandledError } from '../HandledError'
4343
import type { UnwrapPromise } from '../tsHelpers'
4444
import type {
45-
RootState,
45+
ApiRootState,
4646
QueryKeys,
4747
QuerySubstateIdentifier,
4848
InfiniteData,
@@ -355,7 +355,7 @@ export function buildThunks<
355355
catchSchemaFailure: SchemaFailureConverter<BaseQuery> | undefined
356356
skipSchemaValidation: boolean | SchemaType[] | undefined
357357
}) {
358-
type State = RootState<any, string, ReducerPath>
358+
type State = ApiRootState<any, string, ReducerPath>
359359

360360
const patchQueryData: PatchQueryDataThunk<EndpointDefinitions, State> =
361361
(endpointName, arg, patches, updateProvided) => (dispatch, getState) => {
@@ -377,7 +377,7 @@ export function buildThunks<
377377

378378
const newValue = api.endpoints[endpointName].select(arg)(
379379
// Work around TS 4.1 mismatch
380-
getState() as RootState<any, any, any>,
380+
getState() as ApiRootState<any, any, any>,
381381
)
382382

383383
const providedTags = calculateProvidedBy(
@@ -411,7 +411,7 @@ export function buildThunks<
411411

412412
const currentState = endpointDefinition.select(arg)(
413413
// Work around TS 4.1 mismatch
414-
getState() as RootState<any, any, any>,
414+
getState() as ApiRootState<any, any, any>,
415415
)
416416

417417
const ret: PatchCollection = {
@@ -494,7 +494,7 @@ export function buildThunks<
494494
const executeEndpoint: AsyncThunkPayloadCreator<
495495
ThunkResult,
496496
QueryThunkArg | MutationThunkArg | InfiniteQueryThunkArg<any>,
497-
ThunkApiMetaConfig & { state: RootState<any, string, ReducerPath> }
497+
ThunkApiMetaConfig & { state: ApiRootState<any, string, ReducerPath> }
498498
> = async (
499499
arg,
500500
{
@@ -884,7 +884,7 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
884884

885885
function isForcedQuery(
886886
arg: QueryThunkArg,
887-
state: RootState<any, string, ReducerPath>,
887+
state: ApiRootState<any, string, ReducerPath>,
888888
) {
889889
const requestState = selectors.selectQueryEntry(state, arg.queryCacheKey)
890890
const baseFetchOnMountOrArgChange =
@@ -910,7 +910,7 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
910910
const generatedQueryThunk = createAsyncThunk<
911911
ThunkResult,
912912
ThunkArgType,
913-
ThunkApiMetaConfig & { state: RootState<any, string, ReducerPath> }
913+
ThunkApiMetaConfig & { state: ApiRootState<any, string, ReducerPath> }
914914
>(`${reducerPath}/executeQuery`, executeEndpoint, {
915915
getPendingMeta({ arg }) {
916916
const endpointDefinition = endpointDefinitions[arg.endpointName]
@@ -984,7 +984,7 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
984984
const mutationThunk = createAsyncThunk<
985985
ThunkResult,
986986
MutationThunkArg,
987-
ThunkApiMetaConfig & { state: RootState<any, string, ReducerPath> }
987+
ThunkApiMetaConfig & { state: ApiRootState<any, string, ReducerPath> }
988988
>(`${reducerPath}/executeMutation`, executeEndpoint, {
989989
getPendingMeta() {
990990
return addShouldAutoBatch({ startedTimeStamp: Date.now() })

packages/toolkit/src/query/core/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type {
1313
QueryCacheKey,
1414
QueryKeys,
1515
QuerySubState,
16-
RootState,
16+
ApiRootState,
1717
SubscriptionOptions,
1818
} from './apiState'
1919
export type {

packages/toolkit/src/query/core/module.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type {
3434
CombinedState,
3535
MutationKeys,
3636
QueryKeys,
37-
RootState,
37+
ApiRootState,
3838
} from './apiState'
3939
import type {
4040
BuildInitiateApiEndpointMutation,
@@ -157,7 +157,7 @@ export interface ApiModules<
157157
*/
158158
middleware: Middleware<
159159
{},
160-
RootState<Definitions, string, ReducerPath>,
160+
ApiRootState<Definitions, string, ReducerPath>,
161161
ThunkDispatch<any, any, UnknownAction>
162162
>
163163
/**
@@ -274,7 +274,7 @@ export interface ApiModules<
274274
*/
275275
updateQueryData: UpdateQueryDataThunk<
276276
Definitions,
277-
RootState<Definitions, string, ReducerPath>
277+
ApiRootState<Definitions, string, ReducerPath>
278278
>
279279

280280
/**
@@ -298,7 +298,7 @@ export interface ApiModules<
298298
*/
299299
upsertQueryData: UpsertQueryDataThunk<
300300
Definitions,
301-
RootState<Definitions, string, ReducerPath>
301+
ApiRootState<Definitions, string, ReducerPath>
302302
>
303303
/**
304304
* A Redux thunk that applies a JSON diff/patch array to the cached data for a given query result. This immediately updates the Redux state with those changes.
@@ -328,7 +328,7 @@ export interface ApiModules<
328328
*/
329329
patchQueryData: PatchQueryDataThunk<
330330
Definitions,
331-
RootState<Definitions, string, ReducerPath>
331+
ApiRootState<Definitions, string, ReducerPath>
332332
>
333333

334334
/**
@@ -381,7 +381,7 @@ export interface ApiModules<
381381
* Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update.
382382
*/
383383
selectInvalidatedBy: (
384-
state: RootState<Definitions, string, ReducerPath>,
384+
state: ApiRootState<Definitions, string, ReducerPath>,
385385
tags: ReadonlyArray<TagDescription<TagTypes> | null | undefined>,
386386
) => Array<{
387387
endpointName: string
@@ -395,7 +395,7 @@ export interface ApiModules<
395395
* Can be used for mutations that want to do optimistic updates instead of invalidating a set of tags, but don't know exactly what they need to update.
396396
*/
397397
selectCachedArgsForQuery: <QueryName extends AllQueryKeys<Definitions>>(
398-
state: RootState<Definitions, string, ReducerPath>,
398+
state: ApiRootState<Definitions, string, ReducerPath>,
399399
queryName: QueryName,
400400
) => Array<QueryArgFromAnyQuery<Definitions[QueryName]>>
401401
}

packages/toolkit/src/query/endpointDefinitions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import type {
2525
InfiniteData,
2626
InfiniteQueryConfigOptions,
2727
QuerySubState,
28-
RootState,
28+
ApiRootState,
2929
} from './core/index'
3030
import type { SerializeQueryArgs } from './defaultSerializeQueryArgs'
3131
import type { NEVER } from './fakeBaseQuery'
@@ -855,7 +855,7 @@ export interface QueryExtraOptions<
855855
forceRefetch?(params: {
856856
currentArg: QueryArg | undefined
857857
previousArg: QueryArg | undefined
858-
state: RootState<any, any, string>
858+
state: ApiRootState<any, any, string>
859859
endpointState?: QuerySubState<any>
860860
}): boolean
861861

packages/toolkit/src/query/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type {
77
QueryCacheKey,
88
QueryKeys,
99
QuerySubState,
10-
RootState,
10+
ApiRootState,
1111
SubscriptionOptions,
1212
} from './core/apiState'
1313
export { QueryStatus } from './core/apiState'

0 commit comments

Comments
 (0)