Skip to content

Commit

Permalink
Manually dedupe all RTK imports in RTKQ core
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Sep 24, 2023
1 parent 9a7803d commit 3b9722d
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 26 deletions.
6 changes: 6 additions & 0 deletions packages/toolkit/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This must remain here so that the `mangleErrors.cjs` build script
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from './formatProdErrorMessage'

export * from 'redux'
export {
produce as createNextState,
Expand Down Expand Up @@ -207,3 +211,5 @@ export { combineSlices } from './combineSlices'
export type { WithSlice } from './combineSlices'

export type { ExtractDispatchExtensions as TSHelpersExtractDispatchExtensions } from './tsHelpers'

export { formatProdErrorMessage } from './formatProdErrorMessage'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAsyncThunkAction, isFulfilled } from '@reduxjs/toolkit'
import { isAsyncThunkAction, isFulfilled } from '../rtkImports'
import type { UnknownAction } from 'redux'
import type { ThunkDispatch } from 'redux-thunk'
import type { BaseQueryFn, BaseQueryMeta } from '../../baseQueryTypes'
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/core/buildMiddleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
ThunkDispatch,
UnknownAction,
} from '@reduxjs/toolkit'
import { isAction, createAction } from '@reduxjs/toolkit'
import { isAction, createAction } from '../rtkImports'

import type {
EndpointDefinitions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isAnyOf, isFulfilled, isRejectedWithValue } from '@reduxjs/toolkit'
import { isAnyOf, isFulfilled, isRejectedWithValue } from '../rtkImports'

import type { FullTagDescription } from '../../endpointDefinitions'
import { calculateProvidedBy } from '../../endpointDefinitions'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isPending, isRejected, isFulfilled } from '@reduxjs/toolkit'
import { isPending, isRejected, isFulfilled } from '../rtkImports'
import type {
BaseQueryError,
BaseQueryFn,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/core/buildSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createNextState, createSelector } from '@reduxjs/toolkit'
import { createNextState, createSelector } from './rtkImports'
import type {
MutationSubState,
QuerySubState,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/core/buildSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
isRejectedWithValue,
createNextState,
prepareAutoBatched,
} from '@reduxjs/toolkit'
} from './rtkImports'
import type {
QuerySubstateIdentifier,
QuerySubState,
Expand Down
5 changes: 3 additions & 2 deletions packages/toolkit/src/query/core/buildThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ import {
isPending,
isRejected,
isRejectedWithValue,
} from '@reduxjs/toolkit'
createAsyncThunk,
SHOULD_AUTOBATCH,
} from './rtkImports'
import type { Patch } from 'immer'
import { isDraftable, produceWithPatches } from 'immer'
import type { ThunkAction, ThunkDispatch, AsyncThunk } from '@reduxjs/toolkit'
import { createAsyncThunk, SHOULD_AUTOBATCH } from '@reduxjs/toolkit'

import { HandledError } from '../HandledError'

Expand Down
24 changes: 24 additions & 0 deletions packages/toolkit/src/query/core/rtkImports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file exists to consolidate all of the imports from the `@reduxjs/toolkit` package.
// ESBuild does not de-duplicate imports, so this file is used to ensure that each method
// imported is only listed once, and there's only one mention of the `@reduxjs/toolkit` package.

export {
createAction,
createSlice,
createSelector,
createAsyncThunk,
combineReducers,
createNextState,
isAnyOf,
isAllOf,
isAction,
isPending,
isRejected,
isFulfilled,
isRejectedWithValue,
isAsyncThunkAction,
prepareAutoBatched,
SHOULD_AUTOBATCH,
isPlainObject,
nanoid,
} from '@reduxjs/toolkit'
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/core/setupListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
ThunkDispatch,
ActionCreatorWithoutPayload, // Workaround for API-Extractor
} from '@reduxjs/toolkit'
import { createAction } from '@reduxjs/toolkit'
import { createAction } from './rtkImports'

export const onFocus = /* @__PURE__ */ createAction('__rtkq/focused')
export const onFocusLost = /* @__PURE__ */ createAction('__rtkq/unfocused')
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/createApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
EndpointDefinitions,
} from './endpointDefinitions'
import { DefinitionType, isQueryDefinition } from './endpointDefinitions'
import { nanoid } from '@reduxjs/toolkit'
import { nanoid } from './core/rtkImports'
import type { UnknownAction } from '@reduxjs/toolkit'
import type { NoInfer } from './tsHelpers'
import { defaultMemoize } from 'reselect'
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/defaultSerializeQueryArgs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { QueryCacheKey } from './core/apiState'
import type { EndpointDefinition } from './endpointDefinitions'
import { isPlainObject } from '@reduxjs/toolkit'
import { isPlainObject } from './core/rtkImports'

const cache: WeakMap<any, string> | undefined = WeakMap
? new WeakMap()
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/fetchBaseQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { joinUrls } from './utils'
import { isPlainObject } from '@reduxjs/toolkit'
import { isPlainObject } from './core/rtkImports'
import type { BaseQueryApi, BaseQueryFn } from './baseQueryTypes'
import type { MaybePromise, Override } from './tsHelpers'

Expand Down
4 changes: 4 additions & 0 deletions packages/toolkit/src/query/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This must remain here so that the `mangleErrors.cjs` build script
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'

export type {
QuerySubState,
SubscriptionOptions,
Expand Down
18 changes: 5 additions & 13 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,29 @@ import type {
SubscriptionOptions,
QueryKeys,
RootState,
} from '@reduxjs/toolkit/query'
import type {
EndpointDefinitions,
MutationDefinition,
QueryDefinition,
QueryArgFrom,
ResultTypeFrom,
} from '@reduxjs/toolkit/query'
import type {
QueryResultSelectorResult,
MutationResultSelectorResult,
SkipToken,
} from '@reduxjs/toolkit/query'
import type {
QueryActionCreatorResult,
MutationActionCreatorResult,
} from '@reduxjs/toolkit/query'
import type { SerializeQueryArgs } from '@reduxjs/toolkit/query'
import { shallowEqual } from 'react-redux'
import type { Api, ApiContext } from '@reduxjs/toolkit/query'
import type {
SerializeQueryArgs,
Api,
ApiContext,
TSHelpersId,
TSHelpersNoInfer,
TSHelpersOverride,
} from '@reduxjs/toolkit/query'
import type {
ApiEndpointMutation,
ApiEndpointQuery,
CoreModule,
PrefetchOptions,
} from '@reduxjs/toolkit/query'

import { shallowEqual } from 'react-redux'
import type { ReactHooksModuleOptions } from './module'
import { useStableQueryArgs } from './useSerializedStableValue'
import type { UninitializedValue } from './constants'
Expand Down
4 changes: 4 additions & 0 deletions packages/toolkit/src/query/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// This must remain here so that the `mangleErrors.cjs` build script
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'

import { coreModule, buildCreateApi } from '@reduxjs/toolkit/query'
import { reactHooksModule, reactHooksModuleName } from './module'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isPlainObject as _iPO } from '@reduxjs/toolkit'
import { isPlainObject as _iPO } from '../core/rtkImports'

// remove type guard
const isPlainObject: (_: any) => boolean = _iPO
Expand Down
3 changes: 3 additions & 0 deletions packages/toolkit/src/react/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This must remain here so that the `mangleErrors.cjs` build script
// does not have to import this into each source file it rewrites.
import { formatProdErrorMessage } from '@reduxjs/toolkit'
export * from '@reduxjs/toolkit'

export { createDynamicMiddleware } from '../dynamicMiddleware/react'

0 comments on commit 3b9722d

Please sign in to comment.