[js] prefix snapshot internals with '_'
This commit is contained in:
parent
9f5b132f38
commit
f5d0bd002a
|
@ -1,5 +1,4 @@
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
package = JSON.parse(File.read('package.json'))
|
package = JSON.parse(File.read('package.json'))
|
||||||
|
|
||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
|
@ -13,7 +12,7 @@ Pod::Spec.new do |s|
|
||||||
s.license = package['license']
|
s.license = package['license']
|
||||||
s.author = "Mike Diarmid"
|
s.author = "Mike Diarmid"
|
||||||
s.source = { :git => "https://github.com/invertase/react-native-firebase.git", :tag => "v#{s.version}" }
|
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.platform = :ios, "8.0"
|
||||||
s.header_dir = 'ios/RNFirebase'
|
s.header_dir = 'ios/RNFirebase'
|
||||||
s.preserve_paths = 'README.md', 'package.json', '*.js'
|
s.preserve_paths = 'README.md', 'package.json', '*.js'
|
||||||
|
|
|
@ -8,25 +8,21 @@ import { isObject, deepGet, deepExists } from './../../utils';
|
||||||
* @link https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot
|
* @link https://firebase.google.com/docs/reference/js/firebase.database.DataSnapshot
|
||||||
*/
|
*/
|
||||||
export default class Snapshot {
|
export default class Snapshot {
|
||||||
static key: String;
|
|
||||||
static value: Object;
|
|
||||||
static exists: boolean;
|
|
||||||
static hasChildren: boolean;
|
|
||||||
static childKeys: String[];
|
|
||||||
|
|
||||||
ref: Object;
|
ref: Object;
|
||||||
key: string;
|
key: string;
|
||||||
value: any;
|
|
||||||
exists: boolean;
|
_value: any;
|
||||||
priority: any;
|
_priority: any;
|
||||||
childKeys: Array<string>;
|
_childKeys: Array<string>;
|
||||||
|
|
||||||
constructor(ref: Reference, snapshot: Object) {
|
constructor(ref: Reference, snapshot: Object) {
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
this.key = snapshot.key;
|
this.key = snapshot.key;
|
||||||
this.value = snapshot.value;
|
|
||||||
this.priority = snapshot.priority === undefined ? null : snapshot.priority;
|
// internal use only
|
||||||
this.childKeys = snapshot.childKeys || [];
|
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}
|
* @returns {any}
|
||||||
*/
|
*/
|
||||||
val(): any {
|
val(): any {
|
||||||
// clone via JSON stringify/parse - prevent modification of 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));
|
if (isObject(this._value) || Array.isArray(this._value)) return JSON.parse(JSON.stringify(this._value));
|
||||||
return this.value;
|
return this._value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,7 +43,7 @@ export default class Snapshot {
|
||||||
* @returns {Snapshot}
|
* @returns {Snapshot}
|
||||||
*/
|
*/
|
||||||
child(path: string): Snapshot {
|
child(path: string): Snapshot {
|
||||||
const value = deepGet(this.value, path);
|
const value = deepGet(this._value, path);
|
||||||
const childRef = this.ref.child(path);
|
const childRef = this.ref.child(path);
|
||||||
return new Snapshot(childRef, {
|
return new Snapshot(childRef, {
|
||||||
value,
|
value,
|
||||||
|
@ -67,7 +63,7 @@ export default class Snapshot {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
exists(): Boolean {
|
exists(): Boolean {
|
||||||
return this.value !== null;
|
return this._value !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,11 +72,11 @@ export default class Snapshot {
|
||||||
* @param action
|
* @param action
|
||||||
*/
|
*/
|
||||||
forEach(action: (key: any) => any): Boolean {
|
forEach(action: (key: any) => any): Boolean {
|
||||||
if (!this.childKeys.length) return false;
|
if (!this._childKeys.length) return false;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
|
||||||
for (let i = 0, len = this.childKeys.length; i < len; i++) {
|
for (let i = 0, len = this._childKeys.length; i < len; i++) {
|
||||||
const key = this.childKeys[i];
|
const key = this._childKeys[i];
|
||||||
const childSnapshot = this.child(key);
|
const childSnapshot = this.child(key);
|
||||||
const returnValue = action(childSnapshot);
|
const returnValue = action(childSnapshot);
|
||||||
|
|
||||||
|
@ -99,7 +95,7 @@ export default class Snapshot {
|
||||||
* @returns {String|Number|null}
|
* @returns {String|Number|null}
|
||||||
*/
|
*/
|
||||||
getPriority(): String|Number|null {
|
getPriority(): String|Number|null {
|
||||||
return this.priority;
|
return this._priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,7 +105,7 @@ export default class Snapshot {
|
||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
hasChild(path: string): 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}
|
* @returns {Number}
|
||||||
*/
|
*/
|
||||||
numChildren(): Number {
|
numChildren(): Number {
|
||||||
if (!isObject(this.value)) return 0;
|
if (!isObject(this._value)) return 0;
|
||||||
return Object.keys(this.value).length;
|
return Object.keys(this._value).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "react-native-firebase",
|
"name": "react-native-firebase",
|
||||||
"version": "1.0.0-alpha",
|
"version": "1.0.0-alpha1",
|
||||||
"author": "Invertase <contact@invertase.io> (http://invertase.io)",
|
"author": "Invertase <contact@invertase.io> (http://invertase.io)",
|
||||||
"description": "A react native firebase library supporting both android and ios native firebase SDK's",
|
"description": "A react native firebase library supporting both android and ios native firebase SDK's",
|
||||||
"main": "index",
|
"main": "index",
|
||||||
|
|
Loading…
Reference in New Issue