[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
1 changed files with 12 additions and 11 deletions

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 promise = newRef.set(value);
// todo 'ThenableReference'
return promise
.then(() => {
if (isFunction(onComplete)) return onComplete(null, newRef);
return newRef;
}).catch((error) => {
if (isFunction(onComplete)) return onComplete(error, null);
return error;
});
// if callback provided then internally call the set promise with value
if (isFunction(onComplete)) {
return promise
.then(() => onComplete(null, newRef))
.catch(error => onComplete(error, null));
}
// 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`);
}
} else {
// todo remove all associated event subs if no event type && no orignalCb
}
}