Skip to content

Commit

Permalink
feat(*): use Array.isArray of instanceof
Browse files Browse the repository at this point in the history
  • Loading branch information
Duy Luong committed Dec 24, 2017
1 parent c1ffc4b commit 851071b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Database/Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DatabaseManager {
*/
close (names) {
let connections = names || _.keys(this._connectionPools)
connections = connections instanceof Array === false ? [connections] : connections
connections = !Array.isArray(connections) ? [connections] : connections
_.each(connections, (name) => {
this._connectionPools[name].close()
this._connectionPools[name] = null
Expand Down
2 changes: 1 addition & 1 deletion src/LucidMongo/Model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ class Model extends BaseModel {
* @throws {InvalidArgumentException} If payloadArray is not an array
*/
static async createMany (payloadArray) {
if (payloadArray instanceof Array === false) {
if (!Array.isArray(payloadArray)) {
throw GE
.InvalidArgumentException
.invalidParameter(`${this.name}.createMany expects an array of values`, payloadArray)
Expand Down
2 changes: 1 addition & 1 deletion src/LucidMongo/QueryBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class QueryBuilder {
* Don't do anything when array is empty or value is not
* an array
*/
const scopesToIgnore = scopes instanceof Array === true ? scopes : ['*']
const scopesToIgnore = Array.isArray(scopes) ? scopes : ['*']
this._ignoreScopes = this._ignoreScopes.concat(scopesToIgnore)
return this
}
Expand Down
8 changes: 4 additions & 4 deletions src/LucidMongo/Relations/BelongsToMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ class BelongsToMany extends BaseRelation {
*/
async attach (references, pivotCallback = null) {
await this._loadAndCachePivot()
const rows = references instanceof Array === false ? [references] : references
const rows = !Array.isArray(references) ? [references] : references

return Promise.all(rows.map((row) => {
const pivotInstance = this._getPivotInstance(row)
Expand Down Expand Up @@ -738,7 +738,7 @@ class BelongsToMany extends BaseRelation {
detach (references) {
const query = this.pivotQuery(false)
if (references) {
const rows = references instanceof Array === false ? [references] : references
const rows = !Array.isArray(references) ? [references] : references
query.whereIn(this.relatedForeignKey, rows)
_.remove(this._existingPivotInstances, (pivotInstance) => {
return _.includes(rows, pivotInstance[this.relatedForeignKey])
Expand Down Expand Up @@ -811,7 +811,7 @@ class BelongsToMany extends BaseRelation {
* @return {void}
*/
async saveMany (arrayOfRelatedInstances, pivotCallback) {
if (arrayOfRelatedInstances instanceof Array === false) {
if (!Array.isArray(arrayOfRelatedInstances)) {
throw GE
.InvalidArgumentException
.invalidParameter('belongsToMany.saveMany expects an array of related model instances', arrayOfRelatedInstances)
Expand Down Expand Up @@ -856,7 +856,7 @@ class BelongsToMany extends BaseRelation {
* @return {Array}
*/
async createMany (rows, pivotCallback) {
if (rows instanceof Array === false) {
if (!Array.isArray(rows)) {
throw GE
.InvalidArgumentException
.invalidParameter('belongsToMany.createMany expects an array of related model instances', rows)
Expand Down
4 changes: 2 additions & 2 deletions src/LucidMongo/Relations/HasMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class HasMany extends BaseRelation {
* @return {Array}
*/
async createMany (arrayOfPayload) {
if (arrayOfPayload instanceof Array === false) {
if (!Array.isArray(arrayOfPayload)) {
throw GE
.InvalidArgumentException
.invalidParameter('hasMany.createMany expects an array of values', arrayOfPayload)
Expand All @@ -188,7 +188,7 @@ class HasMany extends BaseRelation {
* @return {Array}
*/
async saveMany (arrayOfRelatedInstances) {
if (arrayOfRelatedInstances instanceof Array === false) {
if (!Array.isArray(arrayOfRelatedInstances)) {
throw GE
.InvalidArgumentException
.invalidParameter('hasMany.saveMany expects an array of related model instances', arrayOfRelatedInstances)
Expand Down

0 comments on commit 851071b

Please sign in to comment.