[js][database] cleanup transaction completion wrapper
This commit is contained in:
parent
bec4e8c59c
commit
fb6251a6fd
@ -172,7 +172,6 @@ export default class Reference extends ReferenceBase {
|
|||||||
* @param onComplete
|
* @param onComplete
|
||||||
* @param applyLocally
|
* @param applyLocally
|
||||||
*/
|
*/
|
||||||
|
|
||||||
transaction(transactionUpdate: Function, onComplete: (error: ?Error, committed: boolean, snapshot: ?Snapshot) => *, applyLocally: boolean = false) {
|
transaction(transactionUpdate: Function, onComplete: (error: ?Error, committed: boolean, snapshot: ?Snapshot) => *, applyLocally: boolean = false) {
|
||||||
if (!isFunction(transactionUpdate)) {
|
if (!isFunction(transactionUpdate)) {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
@ -180,23 +179,15 @@ export default class Reference extends ReferenceBase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo cleanup / use new promiseOrCallback logic
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const onCompleteWrapper = (error, committed, snapshotData) => {
|
const onCompleteWrapper = (error, committed, snapshotData) => {
|
||||||
if (error) {
|
if (isFunction(onComplete)) {
|
||||||
if (typeof onComplete === 'function') {
|
if (error) return onComplete(error, committed, null);
|
||||||
onComplete(error, committed, null);
|
return onComplete(null, committed, new Snapshot(this, snapshotData));
|
||||||
}
|
|
||||||
return reject(error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const snapshot = new Snapshot(this, snapshotData);
|
if (error) return reject(error);
|
||||||
|
return resolve({ committed, snapshot: new Snapshot(this, snapshotData) });
|
||||||
if (typeof onComplete === 'function') {
|
|
||||||
onComplete(null, committed, snapshot);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve({ committed, snapshot });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
this._database._transactionHandler.add(this, transactionUpdate, onCompleteWrapper, applyLocally);
|
this._database._transactionHandler.add(this, transactionUpdate, onCompleteWrapper, applyLocally);
|
||||||
|
@ -28,7 +28,7 @@ const NATIVE_MODULE_EVENTS = {
|
|||||||
'database_transaction_event',
|
'database_transaction_event',
|
||||||
'database_event',
|
'database_event',
|
||||||
'database_error',
|
'database_error',
|
||||||
'database_server_offset',
|
// 'database_server_offset', // TODO
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user