@@ -321,7 +321,8 @@ @implementation FirestackDatabase
321
321
props:(NSDictionary *) props
322
322
callback:(RCTResponseSenderBlock) callback)
323
323
{
324
- FIRDatabaseReference *ref = [[self getRefAtPath: path] childByAutoId ];
324
+ FIRDatabaseReference *pathRef = [self getRefAtPath: path];
325
+ FIRDatabaseReference *ref = [pathRef childByAutoId ];
325
326
326
327
NSURL *url = [NSURL URLWithString: ref.URL];
327
328
NSString *newPath = [url path ];
@@ -351,12 +352,12 @@ @implementation FirestackDatabase
351
352
352
353
RCT_EXPORT_METHOD (on:(NSString *) path
353
354
modifiersString:(NSString *) modifiersString
354
- modifiersArray :(NSArray *) modifiersArray
355
+ modifiers :(NSArray *) modifiers
355
356
name:(NSString *) eventName
356
357
callback:(RCTResponseSenderBlock) callback)
357
358
{
358
- FirestackDBReference *r = [self getDBHandle: path];
359
- FIRDatabaseQuery *query = [r getQueryWithModifiers: modifiersArray ];
359
+ FirestackDBReference *r = [self getDBHandle: path withModifiers: modifiersString ];
360
+ FIRDatabaseQuery *query = [r getQueryWithModifiers: modifiers ];
360
361
361
362
if (![r isListeningTo: eventName]) {
362
363
id withBlock = ^(FIRDataSnapshot * _Nonnull snapshot) {
@@ -368,6 +369,7 @@ @implementation FirestackDatabase
368
369
props: @{
369
370
@" eventName" : eventName,
370
371
@" path" : path,
372
+ @" modifiersString" : modifiersString,
371
373
@" snapshot" : props
372
374
}];
373
375
};
@@ -399,21 +401,22 @@ @implementation FirestackDatabase
399
401
}
400
402
401
403
RCT_EXPORT_METHOD (onOnce:(NSString *) path
402
- modifiersString:(NSString *) modifiersString
403
- modifiersArray :(NSArray *) modifiersArray
404
- name:(NSString *) name
405
- callback:(RCTResponseSenderBlock) callback)
404
+ modifiersString:(NSString *) modifiersString
405
+ modifiers :(NSArray *) modifiers
406
+ name:(NSString *) name
407
+ callback:(RCTResponseSenderBlock) callback)
406
408
{
407
- FirestackDBReference *r = [self getDBHandle: path];
409
+ FirestackDBReference *r = [self getDBHandle: path withModifiers: modifiersString ];
408
410
int eventType = [r eventTypeFromName: name];
409
- FIRDatabaseQuery *ref = [r getQueryWithModifiers: modifiersArray ];
411
+ FIRDatabaseQuery *ref = [r getQueryWithModifiers: modifiers ];
410
412
411
413
[ref observeSingleEventOfType: eventType
412
414
withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
413
415
NSDictionary *props = [self snapshotToDict: snapshot];
414
416
callback (@[[NSNull null ], @{
415
417
@" eventName" : name,
416
418
@" path" : path,
419
+ @" modifiersString" : modifiersString,
417
420
@" snapshot" : props
418
421
}]);
419
422
}
@@ -431,14 +434,14 @@ @implementation FirestackDatabase
431
434
eventName:(NSString *) eventName
432
435
callback:(RCTResponseSenderBlock) callback)
433
436
{
434
- FirestackDBReference *r = [self getDBHandle: path];
437
+ FirestackDBReference *r = [self getDBHandle: path withModifiers: modifiersString ];
435
438
if (eventName == nil || [eventName isEqualToString: @" " ]) {
436
439
[r cleanup ];
437
- [self removeDBHandle: path];
440
+ [self removeDBHandle: path withModifiersString: modifiersString ];
438
441
} else {
439
442
[r removeEventHandler: eventName];
440
443
if (![r hasListeners ]) {
441
- [self removeDBHandle: path];
444
+ [self removeDBHandle: path withModifiersString: modifiersString ];
442
445
}
443
446
}
444
447
@@ -447,6 +450,7 @@ @implementation FirestackDatabase
447
450
callback (@[[NSNull null ], @{
448
451
@" result" : @" success" ,
449
452
@" path" : path,
453
+ @" modifiersString" : modifiersString,
450
454
@" remainingListeners" : [r listenerKeys ],
451
455
}]);
452
456
}
@@ -540,10 +544,9 @@ - (FIRDatabaseReference *) getRef
540
544
return self.ref ;
541
545
}
542
546
543
- - (FIRDatabaseReference *) getRefAtPath : (NSString *) str
547
+ - (FIRDatabaseReference *) getRefAtPath : (NSString *) path
544
548
{
545
- FirestackDBReference *r = [self getDBHandle: str];
546
- return [r getRef ];
549
+ return [[FIRDatabase database ] referenceWithPath: path];
547
550
}
548
551
549
552
// Handles
@@ -555,36 +558,48 @@ - (NSDictionary *) storedDBHandles
555
558
return __DBHandles;
556
559
}
557
560
561
+ - (NSString *) getDBListenerKey : (NSString *) path
562
+ withModifiers : (NSString *) modifiersString
563
+ {
564
+ return [NSString stringWithFormat: @" %@ | %@ " , path, modifiersString, nil ];
565
+ }
566
+
558
567
- (FirestackDBReference *) getDBHandle : (NSString *) path
568
+ withModifiers :modifiersString
559
569
{
560
570
NSDictionary *stored = [self storedDBHandles ];
561
- FirestackDBReference *r = [stored objectForKey: path];
571
+ NSString *key = [self getDBListenerKey: path withModifiers: modifiersString];
572
+ FirestackDBReference *r = [stored objectForKey: key];
562
573
563
574
if (r == nil ) {
564
575
r = [[FirestackDBReference alloc ] initWithPath: path];
565
- [self saveDBHandle: path dbRef: r];
576
+ [self saveDBHandle: path withModifiersString: modifiersString dbRef: r];
566
577
}
567
578
return r;
568
579
}
569
580
570
581
- (void ) saveDBHandle : (NSString *) path
582
+ withModifiersString : (NSString *)modifiersString
571
583
dbRef : (FirestackDBReference *) dbRef
572
584
{
573
585
NSMutableDictionary *stored = [[self storedDBHandles ] mutableCopy ];
574
- if ([stored objectForKey: path]) {
575
- FirestackDBReference *r = [stored objectForKey: path];
586
+ NSString *key = [self getDBListenerKey: path withModifiers: modifiersString];
587
+ if ([stored objectForKey: key]) {
588
+ FirestackDBReference *r = [stored objectForKey: key];
576
589
[r cleanup ];
577
590
}
578
591
579
- [stored setObject: dbRef forKey: path ];
592
+ [stored setObject: dbRef forKey: key ];
580
593
self._DBHandles = stored;
581
594
}
582
595
583
596
- (void ) removeDBHandle : (NSString *) path
597
+ withModifiersString : (NSString *)modifiersString
584
598
{
585
599
NSMutableDictionary *stored = [[self storedDBHandles ] mutableCopy ];
600
+ NSString *key = [self getDBListenerKey: path withModifiers: modifiersString];
586
601
587
- FirestackDBReference *r = [stored objectForKey: path ];
602
+ FirestackDBReference *r = [stored objectForKey: key ];
588
603
if (r != nil ) {
589
604
[r cleanup ];
590
605
}
0 commit comments