@@ -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,9 +57,10 @@ - (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
- @" snapshot" : props
62
+ @" snapshot" : props,
63
+ @" handlePath" : _path
57
64
}];
58
65
};
59
66
id errorBlock = ^(NSError * _Nonnull error) {
@@ -71,13 +78,15 @@ - (void) addEventHandler:(NSString *) eventName
71
78
}
72
79
73
80
- (void ) addSingleEventHandler : (RCTResponseSenderBlock) callback
81
+ ofType : (NSString *) type
74
82
{
75
- [_query observeSingleEventOfType: FIRDataEventTypeValue
83
+ int eventType = [self eventTypeFromName: type];
84
+ [_query observeSingleEventOfType: eventType
76
85
withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
77
- NSDictionary *props = [self snapshotToDict: snapshot];
86
+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
78
87
callback (@[[NSNull null ], @{
79
- @" eventName" : @" value " ,
80
- @" path" : _path ,
88
+ @" eventName" : type ,
89
+ @" path" : [ self absPath: [snapshot ref ]] ,
81
90
@" modifiersString" : _modifiersString,
82
91
@" snapshot" : props
83
92
}]);
@@ -489,7 +498,7 @@ - (id) init
489
498
callback:(RCTResponseSenderBlock) callback)
490
499
{
491
500
FirestackDBReference *ref = [self getDBHandle: path modifiers: modifiers modifiersString: modifiersString];
492
- [ref addSingleEventHandler: callback];
501
+ [ref addSingleEventHandler: callback ofType: name ];
493
502
}
494
503
495
504
RCT_EXPORT_METHOD (off:(NSString *)path
0 commit comments