diff --git a/src/api.js b/src/api.js index 249795d45..14d420eef 100644 --- a/src/api.js +++ b/src/api.js @@ -116,13 +116,13 @@ function resolveParams (method, params) { function getMethodsInfo () { const methods = {} - forEach(this.api._methods, function (method, name) { + forEach(this.api._methods, (method, name) => { this[name] = { description: method.description, params: method.params || {}, permission: method.permission } - }, methods) + }) return methods } @@ -201,7 +201,8 @@ export default class Api { addMethods (methods) { let base = '' - forEach(methods, function addMethod (method, name) { + + const addMethod = (method, name) => { name = base + name if (isFunction(method)) { @@ -211,9 +212,10 @@ export default class Api { const oldBase = base base = name + '.' - forEach(method, addMethod, this) + forEach(method, addMethod) base = oldBase - }, this) + } + forEach(methods, addMethod) } async call (session, name, params) { diff --git a/src/collection.js b/src/collection.js index db1f6af41..fdf2e8fef 100644 --- a/src/collection.js +++ b/src/collection.js @@ -3,7 +3,7 @@ import isObject from 'lodash.isobject' import Model from './model' import {BaseError} from 'make-error' import {EventEmitter} from 'events' -import {mapInPlace} from './utils' +import {map} from './utils' // =================================================================== @@ -42,7 +42,7 @@ export default class Collection extends EventEmitter { } const {Model} = this - mapInPlace(models, model => { + map(models, model => { if (!(model instanceof Model)) { model = new Model(model) } @@ -54,7 +54,7 @@ export default class Collection extends EventEmitter { } return model.properties - }) + }, models) models = await this._add(models, opts) this.emit('add', models) @@ -103,7 +103,7 @@ export default class Collection extends EventEmitter { } const {Model} = this - mapInPlace(models, model => { + map(models, model => { if (!(model instanceof Model)) { // TODO: Problems, we may be mixing in some default // properties which will overwrite existing ones. @@ -125,7 +125,7 @@ export default class Collection extends EventEmitter { } return model.properties - }) + }, models) models = await this._update(models) this.emit('update', models) diff --git a/src/index.js b/src/index.js index 2c6f5bc63..98f999ab1 100644 --- a/src/index.js +++ b/src/index.js @@ -274,7 +274,7 @@ async function registerPlugins (xo) { await Promise.all(mapToArray([ `${__dirname}/../node_modules/`, '/usr/local/lib/node_modules/' - ], registerPluginsInPath, xo)) + ], xo::registerPluginsInPath)) } // =================================================================== @@ -314,7 +314,7 @@ async function makeWebServerListen ({ async function createWebServer (opts) { const webServer = new WebServer() - await Promise.all(mapToArray(opts, makeWebServerListen, webServer)) + await Promise.all(mapToArray(opts, webServer::makeWebServerListen)) return webServer } diff --git a/src/utils.js b/src/utils.js index c7edea684..6a9e8b2e3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -428,11 +428,10 @@ export const DONE = {} export function map ( collection, iteratee, - thisArg, target = has(collection, 'length') ? [] : {} ) { forEach(collection, (item, i) => { - const value = iteratee.call(thisArg, item, i, collection, DONE) + const value = iteratee(item, i, collection, DONE) if (value === DONE) { return false } @@ -443,11 +442,6 @@ export function map ( return target } -// Helper to `map()` to update the current collection. -export function mapInPlace (collection, iteratee, thisArg) { - return map(collection, iteratee, thisArg, collection) -} - // ------------------------------------------------------------------- // Create a hash from multiple values. diff --git a/src/xo.js b/src/xo.js index 914897ddb..51691203a 100644 --- a/src/xo.js +++ b/src/xo.js @@ -545,8 +545,8 @@ export default class Xo extends EventEmitter { group.users = userIds await Promise.all([ - Promise.all(mapToArray(newUsers, this._users.save, this._users)), - Promise.all(mapToArray(oldUsers, this._users.save, this._users)), + Promise.all(mapToArray(newUsers, ::this._users.save)), + Promise.all(mapToArray(oldUsers, ::this._users.save)), this._groups.save(group) ]) }