/
Delegate.js
67 lines (43 loc) · 2.01 KB
/
Delegate.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
Role('Joose.Attribute.Delegate', {
have : {
handles : null
},
override : {
eachDelegate : function (handles, func, scope) {
if (typeof handles == 'string') return func.call(scope, handles, handles)
if (handles instanceof Array)
return Joose.A.each(handles, function (delegateTo) {
func.call(scope, delegateTo, delegateTo)
})
if (handles === Object(handles))
Joose.O.eachOwn(handles, function (delegateTo, handleAs) {
func.call(scope, handleAs, delegateTo)
})
},
getAccessorsFor : function (targetClass) {
var targetMeta = targetClass.meta
var methods = this.SUPER(targetClass)
var me = this
this.eachDelegate(this.handles, function (handleAs, delegateTo) {
if (!targetMeta.hasMethod(handleAs)) {
var handler = methods[ handleAs ] = function () {
var attrValue = me.getValueFrom(this)
return attrValue[ delegateTo ].apply(attrValue, arguments)
}
handler.ACCESSOR_FROM = me
}
})
return methods
},
getAccessorsFrom : function (from) {
var methods = this.SUPER(from)
var me = this
var targetMeta = from.meta
this.eachDelegate(this.handles, function (handleAs) {
var handler = targetMeta.getMethod(handleAs)
if (handler && handler.value.ACCESSOR_FROM == me) methods.push(handleAs)
})
return methods
}
}
})