Skip to content

Commit

Permalink
Don't use ES2015 syntax to allow Babel removal
Browse files Browse the repository at this point in the history
  • Loading branch information
FloEdelmann committed Aug 8, 2018
1 parent 4cb56a6 commit baca113
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 133 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/dist
/tests
27 changes: 26 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module.exports = {
env: {
node: true
},
"plugins": [
"no-es2015"
],
extends: [
'plugin:vue/recommended',
'eslint:recommended'
Expand All @@ -14,6 +17,8 @@ module.exports = {
"semi": "error",
"no-trailing-spaces": "error",
"comma-dangle": ["error", "never"],
"quotes": ["error", "single"],
"no-template-curly-in-string": "error",
"vue/max-attributes-per-line": ["error", { "singleline": 3 }],
"vue/html-closing-bracket-newline": "error",
"vue/html-closing-bracket-spacing": "error",
Expand All @@ -24,7 +29,7 @@ module.exports = {
"MethodDefinition": true,
"ClassDeclaration": true,
"ArrowFunctionExpression": false,
"FunctionExpression": true
"FunctionExpression": false
}
}],
"valid-jsdoc": ["error", {
Expand Down Expand Up @@ -59,6 +64,26 @@ module.exports = {
"String": "string"
}
}],

// Don't use ES2015 at all, so we don't need a transpiler like Babel.
// This reduces the bundle size dramatically.
"no-es2015/no-object-computed-properties": "error",
"no-es2015/no-object-shorthand-properties": "error",
"no-es2015/no-object-shorthand-method": "error",
"no-es2015/only-var": "error",
"no-es2015/no-destructuring-assignment": "error",
"no-es2015/no-destructuring-params": "error",
"no-es2015/no-class": "error",
"no-es2015/no-default-params": "error",
"no-es2015/no-spread-element": "error",
"no-es2015/no-rest-params": "error",
"no-es2015/no-generator-function": "error",
"no-es2015/no-arrow-func": "error",
"no-es2015/no-for-of": "error",
"no-es2015/no-template-string": "error",

// using import is allowed, since webpack gets rid of it automatically
"no-es2015/no-import": "off"
},
parserOptions: {
parser: 'babel-eslint'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@vue/cli-service": "^3.0.0-rc.10",
"@vue/test-utils": "^1.0.0-beta.20",
"chai": "^4.1.2",
"eslint-plugin-no-es2015": "^1.2.0",
"node-sass": "^4.9.2",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
Expand Down
27 changes: 15 additions & 12 deletions src/components/EmbettyEmbed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
/**
* @returns {!object} Component's data.
*/
data() {
data: function() {
return {
embettyLogo: EMBETTY_LOGO,
Expand All @@ -27,20 +27,20 @@ export default {
* Override this in child components!
* @returns {string | undefined} The URL to query for data in this component.
*/
url() {
url: function() {
return undefined;
},
/**
* @returns {!string} The server URL, either from this component's prop or the global config.
*/
_serverUrl() {
_serverUrl: function() {
if (this.serverUrl) {
return this.serverUrl;
}
if (!this._embettyVueOptions.serverUrl) {
throw new Error(`serverUrl is neither set directly on the ${this.$vnode.tag} component nor globally.`);
throw new Error('serverUrl is neither set directly on the ' + this.$vnode.tag + ' component nor globally.');
}
return this._embettyVueOptions.serverUrl;
Expand All @@ -52,7 +52,7 @@ export default {
/**
* @param {?string} url The newly set URL.
*/
handler(url) {
handler: function(url) {
if (url) {
this.fetchData();
}
Expand All @@ -63,21 +63,24 @@ export default {
/**
* Calls the API of embetty-server using the url set in the calling (child) component.
*/
fetchData() {
fetchData: function() {
var thisCmp = this;
window.fetch(this.url)
.then(response => response.json())
.then(data => {
this.data = data;
this.fetched = true;
.then(function (response) {
return response.json();
})
.then(function (data) {
thisCmp.data = data;
thisCmp.fetched = true;
});
},
/**
* @param {?string} apiEndpoint The API endpoint of the embetty-server.
* @returns {?string} The given URL, prepended with the embetty-server base URL.
*/
_api(apiEndpoint) {
return apiEndpoint ? `${this._serverUrl}${apiEndpoint}` : undefined;
_api: function(apiEndpoint) {
return apiEndpoint ? (this._serverUrl + apiEndpoint) : undefined;
}
}
};
Expand Down
Loading

0 comments on commit baca113

Please sign in to comment.