1
|
import { $, createEvent } from '../util/index';
|
2
|
|
3
|
export default function (UIkit) {
|
4
|
|
5
|
const DATA = UIkit.data;
|
6
|
|
7
|
UIkit.prototype.$mount = function (el) {
|
8
|
|
9
|
var name = this.$options.name;
|
10
|
|
11
|
if (!el[DATA]) {
|
12
|
el[DATA] = {};
|
13
|
}
|
14
|
|
15
|
if (el[DATA][name]) {
|
16
|
console.warn(`Component "${name}" is already mounted on element: `, el);
|
17
|
return;
|
18
|
}
|
19
|
|
20
|
el[DATA][name] = this;
|
21
|
|
22
|
this.$el = $(el);
|
23
|
|
24
|
this._initProps();
|
25
|
|
26
|
this._callHook('init');
|
27
|
|
28
|
if (document.documentElement.contains(el)) {
|
29
|
this._callConnected();
|
30
|
}
|
31
|
};
|
32
|
|
33
|
UIkit.prototype.$emit = function (e) {
|
34
|
this._callUpdate(e);
|
35
|
};
|
36
|
|
37
|
UIkit.prototype.$emitSync = function (e) {
|
38
|
this._callUpdate(createEvent(e || 'update', true, false, {sync: true}));
|
39
|
};
|
40
|
|
41
|
UIkit.prototype.$update = function (e, parents) {
|
42
|
UIkit.update(e, this.$el, parents);
|
43
|
};
|
44
|
|
45
|
UIkit.prototype.$updateSync = function (e, parents) {
|
46
|
this.$update(createEvent(e || 'update', true, false, {sync: true}), parents);
|
47
|
};
|
48
|
|
49
|
UIkit.prototype.$reset = function (data) {
|
50
|
this._callDisconnected();
|
51
|
this._initProps(data);
|
52
|
this._callConnected();
|
53
|
};
|
54
|
|
55
|
UIkit.prototype.$destroy = function (remove = false) {
|
56
|
|
57
|
var el = this.$options.el;
|
58
|
|
59
|
if (el) {
|
60
|
this._callDisconnected();
|
61
|
}
|
62
|
|
63
|
this._callHook('destroy');
|
64
|
|
65
|
if (!el || !el[DATA]) {
|
66
|
return;
|
67
|
}
|
68
|
|
69
|
delete el[DATA][this.$options.name];
|
70
|
|
71
|
if (!Object.keys(el[DATA]).length) {
|
72
|
delete el[DATA];
|
73
|
}
|
74
|
|
75
|
if (remove) {
|
76
|
this.$el.remove();
|
77
|
}
|
78
|
};
|
79
|
|
80
|
}
|