Skip to content

Commit

Permalink
[firestore] .settings() - use hasOwnProperty instead of truthy value …
Browse files Browse the repository at this point in the history
…existence checks
  • Loading branch information
Salakar committed Apr 16, 2018
1 parent 016c07f commit f483241
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/modules/firestore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f483241

Please sign in to comment.