mirror of
https://github.com/tenrok/vue-tribute.git
synced 2026-06-19 13:10:36 +03:00
remove timeout in param watcher, add test to ensure param watcher gets called
This commit is contained in:
@@ -14,15 +14,11 @@ exports.install = function (Vue, options) {
|
||||
tribute: null,
|
||||
paramWatchers: {
|
||||
values: function values(val, oldVal) {
|
||||
var _this = this;
|
||||
|
||||
setTimeout(function () {
|
||||
_this.setValues(val);
|
||||
}, 0);
|
||||
this.setValues(val);
|
||||
}
|
||||
},
|
||||
bind: function bind() {
|
||||
var _this2 = this;
|
||||
var _this = this;
|
||||
|
||||
// If it has a "values" property, it's actually a collection
|
||||
if (this.params.values.hasOwnProperty("values")) {
|
||||
@@ -37,10 +33,10 @@ exports.install = function (Vue, options) {
|
||||
|
||||
this.tribute.attach(this.el);
|
||||
this.el.addEventListener("tribute-replaced", function (e) {
|
||||
_this2.vm.$emit("tribute-replaced");
|
||||
_this.vm.$emit("tribute-replaced");
|
||||
});
|
||||
this.el.addEventListener("tribute-no-match", function (e) {
|
||||
_this2.vm.$emit("tribute-no-match");
|
||||
_this.vm.$emit("tribute-no-match");
|
||||
});
|
||||
},
|
||||
setValues: function setValues(values) {
|
||||
|
||||
+4
-8
@@ -16,15 +16,11 @@
|
||||
tribute: null,
|
||||
paramWatchers: {
|
||||
values: function values(val, oldVal) {
|
||||
var _this = this;
|
||||
|
||||
setTimeout(function () {
|
||||
_this.setValues(val);
|
||||
}, 0);
|
||||
this.setValues(val);
|
||||
}
|
||||
},
|
||||
bind: function bind() {
|
||||
var _this2 = this;
|
||||
var _this = this;
|
||||
|
||||
// If it has a "values" property, it's actually a collection
|
||||
if (this.params.values.hasOwnProperty("values")) {
|
||||
@@ -39,10 +35,10 @@
|
||||
|
||||
this.tribute.attach(this.el);
|
||||
this.el.addEventListener("tribute-replaced", function (e) {
|
||||
_this2.vm.$emit("tribute-replaced");
|
||||
_this.vm.$emit("tribute-replaced");
|
||||
});
|
||||
this.el.addEventListener("tribute-no-match", function (e) {
|
||||
_this2.vm.$emit("tribute-no-match");
|
||||
_this.vm.$emit("tribute-no-match");
|
||||
});
|
||||
},
|
||||
setValues: function setValues(values) {
|
||||
|
||||
+1
-3
@@ -10,9 +10,7 @@ exports.install = function (Vue, options) {
|
||||
tribute: null,
|
||||
paramWatchers: {
|
||||
values (val, oldVal) {
|
||||
setTimeout(() => {
|
||||
this.setValues(val)
|
||||
}, 0)
|
||||
this.setValues(val)
|
||||
}
|
||||
},
|
||||
bind () {
|
||||
|
||||
+36
-17
@@ -2,24 +2,43 @@ import Vue from "vue";
|
||||
import VueTribute from "../src";
|
||||
|
||||
Vue.use(VueTribute);
|
||||
|
||||
var vm = null
|
||||
beforeEach(() => {
|
||||
vm = new Vue({
|
||||
el: document.body,
|
||||
replace: false,
|
||||
template: "<input type='text' :values='items' v-tribute />",
|
||||
data(){
|
||||
return {
|
||||
items: [
|
||||
{key: "Phil Heartman", value: "pheartman"},
|
||||
{key: "Gordon Ramsey", value: "gramsey"}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
describe("vue-tribute", () => {
|
||||
it("has an install method for Vue.use()", () => {
|
||||
expect(typeof VueTribute.install).toEqual("function");
|
||||
});
|
||||
it("creates the v-tribute directive", () => {
|
||||
const vm = new Vue({
|
||||
template: "<input type='text' :values='items' v-tribute />",
|
||||
data(){
|
||||
return {
|
||||
items: [
|
||||
{key: "Phil Heartman", value: "pheartman"},
|
||||
{key: "Gordon Ramsey", value: "gramsey"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}).$mount();
|
||||
expect(typeof VueTribute.install).toEqual("function")
|
||||
})
|
||||
|
||||
expect(typeof vm.$options.directives["tribute"]).toEqual("object");
|
||||
});
|
||||
it("creates the v-tribute directive", () => {
|
||||
expect(typeof vm.$options.directives["tribute"]).toEqual("object")
|
||||
})
|
||||
|
||||
it("triggers the param watcher when the underlying model changes", (done) => {
|
||||
spyOn(vm.$options.directives["tribute"].paramWatchers, "values").and.callThrough()
|
||||
|
||||
const newItems = [
|
||||
{key: "Kerem Suer", value: "kerem"},
|
||||
{key: "Rob Delaney", value: "robdelaney"}
|
||||
]
|
||||
vm.$set("items", newItems)
|
||||
|
||||
setTimeout(() => {
|
||||
expect(vm.$options.directives["tribute"].paramWatchers.values).toHaveBeenCalled()
|
||||
done()
|
||||
}, 0)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user