[js] prefix snapshot internals with '_'

This commit is contained in:
Salakar 2017-03-16 16:48:03 +00:00
parent 9f5b132f38
commit f5d0bd002a
3 changed files with 23 additions and 28 deletions

View File

@ -1,5 +1,4 @@
require 'json'
package = JSON.parse(File.read('package.json'))
Pod::Spec.new do |s|
@ -13,7 +12,7 @@ Pod::Spec.new do |s|
s.license = package['license']
s.author = "Mike Diarmid"
s.source = { :git => "https://github.com/invertase/react-native-firebase.git", :tag => "v#{s.version}" }
s.social_media_url = 'http://twitter.com/invertaseio'
s.social_media_url = 'http://twitter.com/mikediarmid'
s.platform = :ios, "8.0"
s.header_dir = 'ios/RNFirebase'
s.preserve_paths = 'README.md', 'package.json', '*.js'

View File

@ -8,25 +8,21 @@ import { isObject, deepGet, deepExists } from './../../utils';
* @link https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot
*/
export default class Snapshot {
static key: String;
static value: Object;
static exists: boolean;
static hasChildren: boolean;
static childKeys: String[];
ref: Object;
key: string;
value: any;
exists: boolean;
priority: any;
childKeys: Array<string>;
_value: any;
_priority: any;
_childKeys: Array<string>;
constructor(ref: Reference, snapshot: Object) {
this.ref = ref;
this.key = snapshot.key;
this.value = snapshot.value;
this.priority = snapshot.priority === undefined ? null : snapshot.priority;
this.childKeys = snapshot.childKeys || [];
// internal use only
this._value = snapshot.value;
this._priority = snapshot.priority === undefined ? null : snapshot.priority;
this._childKeys = snapshot.childKeys || [];
}
/**
@ -35,9 +31,9 @@ export default class Snapshot {
* @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;
// 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;
}
/**
@ -47,7 +43,7 @@ export default class Snapshot {
* @returns {Snapshot}
*/
child(path: string): Snapshot {
const value = deepGet(this.value, path);
const value = deepGet(this._value, path);
const childRef = this.ref.child(path);
return new Snapshot(childRef, {
value,
@ -67,7 +63,7 @@ export default class Snapshot {
* @returns {boolean}
*/
exists(): Boolean {
return this.value !== null;
return this._value !== null;
}
/**
@ -76,11 +72,11 @@ export default class Snapshot {
* @param action
*/
forEach(action: (key: any) => any): Boolean {
if (!this.childKeys.length) return false;
if (!this._childKeys.length) return false;
let cancelled = false;
for (let i = 0, len = this.childKeys.length; i < len; i++) {
const key = this.childKeys[i];
for (let i = 0, len = this._childKeys.length; i < len; i++) {
const key = this._childKeys[i];
const childSnapshot = this.child(key);
const returnValue = action(childSnapshot);
@ -99,7 +95,7 @@ export default class Snapshot {
* @returns {String|Number|null}
*/
getPriority(): String|Number|null {
return this.priority;
return this._priority;
}
/**
@ -109,7 +105,7 @@ export default class Snapshot {
* @returns {Boolean}
*/
hasChild(path: string): Boolean {
return deepExists(this.value, path);
return deepExists(this._value, path);
}
/**
@ -127,8 +123,8 @@ export default class Snapshot {
* @returns {Number}
*/
numChildren(): Number {
if (!isObject(this.value)) return 0;
return Object.keys(this.value).length;
if (!isObject(this._value)) return 0;
return Object.keys(this._value).length;
}
/**

View File

@ -1,6 +1,6 @@
{
"name": "react-native-firebase",
"version": "1.0.0-alpha",
"version": "1.0.0-alpha1",
"author": "Invertase <contact@invertase.io> (http://invertase.io)",
"description": "A react native firebase library supporting both android and ios native firebase SDK's",
"main": "index",