@@ -99,25 +99,26 @@ If not provided, the `state.ids` array will not be sorted, and no guarantees are
99
99
100
100
A "entity adapter" instance. An entity adapter is a plain JS object (not a class) containing the generated reducer functions, the original provided ` selectId ` and ` sortComparer ` callbacks, a method to generate an initial "entity state" value, and functions to generate a set of globalized and non-globalized memoized selector functions for this entity type.
101
101
102
- The adapter instance will include the following methods (some TypeScript overloads removed for space ):
102
+ The adapter instance will include the following methods (additional referenced TypeScript types included ):
103
103
104
104
``` ts
105
105
export type EntityId = number | string
106
106
107
- export type Comparer <T > = (a : T , b : T ) => EntityId
107
+ export type Comparer <T > = (a : T , b : T ) => number
108
+
108
109
export type IdSelector <T > = (model : T ) => EntityId
109
110
110
111
export interface DictionaryNum <T > {
111
112
[id : number ]: T | undefined
112
113
}
113
- export abstract class Dictionary <T > implements DictionaryNum <T > {
114
+
115
+ export interface Dictionary <T > extends DictionaryNum <T > {
114
116
[id : string ]: T | undefined
115
117
}
116
118
117
119
export type Update <T > = { id: EntityId ; changes: Partial <T > }
118
- export type EntityMap <T > = (entity : T ) => T
119
120
120
- export type TypeOrPayloadAction <T > = T | PayloadAction < T >
121
+ export type EntityMap <T > = ( entity : T ) => T
121
122
122
123
export interface EntityState <T > {
123
124
ids: EntityId []
@@ -130,54 +131,49 @@ export interface EntityDefinition<T> {
130
131
}
131
132
132
133
export interface EntityStateAdapter <T > {
133
- addOne<S extends EntityState <T >>(state : S , entity : TypeOrPayloadAction <T >): S
134
+ addOne<S extends EntityState <T >>(state : S , entity : T ): S
135
+ addOne<S extends EntityState <T >>(state : S , action : PayloadAction <T >): S
134
136
135
- addMany<S extends EntityState <T >>(
136
- state : S ,
137
- entities : TypeOrPayloadAction <T []>
138
- ): S
137
+ addMany<S extends EntityState <T >>(state : S , entities : T []): S
138
+ addMany<S extends EntityState <T >>(state : S , entities : PayloadAction <T []>): S
139
139
140
- setAll<S extends EntityState <T >>(
141
- state : S ,
142
- entities : TypeOrPayloadAction <T []>
143
- ): S
140
+ setAll<S extends EntityState <T >>(state : S , entities : T []): S
141
+ setAll<S extends EntityState <T >>(state : S , entities : PayloadAction <T []>): S
144
142
145
- removeOne<S extends EntityState <T >>(
146
- state : S ,
147
- key : TypeOrPayloadAction <EntityId >
148
- ): S
143
+ removeOne<S extends EntityState <T >>(state : S , key : EntityId ): S
144
+ removeOne<S extends EntityState <T >>(state : S , key : PayloadAction <EntityId >): S
149
145
146
+ removeMany<S extends EntityState <T >>(state : S , keys : EntityId []): S
150
147
removeMany<S extends EntityState <T >>(
151
148
state : S ,
152
- keys : TypeOrPayloadAction <EntityId []>
149
+ keys : PayloadAction <EntityId []>
153
150
): S
154
151
155
152
removeAll<S extends EntityState <T >>(state : S ): S
156
153
154
+ updateOne<S extends EntityState <T >>(state : S , update : Update <T >): S
157
155
updateOne<S extends EntityState <T >>(
158
156
state : S ,
159
- update : TypeOrPayloadAction <Update <T >>
157
+ update : PayloadAction <Update <T >>
160
158
): S
161
159
160
+ updateMany<S extends EntityState <T >>(state : S , updates : Update <T >[]): S
162
161
updateMany<S extends EntityState <T >>(
163
162
state : S ,
164
- updates : TypeOrPayloadAction <Update <T >[]>
163
+ updates : PayloadAction <Update <T >[]>
165
164
): S
166
165
167
- upsertOne<S extends EntityState <T >>(
168
- state : S ,
169
- entity : TypeOrPayloadAction <T >
170
- ): S
166
+ upsertOne<S extends EntityState <T >>(state : S , entity : T ): S
167
+ upsertOne<S extends EntityState <T >>(state : S , entity : PayloadAction <T >): S
171
168
169
+ upsertMany<S extends EntityState <T >>(state : S , entities : T []): S
172
170
upsertMany<S extends EntityState <T >>(
173
171
state : S ,
174
- entities : TypeOrPayloadAction <T []>
172
+ entities : PayloadAction <T []>
175
173
): S
176
174
177
- map<S extends EntityState <T >>(
178
- state : S ,
179
- map : TypeOrPayloadAction <EntityMap <T >>
180
- ): S
175
+ map<S extends EntityState <T >>(state : S , map : EntityMap <T >): S
176
+ map<S extends EntityState <T >>(state : S , map : PayloadAction <EntityMap <T >>): S
181
177
}
182
178
183
179
export interface EntitySelectors <T , V > {
@@ -369,7 +365,10 @@ console.log(store.getState().books)
369
365
// {ids: ["a"], entities: {a: {id: "a", title: "First (altered)"}}, loading: 'pending' }
370
366
371
367
store .dispatch (
372
- booksReceived ([{ id: ' b' , title: ' Book 3' }, { id: ' c' , title: ' Book 2' }])
368
+ booksReceived ([
369
+ { id: ' b' , title: ' Book 3' },
370
+ { id: ' c' , title: ' Book 2' }
371
+ ])
373
372
)
374
373
375
374
console .log (booksSelectors .selectIds (store .getState ()))
0 commit comments