forked from DerivcoIpswich/dsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDelegate.js
More file actions
127 lines (107 loc) · 2.99 KB
/
Copy pathDelegate.js
File metadata and controls
127 lines (107 loc) · 2.99 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function _bindList(fnList) {
var d = function (){
var args = arguments;
var result = null;
for (var i = 0, l = fnList.length; i < l; i++) {
result = args.length
? fnList[i].apply(null, args)
: fnList[i].call(null);
}
return result;
};
d._fnList = fnList;
return d;
}
function bind(fn, o) {
if (!o) {
return fn;
}
var name = null;
fn = typeof fn === 'string'
? o[name = fn]
: fn;
return internalBind(fn, o, name);
}
function baseBind(fn, o) {
if (!o) {
return fn;
}
var name = null;
if (typeof fn === 'string') {
name = fn;
fn = o.constructor.$base.prototype[name];
if (!fn) {
throw new Error("Unable to find '" + name + "' on any of the prototype hierarcy for " + o);
}
}
return internalBind(fn, o, name);
}
function internalBind(fn, instance, name) {
if (typeof fn !== 'function') {
throw new Error("binding requires a function instance!");
}
var cache = name ? instance.$$b || (instance.$$b = {}) : null;
var binding = cache ? cache[name] : null;
if (!binding) {
// Create a function that invokes the specified function, in the
// context of the specified object.
binding = function () {
return fn.apply(instance, arguments);
};
if (cache) {
cache[name] = binding;
}
}
return binding;
}
function bindAdd(binding, value) {
if (!binding) {
return value;
}
if (!value) {
return binding;
}
var fnList = [].concat(binding._fnList || binding, value);
return _bindList(fnList);
}
function bindSub(binding, value) {
if (!binding) {
return null;
}
if (!value) {
return binding;
}
var fnList = binding._fnList || [binding];
var index = fnList.indexOf(value);
if (index >= 0) {
if (fnList.length === 1) {
return null;
}
fnList = index ? fnList.slice(0, index).concat(fnList.slice(index + 1)) : fnList.slice(1);
return _bindList(fnList);
}
return binding;
}
function bindExport(fn, multiUse, name, root) {
// Generate a unique name if one is not specified
name = name || '__' + (new Date()).valueOf();
// If unspecified, exported bindings go on the global object
// (so they are callable using a simple identifier).
root = root || self;
var exp = {
name: name,
detach: function () {
root[name] = _nop;
},
dispose: function () {
try { delete root[name]; } catch (e) { root[name] = undefined; }
}
};
// Multi-use bindings are exported directly; for the rest a stub is exported, and the stub
// first auto-disposes, and then invokes the actual binding.
root[name] = multiUse ? fn : function () {
exp.dispose();
return fn.apply(null, arguments);
};
return exp;
}