1
|
import { createEvent, extend, fastdom, isArray, isFunction, isPlainObject, ready } from '../util/index';
|
2
|
|
3
|
export default function (UIkit) {
|
4
|
|
5
|
UIkit.prototype._callHook = function (hook) {
|
6
|
|
7
|
var handlers = this.$options[hook];
|
8
|
|
9
|
if (handlers) {
|
10
|
handlers.forEach(handler => handler.call(this));
|
11
|
}
|
12
|
};
|
13
|
|
14
|
UIkit.prototype._callReady = function () {
|
15
|
|
16
|
if (this._isReady) {
|
17
|
return;
|
18
|
}
|
19
|
|
20
|
this._isReady = true;
|
21
|
this._callHook('ready');
|
22
|
this._callUpdate();
|
23
|
};
|
24
|
|
25
|
UIkit.prototype._callConnected = function () {
|
26
|
|
27
|
if (this._connected) {
|
28
|
return;
|
29
|
}
|
30
|
|
31
|
if (!~UIkit.elements.indexOf(this.$options.el)) {
|
32
|
UIkit.elements.push(this.$options.el);
|
33
|
}
|
34
|
|
35
|
UIkit.instances[this._uid] = this;
|
36
|
|
37
|
this._initEvents();
|
38
|
|
39
|
this._callHook('connected');
|
40
|
this._connected = true;
|
41
|
|
42
|
this._initObserver();
|
43
|
|
44
|
if (!this._isReady) {
|
45
|
ready(() => this._callReady());
|
46
|
}
|
47
|
|
48
|
this._callUpdate();
|
49
|
};
|
50
|
|
51
|
UIkit.prototype._callDisconnected = function () {
|
52
|
|
53
|
if (!this._connected) {
|
54
|
return;
|
55
|
}
|
56
|
|
57
|
if (this._observer) {
|
58
|
this._observer.disconnect();
|
59
|
this._observer = null;
|
60
|
}
|
61
|
|
62
|
var index = UIkit.elements.indexOf(this.$options.el);
|
63
|
|
64
|
if (~index) {
|
65
|
UIkit.elements.splice(index, 1);
|
66
|
}
|
67
|
|
68
|
delete UIkit.instances[this._uid];
|
69
|
|
70
|
this._initEvents(true);
|
71
|
this._callHook('disconnected');
|
72
|
|
73
|
this._connected = false;
|
74
|
|
75
|
};
|
76
|
|
77
|
UIkit.prototype._callUpdate = function (e) {
|
78
|
|
79
|
e = createEvent(e || 'update');
|
80
|
|
81
|
if (e.type === 'update') {
|
82
|
this._computeds = {};
|
83
|
}
|
84
|
|
85
|
var updates = this.$options.update;
|
86
|
|
87
|
if (!updates) {
|
88
|
return;
|
89
|
}
|
90
|
|
91
|
updates.forEach((update, i) => {
|
92
|
|
93
|
if (e.type !== 'update' && (!update.events || !~update.events.indexOf(e.type))) {
|
94
|
return;
|
95
|
}
|
96
|
|
97
|
if (e.sync) {
|
98
|
|
99
|
if (update.read) {
|
100
|
update.read.call(this, e);
|
101
|
}
|
102
|
|
103
|
if (update.write) {
|
104
|
update.write.call(this, e);
|
105
|
}
|
106
|
|
107
|
return;
|
108
|
|
109
|
}
|
110
|
|
111
|
if (update.read && !~fastdom.reads.indexOf(this._frames.reads[i])) {
|
112
|
this._frames.reads[i] = fastdom.measure(() => update.read.call(this, e));
|
113
|
}
|
114
|
|
115
|
if (update.write && !~fastdom.writes.indexOf(this._frames.writes[i])) {
|
116
|
this._frames.writes[i] = fastdom.mutate(() => update.write.call(this, e));
|
117
|
}
|
118
|
|
119
|
});
|
120
|
|
121
|
};
|
122
|
|
123
|
}
|