@@ -321,7 +321,8 @@ @implementation FirestackDatabase
321321 props:(NSDictionary *) props
322322 callback:(RCTResponseSenderBlock) callback)
323323{
324- FIRDatabaseReference *ref = [[self getRefAtPath: path] childByAutoId ];
324+ FIRDatabaseReference *pathRef = [self getRefAtPath: path];
325+ FIRDatabaseReference *ref = [pathRef childByAutoId ];
325326
326327 NSURL *url = [NSURL URLWithString: ref.URL];
327328 NSString *newPath = [url path ];
@@ -351,12 +352,12 @@ @implementation FirestackDatabase
351352
352353RCT_EXPORT_METHOD (on:(NSString *) path
353354 modifiersString:(NSString *) modifiersString
354- modifiersArray :(NSArray *) modifiersArray
355+ modifiers :(NSArray *) modifiers
355356 name:(NSString *) eventName
356357 callback:(RCTResponseSenderBlock) callback)
357358{
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 ];
360361
361362 if (![r isListeningTo: eventName]) {
362363 id withBlock = ^(FIRDataSnapshot * _Nonnull snapshot) {
@@ -368,6 +369,7 @@ @implementation FirestackDatabase
368369 props: @{
369370 @" eventName" : eventName,
370371 @" path" : path,
372+ @" modifiersString" : modifiersString,
371373 @" snapshot" : props
372374 }];
373375 };
@@ -399,21 +401,22 @@ @implementation FirestackDatabase
399401}
400402
401403RCT_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)
406408{
407- FirestackDBReference *r = [self getDBHandle: path];
409+ FirestackDBReference *r = [self getDBHandle: path withModifiers: modifiersString ];
408410 int eventType = [r eventTypeFromName: name];
409- FIRDatabaseQuery *ref = [r getQueryWithModifiers: modifiersArray ];
411+ FIRDatabaseQuery *ref = [r getQueryWithModifiers: modifiers ];
410412
411413 [ref observeSingleEventOfType: eventType
412414 withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
413415 NSDictionary *props = [self snapshotToDict: snapshot];
414416 callback (@[[NSNull null ], @{
415417 @" eventName" : name,
416418 @" path" : path,
419+ @" modifiersString" : modifiersString,
417420 @" snapshot" : props
418421 }]);
419422 }
@@ -431,14 +434,14 @@ @implementation FirestackDatabase
431434 eventName:(NSString *) eventName
432435 callback:(RCTResponseSenderBlock) callback)
433436{
434- FirestackDBReference *r = [self getDBHandle: path];
437+ FirestackDBReference *r = [self getDBHandle: path withModifiers: modifiersString ];
435438 if (eventName == nil || [eventName isEqualToString: @" " ]) {
436439 [r cleanup ];
437- [self removeDBHandle: path];
440+ [self removeDBHandle: path withModifiersString: modifiersString ];
438441 } else {
439442 [r removeEventHandler: eventName];
440443 if (![r hasListeners ]) {
441- [self removeDBHandle: path];
444+ [self removeDBHandle: path withModifiersString: modifiersString ];
442445 }
443446 }
444447
@@ -447,6 +450,7 @@ @implementation FirestackDatabase
447450 callback (@[[NSNull null ], @{
448451 @" result" : @" success" ,
449452 @" path" : path,
453+ @" modifiersString" : modifiersString,
450454 @" remainingListeners" : [r listenerKeys ],
451455 }]);
452456}
@@ -540,10 +544,9 @@ - (FIRDatabaseReference *) getRef
540544 return self.ref ;
541545}
542546
543- - (FIRDatabaseReference *) getRefAtPath : (NSString *) str
547+ - (FIRDatabaseReference *) getRefAtPath : (NSString *) path
544548{
545- FirestackDBReference *r = [self getDBHandle: str];
546- return [r getRef ];
549+ return [[FIRDatabase database ] referenceWithPath: path];
547550}
548551
549552// Handles
@@ -555,36 +558,48 @@ - (NSDictionary *) storedDBHandles
555558 return __DBHandles;
556559}
557560
561+ - (NSString *) getDBListenerKey : (NSString *) path
562+ withModifiers : (NSString *) modifiersString
563+ {
564+ return [NSString stringWithFormat: @" %@ | %@ " , path, modifiersString, nil ];
565+ }
566+
558567- (FirestackDBReference *) getDBHandle : (NSString *) path
568+ withModifiers :modifiersString
559569{
560570 NSDictionary *stored = [self storedDBHandles ];
561- FirestackDBReference *r = [stored objectForKey: path];
571+ NSString *key = [self getDBListenerKey: path withModifiers: modifiersString];
572+ FirestackDBReference *r = [stored objectForKey: key];
562573
563574 if (r == nil ) {
564575 r = [[FirestackDBReference alloc ] initWithPath: path];
565- [self saveDBHandle: path dbRef: r];
576+ [self saveDBHandle: path withModifiersString: modifiersString dbRef: r];
566577 }
567578 return r;
568579}
569580
570581- (void ) saveDBHandle : (NSString *) path
582+ withModifiersString : (NSString *)modifiersString
571583 dbRef : (FirestackDBReference *) dbRef
572584{
573585 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];
576589 [r cleanup ];
577590 }
578591
579- [stored setObject: dbRef forKey: path ];
592+ [stored setObject: dbRef forKey: key ];
580593 self._DBHandles = stored;
581594}
582595
583596- (void ) removeDBHandle : (NSString *) path
597+ withModifiersString : (NSString *)modifiersString
584598{
585599 NSMutableDictionary *stored = [[self storedDBHandles ] mutableCopy ];
600+ NSString *key = [self getDBListenerKey: path withModifiers: modifiersString];
586601
587- FirestackDBReference *r = [stored objectForKey: path ];
602+ FirestackDBReference *r = [stored objectForKey: key ];
588603 if (r != nil ) {
589604 [r cleanup ];
590605 }
0 commit comments