@@ -105,7 +105,7 @@ const PROCESSES = {
105
105
'>=' : ( a , b ) => a >= b ,
106
106
'>' : ( a , b ) => a > b ,
107
107
'array-contains' : ( a , b ) => a . includes ( b ) ,
108
- in : ( a , b ) => a . includes ( b ) ,
108
+ in : ( a , b ) => a && a . includes ( b ) ,
109
109
'array-contains-any' : ( a , b ) => b . some ( ( b1 ) => a . includes ( b1 ) ) ,
110
110
'not-in' : ( a , b ) => ! b . includes ( a ) ,
111
111
'*' : ( ) => true ,
@@ -150,7 +150,16 @@ const fieldsTransducer = (fields) =>
150
150
const orderTransducer = ( order ) => {
151
151
const isFlat = typeof order [ 0 ] === 'string' ;
152
152
const orders = isFlat ? [ order ] : order ;
153
- return partialRight . apply ( null , [ orderBy , ...zip . apply ( null , orders ) ] ) ;
153
+ const [ fields , direction ] = zip (
154
+ ...orders . map ( ( [ field , dir ] ) => [
155
+ ( data ) =>
156
+ typeof data [ field ] === 'string'
157
+ ? data [ field ] . toLowerCase ( )
158
+ : data [ field ] ,
159
+ dir || 'asc' ,
160
+ ] ) ,
161
+ ) ;
162
+ return partialRight ( map , ( docs ) => orderBy ( docs , fields , direction ) ) ;
154
163
} ;
155
164
156
165
/**
@@ -288,6 +297,7 @@ function buildTransducer(overrides, query) {
288
297
} = query ;
289
298
290
299
const useOverrides =
300
+ ordered === undefined ||
291
301
Object . keys ( ( overrides || { } ) [ collection ] || { } ) . length > 0 ;
292
302
293
303
const xfPopulate = ! populates
@@ -299,7 +309,7 @@ function buildTransducer(overrides, query) {
299
309
300
310
const xfApplyOverrides = ! useOverrides
301
311
? null
302
- : overridesTransducers ( overrides , collection ) ;
312
+ : overridesTransducers ( overrides || { [ collection ] : [ ] } , collection ) ;
303
313
const xfFilter =
304
314
! useOverrides || filterTransducers ( ! where ? [ '' , '*' , '' ] : where ) ;
305
315
const xfOrder = ! useOverrides || ! order ? null : orderTransducer ( order ) ;
@@ -313,7 +323,7 @@ function buildTransducer(overrides, query) {
313
323
compact ( [
314
324
xfPopulate ,
315
325
xfGetCollection ,
316
- partialRight ( map , ( db ) => createDraft ( db ) ) ,
326
+ partialRight ( map , ( db ) => createDraft ( db || { } ) ) ,
317
327
...xfApplyOverrides ,
318
328
partialRight ( map , ( db ) => finishDraft ( db ) ) ,
319
329
...xfFilter ,
@@ -541,7 +551,7 @@ function cleanOverride(draft, { path, id, data }) {
541
551
542
552
const initialize = ( state , { action, key, path } ) =>
543
553
produce ( state , ( draft ) => {
544
- const done = mark ( `cache.LISTENER_RESPONSE ` , key ) ;
554
+ const done = mark ( `cache.${ action . type . replace ( / ( @ @ . + \/ ) / , '' ) } ` , key ) ;
545
555
if ( ! draft . database ) {
546
556
set ( draft , [ 'database' ] , { } ) ;
547
557
set ( draft , [ 'databaseOverrides' ] , { } ) ;
@@ -556,8 +566,11 @@ const initialize = (state, { action, key, path }) =>
556
566
}
557
567
558
568
// set the query
559
- set ( draft , [ key ] , {
560
- ordered : action . payload . ordered . map ( ( { path, id } ) => [ path , id ] ) ,
569
+ const ordered = (
570
+ action . payload . ordered || selectDocuments ( draft , action . meta )
571
+ ) . map ( ( { path, id } ) => [ path , id ] ) ;
572
+ set ( draft , [ action . meta . storeAs ] , {
573
+ ordered,
561
574
...action . meta ,
562
575
} ) ;
563
576
@@ -582,13 +595,6 @@ const conclude = (state, { action, key, path }) =>
582
595
return inUse ;
583
596
} , [ ] ) ;
584
597
585
- // remove docs from database if unsed by other queries
586
- draft [ key ] . ordered . forEach ( ( [ __ , id ] ) => {
587
- if ( ! activeIds . includes ( id ) ) {
588
- unset ( draft , [ 'database' , path , id ] ) ;
589
- }
590
- } ) ;
591
-
592
598
// remove query
593
599
unset ( draft , [ key ] ) ;
594
600
@@ -774,6 +780,7 @@ const mutation = (state, { action, key, path }) =>
774
780
const HANDLERS = {
775
781
[ actionTypes . GET_SUCCESS ] : initialize ,
776
782
[ actionTypes . LISTENER_RESPONSE ] : initialize ,
783
+ [ actionTypes . SET_LISTENER ] : initialize ,
777
784
[ actionTypes . UNSET_LISTENER ] : conclude ,
778
785
[ actionTypes . DOCUMENT_ADDED ] : modify ,
779
786
[ actionTypes . DOCUMENT_MODIFIED ] : modify ,
0 commit comments