@@ -21,6 +21,7 @@ @interface FirestackDBReference : NSObject
2121@property FIRDatabaseHandle childRemovedHandler;
2222@property FIRDatabaseHandle childMovedHandler;
2323@property FIRDatabaseHandle childValueHandler;
24+ + (NSDictionary *) snapshotToDict : (FIRDataSnapshot *) snapshot ;
2425@end
2526
2627@implementation FirestackDBReference
@@ -46,7 +47,7 @@ - (void) addEventHandler:(NSString *) eventName
4647{
4748 if (![self isListeningTo: eventName]) {
4849 id withBlock = ^(FIRDataSnapshot * _Nonnull snapshot) {
49- NSDictionary *props = [self snapshotToDict: snapshot];
50+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
5051 [self sendJSEvent: DATABASE_DATA_EVENT
5152 title: eventName
5253 props: @{
@@ -74,7 +75,7 @@ - (void) addSingleEventHandler:(RCTResponseSenderBlock) callback
7475{
7576 [_query observeSingleEventOfType: FIRDataEventTypeValue
7677 withBlock: ^(FIRDataSnapshot * _Nonnull snapshot) {
77- NSDictionary *props = [self snapshotToDict: snapshot];
78+ NSDictionary *props = [FirestackDBReference snapshotToDict: snapshot];
7879 callback (@[[NSNull null ], @{
7980 @" eventName" : @" value" ,
8081 @" path" : _path,
@@ -131,7 +132,7 @@ - (void) removeEventHandler:(NSString *) name
131132 [self unsetListeningOn: name];
132133}
133134
134- - (NSDictionary *) snapshotToDict : (FIRDataSnapshot *) snapshot
135+ + (NSDictionary *) snapshotToDict : (FIRDataSnapshot *) snapshot
135136{
136137 NSMutableDictionary *dict = [[NSMutableDictionary alloc ] init ];
137138 [dict setValue: snapshot.key forKey: @" key" ];
@@ -485,8 +486,22 @@ - (id) init
485486 currentData.value = value;
486487 return [FIRTransactionResult successWithValue: currentData];
487488 }
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+ }
490505 } withLocalEvents: applyLocally];
491506 });
492507}
0 commit comments