initial commit: basic flow errors

This commit is contained in:
Ben Styles
2017-04-04 17:58:20 +01:00
parent 34746c22c2
commit 5acea6d218
10 changed files with 93 additions and 28 deletions

View File

@@ -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);
}