This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUx.mixin.CustomBindable.js
109 lines (90 loc) · 2.45 KB
/
Ux.mixin.CustomBindable.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Ext.define('Ux.mixin.CustomBindable', {
extend: 'Ext.Mixin',
mixinConfig: {
id: 'customBindable',
after: {
initComponent: 'initCustomBindable'
},
before: {
destroy: 'destroy'
}
},
config: {
customBindings: {
$value: [],
lazy: true
}
},
initCustomBindable: function () {
var me = this;
var bindings;
var config;
if (me.initCustomBindings) {
bindings = me.initCustomBindings();
Ext.apply(me.config, {
customBindings: bindings
});
}
me.on({
scope: me,
activate: function () {
var me = this;
if (!me.customBindings) {
me.getCustomBindings();
} else {
me.mixins.customBindable.enable.call(me);
}
},
deactivate: function () {
this.mixins.customBindable.disable.call(this);
}
});
},
applyCustomBindings: function (bindings) {
var i,ln;
var binding;
var bounds = [];
var vm = this.lookupViewModel();
for (i = 0, ln = bindings.length; i < ln; i++) {
binding = vm.bind(
bindings[i].bind,
bindings[i].get,
this,
{
twoWay: false
}
);
bounds.push(binding);
}
return bounds;
},
enable: function () {
var i,ln;
var bindings = this.getCustomBindings();
var scheduler;
for (i = 0, ln = bindings.length; i < ln; i++) {
scheduler = bindings[i].getScheduler();
scheduler.add(bindings[i]);
bindings[i].schedule();
}
if (scheduler) {
scheduler.notify();
}
},
disable: function () {
var i,ln;
var bindings = this.getCustomBindings();
var scheduler;
for (i = 0, ln = bindings.length; i < ln; i++) {
scheduler = bindings[i].getScheduler();
scheduler.remove(bindings[i]);
}
},
destroy: function () {
var me = this;
if (me.customBindings) {
me.mixins.customBindable.disable.call(me);
me.setCustomBindings([]);
}
}
});