From 74c9a570700e745f16575e243ada3fbaba88c17e Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Mon, 9 Nov 2015 14:09:29 +0100 Subject: [PATCH] Replace lodash.assign() with ES2016 object spread. --- src/api.js | 10 +++++----- src/index.js | 4 +--- src/job-executor.js | 2 +- src/model.js | 3 +-- src/models/plugin-metadata.js | 9 ++++----- src/ws-proxy.js | 9 +++++---- src/xapi.js | 3 +-- src/xo.js | 3 +-- 8 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/api.js b/src/api.js index cb7d9416a..d489b2a36 100644 --- a/src/api.js +++ b/src/api.js @@ -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' diff --git a/src/index.js b/src/index.js index 59daeb85d..c8f3bd439 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/src/job-executor.js b/src/job-executor.js index 54e9bc393..a1b75b088 100644 --- a/src/job-executor.js +++ b/src/job-executor.js @@ -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() } diff --git a/src/model.js b/src/model.js index 67452f71a..1e18a8ea0 100644 --- a/src/model.js +++ b/src/model.js @@ -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) diff --git a/src/models/plugin-metadata.js b/src/models/plugin-metadata.js index b15b8ef3f..985bf5beb 100644 --- a/src/models/plugin-metadata.js +++ b/src/models/plugin-metadata.js @@ -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) { diff --git a/src/ws-proxy.js b/src/ws-proxy.js index 2bc258bf6..eababee28 100644 --- a/src/ws-proxy.js +++ b/src/ws-proxy.js @@ -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 diff --git a/src/xapi.js b/src/xapi.js index 075c272bc..d66461484 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -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 diff --git a/src/xo.js b/src/xo.js index cf277f116..601a8093b 100644 --- a/src/xo.js +++ b/src/xo.js @@ -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)