2
0
mirror of synced 2025-02-17 08:46:43 +00:00

[database][js] thenable ref fix for #147

This commit is contained in:
Salakar 2017-08-14 13:30:44 +01:00
parent f1709970e9
commit e1fc30bc8f

View File

@ -257,15 +257,17 @@ export default class Reference extends ReferenceBase {
const newRef = new Reference(this._database, `${this.path}/${generatePushID(this._database.serverTimeOffset)}`); const newRef = new Reference(this._database, `${this.path}/${generatePushID(this._database.serverTimeOffset)}`);
const promise = newRef.set(value); const promise = newRef.set(value);
// todo 'ThenableReference' // if callback provided then internally call the set promise with value
return promise if (isFunction(onComplete)) {
.then(() => { return promise
if (isFunction(onComplete)) return onComplete(null, newRef); .then(() => onComplete(null, newRef))
return newRef; .catch(error => onComplete(error, null));
}).catch((error) => { }
if (isFunction(onComplete)) return onComplete(error, null);
return error; // otherwise attach promise to 'thenable' reference and return the
}); // new reference
newRef._setThenable(promise);
return newRef;
} }
/** /**
@ -656,8 +658,7 @@ export default class Reference extends ReferenceBase {
INTERNALS.SharedEventEmitter.removeAllListeners(`${this.makeQueryKey()}:cancelled`); INTERNALS.SharedEventEmitter.removeAllListeners(`${this.makeQueryKey()}:cancelled`);
} }
} else { } else {
// todo remove all associated event subs if no event type && no orignalCb
} }
} }