-
Notifications
You must be signed in to change notification settings - Fork 1
/
classy-extends.js
107 lines (102 loc) · 4.07 KB
/
classy-extends.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
(function() {
var classObjs, extends_module, waitingClassConstructors,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
extends_module = angular.module('classy-extends', ['classy.core']);
classObjs = {};
waitingClassConstructors = {};
extends_module.classy.plugin.controller({
name: 'extends',
options: {
enabled: true,
"super": '_super'
},
fnTest: (function() {
var fn;
fn = void 0;
return function() {
if (fn == null) {
fn = /xyz/.test('function(){xyz;}') ? RegExp("\\b" + this.options["super"] + "\\b") : /.*/;
}
return fn;
};
})(),
extend: function(classConstructor, classObj, baseClassObj) {
var extra, isInitialized, key, lenInject, processMethods, val, _i, _ref, _ref1, _ref2, _results;
processMethods = (function(_this) {
return function(baseClassMethods, classMethods) {
var prop, _results;
if (!classMethods) {
return;
}
_results = [];
for (prop in baseClassMethods) {
if (typeof classMethods[prop] === 'undefined') {
_results.push(classMethods[prop] = classConstructor.prototype[prop] = baseClassMethods[prop]);
} else if (angular.isFunction(classMethods[prop]) && _this.fnTest().test(classMethods[prop]) && prop !== 'constructor') {
_results.push(classMethods[prop] = classConstructor.prototype[prop] = (function(name, fn, parentName) {
return function() {
var ret, self, tmp;
tmp = this[parentName];
self = this;
this[parentName] = function(args) {
return baseClassMethods[name].apply(self, args || []);
};
ret = fn.apply(this, arguments);
this[parentName] = tmp;
return ret;
};
})(prop, classMethods[prop], _this.options["super"]));
} else {
_results.push(void 0);
}
}
return _results;
};
})(this);
processMethods(baseClassObj.methods, classObj.methods);
processMethods(baseClassObj, classObj);
isInitialized = classConstructor.__classDepNames != null;
_ref = baseClassObj.inject;
for (key in _ref) {
val = _ref[key];
classObj.inject.push(val);
if (isInitialized) {
if (__indexOf.call(classConstructor.$inject, val) < 0) {
lenInject = classConstructor.$inject.length;
classConstructor.$inject.push(val);
extra = (function() {
_results = [];
for (var _i = 0, _ref1 = lenInject - classConstructor.__classDepNames.length; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; 0 <= _ref1 ? _i++ : _i--){ _results.push(_i); }
return _results;
}).apply(this).map((function(_this) {
return function(x) {
return "";
};
})(this));
(_ref2 = classConstructor.__classDepNames).push.apply(_ref2, extra);
classConstructor.__classDepNames.push(val);
}
}
}
},
preInitBefore: function(classConstructor, classObj, module) {
var baseClass, baseClassObj, className, waitingClassConstructor, waitingClassObj;
if (baseClass = classObj["extends"]) {
baseClassObj = classObjs[baseClass];
if (baseClassObj) {
this.extend(classConstructor, classObj, baseClassObj);
} else {
waitingClassConstructors[classObj.name] = classConstructor;
}
}
classObjs[classObj.name] = classObj;
for (className in waitingClassConstructors) {
waitingClassConstructor = waitingClassConstructors[className];
waitingClassObj = classObjs[className];
if (waitingClassObj["extends"] === classObj.name) {
this.extend(waitingClassConstructor, waitingClassObj, classObj);
}
}
}
});
}).call(this);