-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcman.js
127 lines (127 loc) · 4.33 KB
/
cman.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
var CMan, component, gcomponent;
var __slice = Array.prototype.slice, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (this[i] === item) return i;
}
return -1;
};
component = require('./component-core');
CMan = {
genInit: function(func) {
var init;
init = function() {
var args, c, lookup, _i, _j, _len, _len2, _ref, _ref2;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
this.id = CMan.genGUID();
if (this._lookup != null) {
_ref = this._lookup;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
lookup = _ref[_i];
if (lookup instanceof Array) {
lookup.push(this);
} else {
lookup[this.id] = this;
}
}
}
if (this._compInit != null) {
_ref2 = this._compInit;
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
c = _ref2[_j];
c.apply(this);
}
}
if (func != null) {
func.apply(this, args);
}
return null;
};
init._generated = true;
return init;
},
genRemove: function(func) {
var remove;
return remove = function() {
var args, i, lookup, newLookup, obj, _i, _len, _len2, _ref;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (this._lookup != null) {
_ref = this._lookup;
for (i = 0, _len = _ref.length; i < _len; i++) {
lookup = _ref[i];
if (lookup instanceof Array) {
newLookup = lookup.splice(0, lookup.length).filter(__bind(function(obj) {
return obj.id !== this.id;
}, this));
for (_i = 0, _len2 = newLookup.length; _i < _len2; _i++) {
obj = newLookup[_i];
lookup.push(obj);
}
} else {
delete lookup[this.id];
}
}
}
return func != null ? func.apply(this, args) : void 0;
};
},
genGUID: function() {
return Math.round(1000000 * Math.random());
}
};
gcomponent = function() {
var additions, c, compInit, compInits, components, init, lookup, lookups, remove, _i, _j, _k, _len, _len2, _len3, _ref, _ref2, _ref3, _ref4, _ref5;
components = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
compInits = [];
lookups = [];
for (_i = 0, _len = components.length; _i < _len; _i++) {
c = components[_i];
c = (_ref = c.prototype) != null ? _ref : c;
if (c._lookup != null) {
_ref2 = c._lookup;
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
lookup = _ref2[_j];
if (__indexOf.call(lookups, lookup) < 0) {
lookups.push(lookup);
}
}
}
if ((c.lookup != null) && !(_ref3 = c.lookup, __indexOf.call(lookups, _ref3) >= 0)) {
lookups.push(c.lookup);
}
if (c._compInit != null) {
_ref4 = c._compInit;
for (_k = 0, _len3 = _ref4.length; _k < _len3; _k++) {
compInit = _ref4[_k];
if (__indexOf.call(compInits, compInit) < 0) {
compInits.push(compInit);
}
}
}
if ((c.compInit != null) && !(_ref5 = c.compInit, __indexOf.call(compInits, _ref5) >= 0)) {
compInits.push(c.compInit);
}
if ((c.init != null) && typeof c.init === 'function') {
init = c.init._generated != null ? c.init : CMan.genInit(c.init);
} else if ((c.init != null) && typeof c.init !== 'function') {
throw new TypeError("'init' property should be a function, but got:\n" + c.init);
}
if ((c.remove != null) && typeof c.remove === 'function') {
if (c.remove._generated == null) {
remove = CMan.genRemove(c.remove);
}
} else if ((c.remove != null) && typeof c.remove !== 'function') {
throw new TypeError("'remove' property should be a function, but got:\n" + c.remove);
}
}
additions = {
_lookup: lookups,
_compInit: compInits,
init: init != null ? init : CMan.genInit(),
remove: remove != null ? remove : CMan.genRemove()
};
return component.apply(null, [arguments.callee.baseObject].concat(__slice.call(components), [additions]));
};
gcomponent.baseObject = {};
if ((typeof module !== "undefined" && module !== null ? module.exports : void 0) != null) {
module.exports = gcomponent;
}