js: snapshot now returns cloned objects/arrays of this.value

This commit is contained in:
Salakar
2017-03-09 18:45:42 +00:00
parent 178b2e1d99
commit ccd90666f5

View File

@@ -29,16 +29,14 @@ export default class Snapshot {
this.childKeys = snapshot.childKeys || [];
}
/*
* DEFAULT API METHODS
*/
/**
* Extracts a JavaScript value from a DataSnapshot.
* @link https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot#val
* @returns {any}
*/
val(): any {
// clone via JSON stringify/parse - prevent modification of this.value
if (isObject(this.value) || Array.isArray(this.value)) return JSON.parse(JSON.stringify(this.value));
return this.value;
}