File tree 4 files changed +58
-4
lines changed
4 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ export function bindAsObject(
93
93
94
94
return ( reset ?: ResetOption ) => {
95
95
unsubscribe ( )
96
- if ( reset !== false ) {
96
+ if ( reset ) {
97
97
const value = typeof reset === 'function' ? reset ( ) : null
98
98
target . value = value
99
99
}
@@ -209,7 +209,7 @@ export function bindAsArray(
209
209
removeChildRemovedListener ( )
210
210
removeChildChangedListener ( )
211
211
removeChildMovedListener ( )
212
- if ( reset !== false ) {
212
+ if ( reset ) {
213
213
const value = typeof reset === 'function' ? reset ( ) : [ ]
214
214
// we trust the user to return an array
215
215
target . value = value as any
Original file line number Diff line number Diff line change @@ -418,7 +418,7 @@ export function bindCollection<T = unknown>(
418
418
419
419
return ( reset ?: FirestoreRefOptions [ 'reset' ] ) => {
420
420
stopOnSnapshot ( )
421
- if ( reset !== false ) {
421
+ if ( reset ) {
422
422
const value = typeof reset === 'function' ? reset ( ) : [ ]
423
423
ops . set ( target , key , value )
424
424
}
@@ -475,7 +475,7 @@ export function bindDocument<T>(
475
475
476
476
return ( reset ?: FirestoreRefOptions [ 'reset' ] ) => {
477
477
stopOnSnapshot ( )
478
- if ( reset !== false ) {
478
+ if ( reset ) {
479
479
const value = typeof reset === 'function' ? reset ( ) : null
480
480
ops . set ( target , key , value )
481
481
}
Original file line number Diff line number Diff line change @@ -176,6 +176,33 @@ describe('Database lists', () => {
176
176
await wrapper . unmount ( )
177
177
expect ( data . value ) . toEqual ( 'reset' )
178
178
} )
179
+
180
+ it ( 'skips resetting by default when manually reset' , async ( ) => {
181
+ const { listRef, data, stop } = factory ( )
182
+
183
+ await push ( listRef , { name : 'a' } )
184
+ expect ( data . value ) . toHaveLength ( 1 )
185
+ stop ( )
186
+ expect ( data . value ) . toHaveLength ( 1 )
187
+ } )
188
+
189
+ it ( 'resets by default when manually reset' , async ( ) => {
190
+ const { listRef, data, stop } = factory ( )
191
+
192
+ await push ( listRef , { name : 'a' } )
193
+ expect ( data . value ) . toHaveLength ( 1 )
194
+ stop ( true )
195
+ expect ( data . value ) . toHaveLength ( 0 )
196
+ } )
197
+
198
+ it ( 'can be reset to a specific value when manually reset' , async ( ) => {
199
+ const { listRef, data, stop } = factory ( )
200
+
201
+ await push ( listRef , { name : 'a' } )
202
+ expect ( data . value ) . toHaveLength ( 1 )
203
+ stop ( ( ) => [ 1 ] )
204
+ expect ( data . value ) . toEqual ( [ 1 ] )
205
+ } )
179
206
} )
180
207
181
208
it ( 'awaits before setting the value if wait' , async ( ) => {
Original file line number Diff line number Diff line change @@ -264,6 +264,33 @@ describe(
264
264
await wrapper . unmount ( )
265
265
expect ( data . value ) . toEqual ( 'reset' )
266
266
} )
267
+
268
+ it ( 'skips resetting by default when manually reset' , async ( ) => {
269
+ const { listRef, data, stop } = factory ( )
270
+
271
+ await addDoc ( listRef , { name : 'a' } )
272
+ expect ( data . value ) . toHaveLength ( 1 )
273
+ stop ( )
274
+ expect ( data . value ) . toHaveLength ( 1 )
275
+ } )
276
+
277
+ it ( 'resets by default when manually reset' , async ( ) => {
278
+ const { listRef, data, stop } = factory ( )
279
+
280
+ await addDoc ( listRef , { name : 'a' } )
281
+ expect ( data . value ) . toHaveLength ( 1 )
282
+ stop ( true )
283
+ expect ( data . value ) . toHaveLength ( 0 )
284
+ } )
285
+
286
+ it ( 'can be reset to a specific value when manually reset' , async ( ) => {
287
+ const { listRef, data, stop } = factory ( )
288
+
289
+ await addDoc ( listRef , { name : 'a' } )
290
+ expect ( data . value ) . toHaveLength ( 1 )
291
+ stop ( ( ) => [ 1 ] )
292
+ expect ( data . value ) . toEqual ( [ 1 ] )
293
+ } )
267
294
} )
268
295
269
296
it ( 'awaits before setting the value if wait' , async ( ) => {
You can’t perform that action at this time.
0 commit comments