@@ -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,9 +57,10 @@ - (void) addEventHandler:(NSString *) eventName
5157 title: eventName
5258 props: @{
5359 @" eventName" : eventName,
54- @" path" : _path ,
60+ @" path" : [ self absPath: [snapshot ref ]] ,
5561 @" modifiersString" : _modifiersString,
56- @" snapshot" : props
62+ @" snapshot" : props,
63+ @" handlePath" : _path
5764 }];
5865 };
5966 id errorBlock = ^(NSError * _Nonnull error) {
@@ -71,13 +78,15 @@ - (void) addEventHandler:(NSString *) eventName
7178}
7279
7380- (void ) addSingleEventHandler : (RCTResponseSenderBlock) callback
81+ ofType : (NSString *) type
7482{
75- [_query observeSingleEventOfType: FIRDataEventTypeValue
83+ int eventType = [self eventTypeFromName: type];
84+ [_query observeSingleEventOfType: eventType
7685 withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
77- NSDictionary *props = [self snapshotToDict: snapshot];
86+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
7887 callback (@[[NSNull null ], @{
79- @" eventName" : @" value " ,
80- @" path" : _path ,
88+ @" eventName" : type ,
89+ @" path" : [ self absPath: [snapshot ref ]] ,
8190 @" modifiersString" : _modifiersString,
8291 @" snapshot" : props
8392 }]);
@@ -489,7 +498,7 @@ - (id) init
489498 callback:(RCTResponseSenderBlock) callback)
490499{
491500 FirestackDBReference *ref = [self getDBHandle: path modifiers: modifiers modifiersString: modifiersString];
492- [ref addSingleEventHandler: callback];
501+ [ref addSingleEventHandler: callback ofType: name ];
493502}
494503
495504RCT_EXPORT_METHOD (off:(NSString *)path
0 commit comments