Lodash 4 iteration: no thisArg argument.

This commit is contained in:
Julien Fontanet 2016-02-16 15:50:10 +01:00
parent 06fb06829b
commit dc1f5826f8
5 changed files with 17 additions and 21 deletions

View File

@ -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) {

View File

@ -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)

View File

@ -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
}

View File

@ -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.

View File

@ -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)
])
}