-
Notifications
You must be signed in to change notification settings - Fork 10
/
vue.js
57 lines (51 loc) · 1.35 KB
/
vue.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Vue from "vue";
export default (Component, style = {}, tag = "span") =>
Vue.component("vue-svelte-adaptor", {
render(createElement) {
return createElement(tag, {
ref: "container",
props: this.$attrs,
style
});
},
data() {
return {
comp: null
};
},
mounted() {
this.comp = new Component({
target: this.$refs.container,
props: this.$attrs
});
let watchers = [];
for (const key in this.$listeners) {
this.comp.$on(key, this.$listeners[key]);
const watchRe = /watch:([^]+)/;
const watchMatch = key.match(watchRe);
if (watchMatch && typeof this.$listeners[key] === "function") {
watchers.push([
`${watchMatch[1][0].toLowerCase()}${watchMatch[1].slice(1)}`,
this.$listeners[key]
]);
}
}
if (watchers.length) {
let comp = this.comp;
const update = this.comp.$$.update;
this.comp.$$.update = function() {
watchers.forEach(([name, callback]) => {
const index = comp.$$.props[name];
callback(comp.$$.ctx[index]);
});
update.apply(null, arguments);
};
}
},
updated() {
this.comp.$set(this.$attrs);
},
destroyed() {
this.comp.$destroy();
}
});