mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-29 04:35:43 +08:00
js: snapshot now returns cloned objects/arrays of this.value
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user