File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -157,6 +157,23 @@ export function commandDispatchTest(
157
157
expect ( data ) . toBe ( hero ) ;
158
158
} ) ;
159
159
160
+ it ( '#add(hero) dispatches SAVE_ADD pessimistically with partial hero' , ( ) => {
161
+ const hero : Partial < Hero > = { name : 'test' } ;
162
+ dispatcher . add ( hero ) ;
163
+ const { entityOp, isOptimistic, data } = dispatchedAction ( ) . payload ;
164
+ expect ( entityOp ) . toBe ( EntityOp . SAVE_ADD_ONE ) ;
165
+ expect ( isOptimistic ) . toBe ( false ) ;
166
+ expect ( data ) . toBe ( hero ) ;
167
+
168
+ testStore . dispatch . calls . reset ( ) ;
169
+
170
+ dispatcher . add ( hero , { isOptimistic : false } ) ;
171
+ const specificallyPessimistic = dispatchedAction ( ) . payload ;
172
+ expect ( specificallyPessimistic . entityOp ) . toBe ( EntityOp . SAVE_ADD_ONE ) ;
173
+ expect ( specificallyPessimistic . isOptimistic ) . toBe ( false ) ;
174
+ expect ( specificallyPessimistic . data ) . toBe ( hero ) ;
175
+ } ) ;
176
+
160
177
it ( '#delete(42) can dispatch SAVE_DELETE pessimistically for the id:42' , ( ) => {
161
178
dispatcher . delete ( 42 , { isOptimistic : false } ) ; // optimistic by default
162
179
const { entityOp, isOptimistic, data } = dispatchedAction ( ) . payload ;
Original file line number Diff line number Diff line change @@ -11,6 +11,14 @@ export interface EntityServerCommands<T> {
11
11
* @returns A terminating Observable of the entity
12
12
* after server reports successful save or the save error.
13
13
*/
14
+ add (
15
+ entity : Partial < T > ,
16
+ options ?: EntityActionOptions & { isOptimistic ?: false }
17
+ ) : Observable < T > ;
18
+ add (
19
+ entity : T ,
20
+ options : EntityActionOptions & { isOptimistic : true }
21
+ ) : Observable < T > ;
14
22
add ( entity : T , options ?: EntityActionOptions ) : Observable < T > ;
15
23
16
24
/**
@@ -101,11 +109,11 @@ export interface EntityServerCommands<T> {
101
109
* after server reports successful query or the query error.
102
110
* @see getWithQuery
103
111
*/
104
- loadWithQuery ( queryParams : QueryParams | string ,
105
- options ?: EntityActionOptions
112
+ loadWithQuery (
113
+ queryParams : QueryParams | string ,
114
+ options ?: EntityActionOptions
106
115
) : Observable < T [ ] > ;
107
116
108
-
109
117
/**
110
118
* Dispatch action to save the updated entity (or partial entity) in remote storage.
111
119
* The update entity may be partial (but must have its key)
You can’t perform that action at this time.
0 commit comments