[both][database] Fixed an issue where the reference from a child snapshot was being returned as the parent snapshot when listening to child events

This commit is contained in:
Salakar 2017-07-04 16:16:08 +01:00
parent 9572538af0
commit d1196b98c4
2 changed files with 12 additions and 11 deletions

View File

@ -262,13 +262,11 @@ export default class Reference extends ReferenceBase {
if (_failureCallback) {
_failureCallback = (error) => {
if (error.message.startsWith('FirebaseError: permission_denied')) {
error.message = `permission_denied at /${this.path}: Client doesn\'t have permission to access the desired data.`
error.message = `permission_denied at /${this.path}: Client doesn't have permission to access the desired data.`
}
failureCallbackOrContext(error);
}
};
}
let _successCallback;
@ -375,11 +373,9 @@ export default class Reference extends ReferenceBase {
* @param onComplete
* @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)) {
return Promise.reject(
new Error('Missing transactionUpdate function argument.')
@ -588,7 +584,7 @@ export default class Reference extends ReferenceBase {
*
* {@link https://firebase.google.com/docs/reference/js/firebase.database.Reference#parent}
*/
get parent(): Reference|null {
get parent(): Reference | null {
if (this.path === '/') return null;
return new Reference(this.database, this.path.substring(0, this.path.lastIndexOf('/')));
}

View File

@ -17,9 +17,14 @@ export default class Snapshot {
_childKeys: Array<string>;
constructor(ref: Reference, snapshot: Object) {
this.ref = ref;
this.key = snapshot.key;
if (ref.key !== snapshot.key) {
this.ref = ref.child(snapshot.key);
} else {
this.ref = ref;
}
// internal use only
this._value = snapshot.value;
this._priority = snapshot.priority === undefined ? null : snapshot.priority;