mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-24 04:24:52 +08:00
initial commit: basic flow errors
This commit is contained in:
@@ -157,19 +157,25 @@ export default class Reference extends ReferenceBase {
|
||||
* @param onComplete
|
||||
* @param applyLocally
|
||||
*/
|
||||
transaction(transactionUpdate, onComplete?: () => any, applyLocally: boolean = false) {
|
||||
transaction(
|
||||
transactionUpdate: Function,
|
||||
onComplete?: (?Error, any, ?Snapshot) => any,
|
||||
applyLocally: boolean = false
|
||||
) {
|
||||
if (!isFunction(transactionUpdate)) return Promise.reject(new Error('Missing transactionUpdate function argument.'));
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const onCompleteWrapper = (error, committed, snapshotData) => {
|
||||
if (error) {
|
||||
if (isFunction(onComplete)) onComplete(error, committed, null);
|
||||
if (typeof onComplete === 'function') {
|
||||
onComplete(error, committed, null);
|
||||
}
|
||||
return reject(error);
|
||||
}
|
||||
|
||||
const snapshot = new Snapshot(this, snapshotData);
|
||||
|
||||
if (isFunction(onComplete)) {
|
||||
if (typeof onComplete === 'function') {
|
||||
onComplete(null, committed, snapshot);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user