diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..043daa7 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,7 @@ +{ + "extends": "standard", + "rules": { + "arrow-parens": [2, "as-needed"], + "quotes": [2, "double"] + } +} diff --git a/index.js b/index.js index 8ae63d2..4f22f94 100644 --- a/index.js +++ b/index.js @@ -30,10 +30,9 @@ exports.install = function (Vue, options) { collection: this.params.values }); } else { - this.tribute = new Tribute({ - values: this.params.values, - options: options - }); + this.tribute = new Tribute(Object.assign({ + values: this.params.values + }, options)); } this.tribute.attach(this.el); diff --git a/index.umd.js b/index.umd.js index 5c74e21..3d695d8 100644 --- a/index.umd.js +++ b/index.umd.js @@ -32,10 +32,9 @@ collection: this.params.values }); } else { - this.tribute = new Tribute({ - values: this.params.values, - options: options - }); + this.tribute = new Tribute(Object.assign({ + values: this.params.values + }, options)); } this.tribute.attach(this.el); diff --git a/package.json b/package.json index 8c7442f..9b1f705 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,8 @@ "example": "vbuild --dev", "example:build": "vbuild -t VueTribute", "test": "karma start karma.conf.js --single-run true --auto-watch false", - "watch-test": "karma start karma.conf.js --single-run false --auto-watch true" + "watch-test": "karma start karma.conf.js --single-run false --auto-watch true", + "lint": "eslint src" }, "main": "index.js", "files": [ @@ -42,6 +43,10 @@ "babel-runtime": "^6.9.2", "babelify": "^7.3.0", "browserify": "^13.0.1", + "eslint": "^3.1.1", + "eslint-config-standard": "^5.3.5", + "eslint-plugin-promise": "^2.0.0", + "eslint-plugin-standard": "^2.0.0", "jasmine-core": "^2.4.1", "karma": "^1.1.1", "karma-browserify": "^5.1.0", diff --git a/src/index.js b/src/index.js index cf80a9f..5633c53 100644 --- a/src/index.js +++ b/src/index.js @@ -1,51 +1,47 @@ -import Tribute from "tributejs"; +import Tribute from "tributejs" -if(!Tribute){ +if (!Tribute) { throw new Error("[vue-tribute] cannot locate tributejs") } -exports.install = function(Vue, options){ +exports.install = function (Vue, options) { Vue.directive("tribute", { params: ["values"], tribute: null, paramWatchers: { - values(val, oldVal){ + values (val, oldVal) { setTimeout(() => { - this.setValues(val); + this.setValues(val) }, 0) } }, - bind(){ + bind () { // If it has a "values" property, it's actually a collection - if( this.params.values.hasOwnProperty("values") ){ + if (this.params.values.hasOwnProperty("values")) { this.tribute = new Tribute({ - collection: this.params.values, - }); - } - else { - this.tribute = new Tribute({ - values: this.params.values, - options - }); + collection: this.params.values + }) + } else { + this.tribute = new Tribute(Object.assign({ + values: this.params.values + }, options)) } - this.tribute.attach(this.el); - this.el.addEventListener("tribute-replaced", (e) => { - this.vm.$emit("tribute-replaced"); - }); - this.el.addEventListener("tribute-no-match", (e) => { - this.vm.$emit("tribute-no-match"); - }); + this.tribute.attach(this.el) + this.el.addEventListener("tribute-replaced", e => { + this.vm.$emit("tribute-replaced") + }) + this.el.addEventListener("tribute-no-match", e => { + this.vm.$emit("tribute-no-match") + }) }, - setValues(values){ + setValues (values) { // If it has a "values" property, it's actually a collection - if( values.hasOwnProperty("values") ){ - this.tribute.collection = values; - } - else { - this.tribute.collection[0].values = values; + if (values.hasOwnProperty("values")) { + this.tribute.collection = values + } else { + this.tribute.collection[0].values = values } } - }); - + }) }