1
+ import { PayloadAction } from '../createAction'
2
+
1
3
export type ComparerStr < T > = ( a : T , b : T ) => string
2
4
export type ComparerNum < T > = ( a : T , b : T ) => number
3
5
@@ -32,6 +34,8 @@ export type Predicate<T> = (entity: T) => boolean
32
34
33
35
export type EntityMap < T > = ( entity : T ) => T
34
36
37
+ export type TypeOrPayloadAction < T > = T | PayloadAction < T >
38
+
35
39
export interface EntityState < T > {
36
40
ids : string [ ] | number [ ]
37
41
entities : Dictionary < T >
@@ -43,27 +47,61 @@ export interface EntityDefinition<T> {
43
47
}
44
48
45
49
export interface EntityStateAdapter < T > {
46
- addOne < S extends EntityState < T > > ( entity : T , state : S ) : S
47
- addMany < S extends EntityState < T > > ( entities : T [ ] , state : S ) : S
48
-
49
- setAll < S extends EntityState < T > > ( entities : T [ ] , state : S ) : S
50
-
51
- removeOne < S extends EntityState < T > > ( key : string , state : S ) : S
52
- removeOne < S extends EntityState < T > > ( key : number , state : S ) : S
53
-
54
- removeMany < S extends EntityState < T > > ( keys : string [ ] , state : S ) : S
55
- removeMany < S extends EntityState < T > > ( keys : number [ ] , state : S ) : S
56
- removeMany < S extends EntityState < T > > ( predicate : Predicate < T > , state : S ) : S
50
+ addOne < S extends EntityState < T > > ( state : S , entity : TypeOrPayloadAction < T > ) : S
51
+ addMany < S extends EntityState < T > > (
52
+ state : S ,
53
+ entities : TypeOrPayloadAction < T [ ] >
54
+ ) : S
55
+
56
+ setAll < S extends EntityState < T > > (
57
+ state : S ,
58
+ entities : TypeOrPayloadAction < T [ ] >
59
+ ) : S
60
+
61
+ removeOne < S extends EntityState < T > > (
62
+ state : S ,
63
+ key : TypeOrPayloadAction < string >
64
+ ) : S
65
+ removeOne < S extends EntityState < T > > (
66
+ state : S ,
67
+ key : TypeOrPayloadAction < number >
68
+ ) : S
69
+
70
+ removeMany < S extends EntityState < T > > (
71
+ state : S ,
72
+ keys : TypeOrPayloadAction < string [ ] >
73
+ ) : S
74
+ removeMany < S extends EntityState < T > > (
75
+ state : S ,
76
+ keys : TypeOrPayloadAction < number [ ] >
77
+ ) : S
78
+ /** @deprecated Should not pass functions inside of Redux actions */
79
+ removeMany < S extends EntityState < T > > ( state : S , predicate : Predicate < T > ) : S
57
80
58
81
removeAll < S extends EntityState < T > > ( state : S ) : S
59
82
60
- updateOne < S extends EntityState < T > > ( update : Update < T > , state : S ) : S
61
- updateMany < S extends EntityState < T > > ( updates : Update < T > [ ] , state : S ) : S
62
-
63
- upsertOne < S extends EntityState < T > > ( entity : T , state : S ) : S
64
- upsertMany < S extends EntityState < T > > ( entities : T [ ] , state : S ) : S
65
-
66
- map < S extends EntityState < T > > ( map : EntityMap < T > , state : S ) : S
83
+ updateOne < S extends EntityState < T > > (
84
+ state : S ,
85
+ update : TypeOrPayloadAction < Update < T > >
86
+ ) : S
87
+ updateMany < S extends EntityState < T > > (
88
+ state : S ,
89
+ updates : TypeOrPayloadAction < Update < T > [ ] >
90
+ ) : S
91
+
92
+ upsertOne < S extends EntityState < T > > (
93
+ state : S ,
94
+ entity : TypeOrPayloadAction < T >
95
+ ) : S
96
+ upsertMany < S extends EntityState < T > > (
97
+ state : S ,
98
+ entities : TypeOrPayloadAction < T [ ] >
99
+ ) : S
100
+
101
+ map < S extends EntityState < T > > (
102
+ state : S ,
103
+ map : TypeOrPayloadAction < EntityMap < T > >
104
+ ) : S
67
105
}
68
106
69
107
export interface EntitySelectors < T , V > {
0 commit comments