Replace lodash.assign() with ES2016 object spread.

This commit is contained in:
Julien Fontanet 2015-11-09 14:09:29 +01:00
parent 8ab2ca3f24
commit 74c9a57070
8 changed files with 19 additions and 24 deletions

View File

@ -1,7 +1,6 @@
import createDebug from 'debug'
const debug = createDebug('xo:api')
import assign from 'lodash.assign'
import getKeys from 'lodash.keys'
import isFunction from 'lodash.isfunction'
import kindOf from 'kindof'
@ -114,11 +113,11 @@ function getMethodsInfo () {
const methods = {}
forEach(this.api._methods, function (method, name) {
this[name] = assign({}, {
this[name] = {
description: method.description,
params: method.params || {},
permission: method.permission
})
}
}, methods)
return methods
@ -149,11 +148,12 @@ function methodSignature ({method: name}) {
// Return an array for compatibility with XML-RPC.
return [
// XML-RPC require the name of the method.
assign({ name }, {
{
name,
description: method.description,
params: method.params || {},
permission: method.permission
})
}
]
}
methodSignature.description = 'returns the signature of an API method'

View File

@ -2,7 +2,6 @@ import createLogger from 'debug'
const debug = createLogger('xo:main')
import appConf from 'app-conf'
import assign from 'lodash.assign'
import bind from 'lodash.bind'
import blocked from 'blocked'
import createExpress from 'express'
@ -394,8 +393,7 @@ const apiHelpers = {
}
const setUpApi = (webSocketServer, xo) => {
const context = Object.create(xo)
assign(xo, apiHelpers)
const context = { __proto__: xo, ...apiHelpers }
const api = new Api({
context

View File

@ -51,7 +51,7 @@ export default class JobExecutor {
const connection = this.xo.createUserConnection()
connection.set('user_id', userId)
forEach(paramsFlatVector, params => {
this.api.call(connection, method, assign({}, params))
this.api.call(connection, method, { ...params })
})
connection.close()
}

View File

@ -1,4 +1,3 @@
import assign from 'lodash.assign'
import {EventEmitter} from 'events'
import {
@ -12,7 +11,7 @@ export default class Model extends EventEmitter {
constructor (properties) {
super()
this.properties = assign({}, this.default)
this.properties = { ...this.default }
if (properties) {
this.set(properties)

View File

@ -1,5 +1,3 @@
import assign from 'lodash.assign'
import Collection from '../collection/redis'
import Model from '../model'
import { forEach } from '../utils'
@ -33,9 +31,10 @@ export class PluginsMetadata extends Collection {
throw new Error('no such plugin metadata')
}
const {properties} = pluginMetadata
assign(properties, data)
return await this.save(properties)
return await this.save({
...pluginMetadata.properties,
...data
})
}
async get (properties) {

View File

@ -1,4 +1,3 @@
import assign from 'lodash.assign'
import createDebug from 'debug'
import WebSocket from 'ws'
@ -12,9 +11,11 @@ const defaults = {
// Proxy a WebSocket `client` to a remote server which has `url` as
// address.
export default function wsProxy (client, url, opts) {
opts = assign({}, defaults, {
protocol: client.protocol
}, opts)
opts = {
...defaults,
protocol: client.protocol,
...opts
}
const autoClose = !!opts.autoClose
delete opts.autoClose

View File

@ -1,4 +1,3 @@
import assign from 'lodash.assign'
import createDebug from 'debug'
import d3TimeFormat from 'd3-time-format'
import escapeStringRegexp from 'escape-string-regexp'
@ -648,7 +647,7 @@ export default class Xapi extends XapiBase {
}
this._setObjectProperties(vm, {
HVM_boot_params: assign({}, bootParams, { order })
HVM_boot_params: { ...bootParams, order }
})
}
} else { // PV

View File

@ -1,5 +1,4 @@
// import XoView from 'xo-collection/view'
import assign from 'lodash.assign'
import createJsonSchemaValidator from 'is-my-json-valid'
import endsWith from 'lodash.endswith'
import escapeStringRegexp from 'escape-string-regexp'
@ -645,7 +644,7 @@ export default class Xo extends EventEmitter {
// -----------------------------------------------------------------
_developRemote (remote) {
const _remote = assign({}, remote)
const _remote = { ...remote }
if (startsWith(_remote.url, 'file://')) {
_remote.type = 'local'
_remote.path = _remote.url.slice(6)