Add object rest spread transform

Object rest spread was standardised this year so it's safe to use. It
has shipped in major browsers and Node. Because Uppy uses immutable
state we can make a lot of gains in terseness and readability by using
the new object syntaxes, I think.

I updated one place where we were using Object.assign; I think we can
merge it like this first and then update the other places when we are
changing stuff there anyway.
This commit is contained in:
Renée Kooi 2018-07-16 14:26:30 +02:00
parent 944cbdf382
commit 68b4529ec7
No known key found for this signature in database
GPG key ID: 8CDD5F0BC448F040
4 changed files with 35 additions and 3 deletions

View file

@ -6,6 +6,7 @@
}]
],
"plugins": [
"transform-object-rest-spread",
"transform-object-assign",
["transform-react-jsx", { "pragma":"h" }]
]

28
package-lock.json generated
View file

@ -1734,6 +1734,34 @@
"babel-runtime": "^6.22.0"
}
},
"babel-plugin-transform-object-rest-spread": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-plugin-transform-object-rest-spread/-/babel-plugin-transform-object-rest-spread-6.26.0.tgz",
"integrity": "sha1-DzZpLVD+9rfi1LOsFHgTepY7ewY=",
"dev": true,
"requires": {
"babel-plugin-syntax-object-rest-spread": "^6.8.0",
"babel-runtime": "^6.26.0"
},
"dependencies": {
"babel-runtime": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-runtime/-/babel-runtime-6.26.0.tgz",
"integrity": "sha1-llxwWGaOgrVde/4E/yM3vItWR/4=",
"dev": true,
"requires": {
"core-js": "^2.4.0",
"regenerator-runtime": "^0.11.0"
}
},
"regenerator-runtime": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz",
"integrity": "sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==",
"dev": true
}
}
},
"babel-plugin-transform-proto-to-assign": {
"version": "6.26.0",
"resolved": "https://registry.npmjs.org/babel-plugin-transform-proto-to-assign/-/babel-plugin-transform-proto-to-assign-6.26.0.tgz",

View file

@ -14,6 +14,7 @@
"babel-core": "^6.26.3",
"babel-jest": "^22.4.4",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-proto-to-assign": "^6.26.0",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-polyfill": "^6.26.0",

View file

@ -49,11 +49,13 @@ module.exports = class Plugin {
}
setPluginState (update) {
const plugins = Object.assign({}, this.uppy.getState().plugins)
plugins[this.id] = Object.assign({}, plugins[this.id], update)
const { plugins } = this.uppy.getState()
this.uppy.setState({
plugins: plugins
plugins: {
...plugins,
[this.id]: update
}
})
}