@@ -42,6 +42,12 @@ - (id) initWithPathAndModifiers:(RCTEventEmitter *) emitter
42
42
return self;
43
43
}
44
44
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
+
45
51
- (void ) addEventHandler : (NSString *) eventName
46
52
{
47
53
if (![self isListeningTo: eventName]) {
@@ -51,7 +57,7 @@ - (void) addEventHandler:(NSString *) eventName
51
57
title: eventName
52
58
props: @{
53
59
@" eventName" : eventName,
54
- @" path" : _path ,
60
+ @" path" : [ self absPath: [snapshot ref ]] ,
55
61
@" modifiersString" : _modifiersString,
56
62
@" snapshot" : props
57
63
}];
@@ -71,13 +77,15 @@ - (void) addEventHandler:(NSString *) eventName
71
77
}
72
78
73
79
- (void ) addSingleEventHandler : (RCTResponseSenderBlock) callback
80
+ ofType : (NSString *) type
74
81
{
75
- [_query observeSingleEventOfType: FIRDataEventTypeValue
82
+ int eventType = [self eventTypeFromName: type];
83
+ [_query observeSingleEventOfType: eventType
76
84
withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
77
- NSDictionary *props = [self snapshotToDict: snapshot];
85
+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
78
86
callback (@[[NSNull null ], @{
79
- @" eventName" : @" value " ,
80
- @" path" : _path ,
87
+ @" eventName" : type ,
88
+ @" path" : [ self absPath: [snapshot ref ]] ,
81
89
@" modifiersString" : _modifiersString,
82
90
@" snapshot" : props
83
91
}]);
@@ -478,7 +486,7 @@ - (id) init
478
486
callback:(RCTResponseSenderBlock) callback)
479
487
{
480
488
FirestackDBReference *ref = [self getDBHandle: path modifiers: modifiers modifiersString: modifiersString];
481
- [ref addSingleEventHandler: callback];
489
+ [ref addSingleEventHandler: callback ofType: name ];
482
490
}
483
491
484
492
RCT_EXPORT_METHOD (off:(NSString *)path
0 commit comments