[firestore] .settings() - use hasOwnProperty instead of truthy value existence checks

This commit is contained in:
Salakar 2018-04-16 18:20:08 +01:00
parent 016c07fa35
commit f4832410bb
2 changed files with 17 additions and 5 deletions

View File

@ -15,7 +15,7 @@ import Path from './Path';
import WriteBatch from './WriteBatch';
import TransactionHandler from './TransactionHandler';
import Transaction from './Transaction';
import { isBoolean, isObject, isString } from '../../utils';
import { isBoolean, isObject, isString, hop } from '../../utils';
import { getNativeModule } from '../../utils/native';
import type DocumentSnapshot from './DocumentSnapshot';
@ -164,22 +164,25 @@ export default class Firestore extends ModuleBase {
return Promise.reject(
new Error('Firestore.settings failed: settings must be an object.')
);
} else if (settings.host && !isString(settings.host)) {
} else if (hop(settings, 'host') && !isString(settings.host)) {
return Promise.reject(
new Error('Firestore.settings failed: settings.host must be a string.')
);
} else if (settings.persistence && !isBoolean(settings.persistence)) {
} else if (
hop(settings, 'persistence') &&
!isBoolean(settings.persistence)
) {
return Promise.reject(
new Error(
'Firestore.settings failed: settings.persistence must be boolean.'
)
);
} else if (settings.ssl && !isBoolean(settings.ssl)) {
} else if (hop(settings, 'ssl') && !isBoolean(settings.ssl)) {
return Promise.reject(
new Error('Firestore.settings failed: settings.ssl must be boolean.')
);
} else if (
settings.timestampsInSnapshots &&
hop(settings, 'timestampsInSnapshots') &&
!isBoolean(settings.timestampsInSnapshots)
) {
return Promise.reject(

View File

@ -11,6 +11,15 @@ const AUTO_ID_CHARS =
const { hasOwnProperty } = Object;
// const DEFAULT_CHUNK_SIZE = 50;
/**
* Checks for property existence by name on the specified object
* @param object
* @param property
* @returns {*}
*/
export function hop(object: Object, property: string): boolean {
return hasOwnProperty.call(object, property);
}
/**
* Deep get a value from an object.