Skip to content

Commit

Permalink
Undo renaming of Id to Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
aryaemami59 committed Jun 19, 2024
1 parent 1b47971 commit 51e9cd5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
12 changes: 6 additions & 6 deletions packages/toolkit/src/combineSlices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Reducer, StateFromReducersMapObject, UnknownAction } from 'redux'
import { combineReducers } from 'redux'
import { nanoid } from './nanoid'
import type {
Id,
NonUndefined,
Simplify,
Tail,
UnionToIntersection,
WithOptionalProp,
Expand Down Expand Up @@ -81,7 +81,7 @@ export interface CombinedSliceReducer<
*/
withLazyLoadedSlices<Lazy = {}>(): CombinedSliceReducer<
InitialState,
Simplify<DeclaredState & Partial<Lazy>>
Id<DeclaredState & Partial<Lazy>>
>

/**
Expand All @@ -96,10 +96,10 @@ export interface CombinedSliceReducer<
* ```
*
*/
inject<Sl extends Simplify<ExistingSliceLike<DeclaredState>>>(
inject<Sl extends Id<ExistingSliceLike<DeclaredState>>>(
slice: Sl,
config?: InjectConfig,
): CombinedSliceReducer<InitialState, Simplify<DeclaredState & WithSlice<Sl>>>
): CombinedSliceReducer<InitialState, Id<DeclaredState & WithSlice<Sl>>>

/**
* Inject a slice.
Expand All @@ -121,7 +121,7 @@ export interface CombinedSliceReducer<
config?: InjectConfig,
): CombinedSliceReducer<
InitialState,
Simplify<DeclaredState & WithSlice<SliceLike<ReducerPath, State>>>
Id<DeclaredState & WithSlice<SliceLike<ReducerPath, State>>>
>

/**
Expand Down Expand Up @@ -363,7 +363,7 @@ const noopReducer: Reducer<Record<string, any>> = (state = {}) => state

export function combineSlices<Slices extends Array<AnySliceLike | ReducerMap>>(
...slices: Slices
): CombinedSliceReducer<Simplify<InitialState<Slices>>> {
): CombinedSliceReducer<Id<InitialState<Slices>>> {
const reducerMap = Object.fromEntries<Reducer>(getReducers(slices))

const getReducer = () =>
Expand Down
4 changes: 2 additions & 2 deletions packages/toolkit/src/createAsyncThunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { isAnyOf } from './matchers'
import { nanoid } from './nanoid'
import type {
FallbackIfUnknown,
Id,
IsAny,
IsUnknown,
SafePromise,
Simplify,
} from './tsHelpers'

export type BaseThunkAPI<
Expand Down Expand Up @@ -428,7 +428,7 @@ export type AsyncThunk<
typePrefix: string
}

export type OverrideThunkApiConfigs<OldConfig, NewConfig> = Simplify<
export type OverrideThunkApiConfigs<OldConfig, NewConfig> = Id<
NewConfig & Omit<OldConfig, keyof NewConfig>
>

Expand Down
18 changes: 8 additions & 10 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
import { createReducer } from './createReducer'
import type { ActionReducerMapBuilder, TypedActionCreator } from './mapBuilders'
import { executeReducerBuilderCallback } from './mapBuilders'
import type { Simplify, TypeGuard } from './tsHelpers'
import type { Id, TypeGuard } from './tsHelpers'
import { emplace } from './utils'

const asyncThunkSymbol = /* @__PURE__ */ Symbol.for(
Expand Down Expand Up @@ -90,21 +90,21 @@ export interface Slice<
/**
* Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter)
*/
getSelectors(): Simplify<SliceDefinedSelectors<State, Selectors, State>>
getSelectors(): Id<SliceDefinedSelectors<State, Selectors, State>>

/**
* Get globalised slice selectors (`selectState` callback is expected to receive first parameter and return slice state)
*/
getSelectors<RootState>(
selectState: (rootState: RootState) => State,
): Simplify<SliceDefinedSelectors<State, Selectors, RootState>>
): Id<SliceDefinedSelectors<State, Selectors, RootState>>

/**
* Selectors that assume the slice's state is `rootState[slice.reducerPath]` (which is usually the case)
*
* Equivalent to `slice.getSelectors((state: RootState) => state[slice.reducerPath])`.
*/
get selectors(): Simplify<
get selectors(): Id<
SliceDefinedSelectors<State, Selectors, { [K in ReducerPath]: State }>
>

Expand Down Expand Up @@ -148,23 +148,21 @@ type InjectedSlice<
/**
* Get localised slice selectors (expects to be called with *just* the slice's state as the first parameter)
*/
getSelectors(): Simplify<
SliceDefinedSelectors<State, Selectors, State | undefined>
>
getSelectors(): Id<SliceDefinedSelectors<State, Selectors, State | undefined>>

/**
* Get globalised slice selectors (`selectState` callback is expected to receive first parameter and return slice state)
*/
getSelectors<RootState>(
selectState: (rootState: RootState) => State | undefined,
): Simplify<SliceDefinedSelectors<State, Selectors, RootState>>
): Id<SliceDefinedSelectors<State, Selectors, RootState>>

/**
* Selectors that assume the slice's state is `rootState[slice.name]` (which is usually the case)
*
* Equivalent to `slice.getSelectors((state: RootState) => state[slice.name])`.
*/
get selectors(): Simplify<
get selectors(): Id<
SliceDefinedSelectors<
State,
Selectors,
Expand Down Expand Up @@ -509,7 +507,7 @@ type ActionCreatorForCaseReducer<CR, Type extends string> = CR extends (
type SliceDefinedCaseReducers<CaseReducers extends SliceCaseReducers<any>> = {
[Type in keyof CaseReducers]: CaseReducers[Type] extends infer Definition
? Definition extends AsyncThunkSliceReducerDefinition<any, any, any>
? Simplify<
? Id<
Pick<
Required<Definition>,
'fulfilled' | 'rejected' | 'pending' | 'settled'
Expand Down
10 changes: 5 additions & 5 deletions packages/toolkit/src/entities/models.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Draft } from 'immer'
import type { PayloadAction } from '../createAction'
import type { CastAny, Simplify } from '../tsHelpers'
import type { CastAny, Id } from '../tsHelpers'
import type { UncheckedIndexedAccess } from '../uncheckedindexed.js'
import type { GetSelectorsOptions } from './state_selectors'

Expand Down Expand Up @@ -158,12 +158,12 @@ export interface EntityStateAdapter<T, Id extends EntityId> {
/**
* @public
*/
export interface EntitySelectors<T, V, Id extends EntityId> {
selectIds: (state: V) => Id[]
selectEntities: (state: V) => Record<Id, T>
export interface EntitySelectors<T, V, IdType extends EntityId> {
selectIds: (state: V) => IdType[]
selectEntities: (state: V) => Record<IdType, T>
selectAll: (state: V) => T[]
selectTotal: (state: V) => number
selectById: (state: V, id: Id) => Simplify<UncheckedIndexedAccess<T>>
selectById: (state: V, id: IdType) => Id<UncheckedIndexedAccess<T>>
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/tsHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export type Matcher<T> = HasMatchFunction<T> | TypeGuard<T>
export type ActionFromMatcher<M extends Matcher<any>> =
M extends Matcher<infer T> ? T : never

export type Simplify<T> = { [K in keyof T]: T[K] } & {}
export type Id<T> = { [K in keyof T]: T[K] } & {}

export type Tail<T extends any[]> = T extends [any, ...infer Tail]
? Tail
Expand Down

0 comments on commit 51e9cd5

Please sign in to comment.