@@ -42,6 +42,12 @@ - (id) initWithPathAndModifiers:(RCTEventEmitter *) emitter
4242 return self;
4343}
4444
45+ - (NSString *) absPath : (FIRDatabaseReference *) ref {
46+ NSString *url = ref.URL ;
47+ NSString *rooturl = ref.root .URL ;
48+ return [[url substringFromIndex: rooturl.length] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
49+ }
50+
4551- (void ) addEventHandler : (NSString *) eventName
4652{
4753 if (![self isListeningTo: eventName]) {
@@ -51,7 +57,7 @@ - (void) addEventHandler:(NSString *) eventName
5157 title: eventName
5258 props: @{
5359 @" eventName" : eventName,
54- @" path" : _path ,
60+ @" path" : [ self absPath: [snapshot ref ]] ,
5561 @" modifiersString" : _modifiersString,
5662 @" snapshot" : props
5763 }];
@@ -71,13 +77,15 @@ - (void) addEventHandler:(NSString *) eventName
7177}
7278
7379- (void ) addSingleEventHandler : (RCTResponseSenderBlock) callback
80+ ofType : (NSString *) type
7481{
75- [_query observeSingleEventOfType: FIRDataEventTypeValue
82+ int eventType = [self eventTypeFromName: type];
83+ [_query observeSingleEventOfType: eventType
7684 withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
77- NSDictionary *props = [self snapshotToDict: snapshot];
85+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
7886 callback (@[[NSNull null ], @{
79- @" eventName" : @" value " ,
80- @" path" : _path ,
87+ @" eventName" : type ,
88+ @" path" : [ self absPath: [snapshot ref ]] ,
8189 @" modifiersString" : _modifiersString,
8290 @" snapshot" : props
8391 }]);
@@ -489,7 +497,7 @@ - (id) init
489497 callback:(RCTResponseSenderBlock) callback)
490498{
491499 FirestackDBReference *ref = [self getDBHandle: path modifiers: modifiers modifiersString: modifiersString];
492- [ref addSingleEventHandler: callback];
500+ [ref addSingleEventHandler: callback ofType: name ];
493501}
494502
495503RCT_EXPORT_METHOD (off:(NSString *)path
0 commit comments