Skip to content

Commit 00a8685

Browse files
committed
Export Entity types as part of the public API
1 parent ff69954 commit 00a8685

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

etc/redux-toolkit.api.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ export type CaseReducerWithPrepare<State, Action extends PayloadAction> = {
7777
prepare: PrepareAction<Action['payload']>;
7878
};
7979

80+
// @public (undocumented)
81+
export type Comparer<T> = ComparerNum<T> | ComparerStr<T>;
82+
8083
// @public
8184
export type ConfigureEnhancersCallback = (defaultEnhancers: StoreEnhancer[]) => StoreEnhancer[];
8285

@@ -98,6 +101,12 @@ export function createAction<P = void, T extends string = string>(type: T): Payl
98101
// @public
99102
export function createAction<PA extends PrepareAction<any>, T extends string = string>(type: T, prepareAction: PA): PayloadActionCreator<ReturnType<PA>['payload'], T, PA>;
100103

104+
// @public (undocumented)
105+
export function createEntityAdapter<T>(options?: {
106+
selectId?: IdSelector<T>;
107+
sortComparer?: false | Comparer<T>;
108+
}): EntityAdapter<T>;
109+
101110
export { createNextState }
102111

103112
// @public
@@ -122,13 +131,46 @@ export interface CreateSliceOptions<State = any, CR extends SliceCaseReducers<St
122131
reducers: ValidateSliceCaseReducers<State, CR>;
123132
}
124133

134+
// @public (undocumented)
135+
export abstract class Dictionary<T> implements DictionaryNum<T> {
136+
// (undocumented)
137+
[id: string]: T | undefined;
138+
}
139+
125140
export { Draft }
126141

127142
// @public
128143
export interface EnhancedStore<S = any, A extends Action = AnyAction, M extends Middlewares<S> = Middlewares<S>> extends Store<S, A> {
129144
dispatch: DispatchForMiddlewares<M> & Dispatch<A>;
130145
}
131146

147+
// @public (undocumented)
148+
export interface EntityAdapter<T> extends EntityStateAdapter<T> {
149+
// (undocumented)
150+
getInitialState(): EntityState<T>;
151+
// (undocumented)
152+
getInitialState<S extends object>(state: S): EntityState<T> & S;
153+
// (undocumented)
154+
getSelectors(): EntitySelectors<T, EntityState<T>>;
155+
// (undocumented)
156+
getSelectors<V>(selectState: (state: V) => EntityState<T>): EntitySelectors<T, V>;
157+
// (undocumented)
158+
selectId: IdSelector<T>;
159+
// (undocumented)
160+
sortComparer: false | Comparer<T>;
161+
}
162+
163+
// @public (undocumented)
164+
export type EntityMap<T> = (entity: T) => T;
165+
166+
// @public (undocumented)
167+
export interface EntityState<T> {
168+
// (undocumented)
169+
entities: Dictionary<T>;
170+
// (undocumented)
171+
ids: string[] | number[];
172+
}
173+
132174
// @public (undocumented)
133175
export function findNonSerializableValue(value: unknown, path?: ReadonlyArray<string>, isSerializable?: (value: unknown) => boolean, getEntries?: (value: unknown) => [string, any][], ignoredPaths?: string[]): NonSerializableValue | false;
134176

@@ -142,6 +184,9 @@ export function getDefaultMiddleware<S = any, O extends Partial<GetDefaultMiddle
142184
// @public
143185
export function getType<T extends string>(actionCreator: PayloadActionCreator<any, T>): T;
144186

187+
// @public (undocumented)
188+
export type IdSelector<T> = IdSelectorStr<T> | IdSelectorNum<T>;
189+
145190
// @public
146191
export function isPlain(val: any): boolean;
147192

@@ -158,6 +203,9 @@ export type PayloadAction<P = void, T extends string = string, M = never, E = ne
158203
// @public
159204
export type PayloadActionCreator<P = void, T extends string = string, PA extends PrepareAction<P> | void = void> = IfPrepareActionMethodProvided<PA, _ActionCreatorWithPreparedPayload<PA, T>, IsAny<P, ActionCreatorWithPayload<any, T>, IsUnknownOrNonInferrable<P, ActionCreatorWithNonInferrablePayload<T>, IfVoid<P, ActionCreatorWithoutPayload<T>, IfMaybeUndefined<P, ActionCreatorWithOptionalPayload<P, T>, ActionCreatorWithPayload<P, T>>>>>>;
160205

206+
// @public (undocumented)
207+
export type Predicate<T> = (entity: T) => boolean;
208+
161209
// @public
162210
export type PrepareAction<P> = ((...args: any[]) => {
163211
payload: P;
@@ -199,6 +247,9 @@ export type SliceCaseReducers<State> = {
199247

200248
export { ThunkAction }
201249

250+
// @public (undocumented)
251+
export type Update<T> = UpdateStr<T> | UpdateNum<T>;
252+
202253
// @public
203254
export type ValidateSliceCaseReducers<S, ACR extends SliceCaseReducers<S>> = ACR & {
204255
[P in keyof ACR]: ACR[P] extends {

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,15 @@ export {
6161
// types
6262
ActionReducerMapBuilder
6363
} from './mapBuilders'
64+
65+
export { createEntityAdapter } from './entities/create_adapter'
66+
export {
67+
Dictionary,
68+
EntityState,
69+
EntityAdapter,
70+
Update,
71+
EntityMap,
72+
Predicate,
73+
IdSelector,
74+
Comparer
75+
} from './entities/models'

0 commit comments

Comments
 (0)