@@ -21,6 +21,7 @@ @interface FirestackDBReference : NSObject
21
21
@property FIRDatabaseHandle childRemovedHandler;
22
22
@property FIRDatabaseHandle childMovedHandler;
23
23
@property FIRDatabaseHandle childValueHandler;
24
+ + (NSDictionary *) snapshotToDict : (FIRDataSnapshot *) snapshot ;
24
25
@end
25
26
26
27
@implementation FirestackDBReference
@@ -46,7 +47,7 @@ - (void) addEventHandler:(NSString *) eventName
46
47
{
47
48
if (![self isListeningTo: eventName]) {
48
49
id withBlock = ^(FIRDataSnapshot * _Nonnull snapshot) {
49
- NSDictionary *props = [self snapshotToDict: snapshot];
50
+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
50
51
[self sendJSEvent: DATABASE_DATA_EVENT
51
52
title: eventName
52
53
props: @{
@@ -74,7 +75,7 @@ - (void) addSingleEventHandler:(RCTResponseSenderBlock) callback
74
75
{
75
76
[_query observeSingleEventOfType: FIRDataEventTypeValue
76
77
withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
77
- NSDictionary *props = [self snapshotToDict: snapshot];
78
+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
78
79
callback (@[[NSNull null ], @{
79
80
@" eventName" : @" value" ,
80
81
@" path" : _path,
@@ -131,7 +132,7 @@ - (void) removeEventHandler:(NSString *) name
131
132
[self unsetListeningOn: name];
132
133
}
133
134
134
- - (NSDictionary *) snapshotToDict : (FIRDataSnapshot *) snapshot
135
+ + (NSDictionary *) snapshotToDict : (FIRDataSnapshot *) snapshot
135
136
{
136
137
NSMutableDictionary *dict = [[NSMutableDictionary alloc ] init ];
137
138
[dict setValue: snapshot.key forKey: @" key" ];
@@ -485,8 +486,22 @@ - (id) init
485
486
currentData.value = value;
486
487
return [FIRTransactionResult successWithValue: currentData];
487
488
}
488
- } andCompletionBlock: ^(NSError * _Nullable error, BOOL committed, FIRDataSnapshot * _Nullable snapshot) {
489
- [self handleCallback: @" transaction" callback: onComplete databaseError: error];
489
+ } andCompletionBlock: ^(NSError * _Nullable databaseError, BOOL committed, FIRDataSnapshot * _Nullable snapshot) {
490
+ if (databaseError != nil ) {
491
+ NSDictionary *evt = @{
492
+ @" errorCode" : [NSNumber numberWithInt: [databaseError code ]],
493
+ @" errorDetails" : [databaseError debugDescription ],
494
+ @" description" : [databaseError description ]
495
+ };
496
+ onComplete (@[evt]);
497
+ } else {
498
+ onComplete (@[[NSNull null ], @{
499
+ @" committed" : [NSNumber numberWithBool: committed],
500
+ @" snapshot" : [FirestackDBReference snapshotToDict: snapshot],
501
+ @" status" : @" success" ,
502
+ @" method" : @" transaction"
503
+ }]);
504
+ }
490
505
} withLocalEvents: applyLocally];
491
506
});
492
507
}
0 commit comments