-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (29 loc) · 920 Bytes
/
index.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
exports.getterThrottle = function (delay) {
if (!delay) delay = 0;
return function(target, key, descriptor) {
var dependencies = descriptor.get.dependencies;
var originalGetter = descriptor.get;
var innerPropertyName = '_au_gt_' + key;
var clearInnerProperty = function() {
delete this[innerPropertyName];
};
descriptor.get = function() {
if (this.hasOwnProperty(innerPropertyName)) {
return this[innerPropertyName];
}
Object.defineProperty(this, innerPropertyName, {
value: originalGetter.call(this),
configurable: true,
enumerable: false,
writable: true
});
setTimeout(clearInnerProperty.bind(this), delay);
return this[innerPropertyName];
};
if (dependencies) {
descriptor.get.dependencies = dependencies;
delete originalGetter.dependencies;
}
return descriptor;
};
};