[js][database] cleanup transaction completion wrapper

This commit is contained in:
Salakar 2017-08-05 22:00:06 +01:00
parent bec4e8c59c
commit fb6251a6fd
2 changed files with 6 additions and 15 deletions

View File

@ -172,7 +172,6 @@ export default class Reference extends ReferenceBase {
* @param onComplete
* @param applyLocally
*/
transaction(transactionUpdate: Function, onComplete: (error: ?Error, committed: boolean, snapshot: ?Snapshot) => *, applyLocally: boolean = false) {
if (!isFunction(transactionUpdate)) {
return Promise.reject(
@ -180,23 +179,15 @@ export default class Reference extends ReferenceBase {
);
}
// todo cleanup / use new promiseOrCallback logic
return new Promise((resolve, reject) => {
const onCompleteWrapper = (error, committed, snapshotData) => {
if (error) {
if (typeof onComplete === 'function') {
onComplete(error, committed, null);
}
return reject(error);
if (isFunction(onComplete)) {
if (error) return onComplete(error, committed, null);
return onComplete(null, committed, new Snapshot(this, snapshotData));
}
const snapshot = new Snapshot(this, snapshotData);
if (typeof onComplete === 'function') {
onComplete(null, committed, snapshot);
}
return resolve({ committed, snapshot });
if (error) return reject(error);
return resolve({ committed, snapshot: new Snapshot(this, snapshotData) });
};
this._database._transactionHandler.add(this, transactionUpdate, onCompleteWrapper, applyLocally);

View File

@ -28,7 +28,7 @@ const NATIVE_MODULE_EVENTS = {
'database_transaction_event',
'database_event',
'database_error',
'database_server_offset',
// 'database_server_offset', // TODO
],
};