[database][js] thenable ref fix for #147
This commit is contained in:
parent
f1709970e9
commit
e1fc30bc8f
@ -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
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user