forked from apla/dataflo.ws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequire-browser.js
143 lines (118 loc) · 3.52 KB
/
require-browser.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// usage:
/*
<script src="require-browser.js"></script> <!-- sync loading -->
<script>
preloadAssets ();
</script>
*/
var _required = {
};
define ('fs', [], function () {});
define ('path', [], function () {});
define ('util', [], function () {
var util = {};
util.inherits = function (ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create (superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}});
};
util.class2type = {};
"Boolean Number String Function Array Date RegExp Object Error".split(" ").forEach (function(name, i) {
util.class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
util.isPlainObject = function isPlainObject (obj) {
var isObject = typeof obj === "object" || typeof obj === "function" ? util.class2type[{}.toString.call(obj)] || "object" : typeof obj;
if (isObject !== "object" || obj.nodeType || obj === obj.window) {
return false;
}
// Support: Firefox <20
// The try/catch suppresses exceptions thrown when attempting to access
// the "constructor" property of certain host objects, ie. |window.location|
// https://bugzilla.mozilla.org/show_bug.cgi?id=814622
try {
if (obj.constructor &&
!{}.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
return false;
}
} catch (e) {
return false;
}
// If the function hasn't returned already, we're confident that
// |obj| is a plain object, created by {} or constructed with new Object
return true;
};
util.extend = function extend () {
// copy reference to target object
var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options, name, src, copy;
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !typeof target === 'function')
target = {};
for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) !== null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
// Prevent never-ending loop
if (target === copy)
continue;
// Recurse if we're merging object literal values or arrays
if (deep && copy && (util.isPlainObject(copy) || Array.isArray(copy))) {
var clone = src && (util.isPlainObject(src) || Array.isArray(src)) ? src : Array.isArray(copy) ? [] : {};
// Never move original objects, clone them
target[name] = extend(deep, clone, copy);
// Don't bring in undefined values
} else if (typeof copy !== "undefined")
target[name] = copy;
}
}
}
// Return the modified object
return target;
}
return util;
});
define ('events', [], function () {
var events = module.exports = {
EventEmitter: function () {}
};
// move to event emitter
events.EventEmitter.prototype.on = function (type, cb) {
if (!this.cb)
this.cb = {};
if (!this.cb[type])
this.cb[type] = [];
this.cb[type].push (cb);
}
// TODO: add un method
events.EventEmitter.prototype.emit = function (type) {
if (!this.cb)
return;
if (!this.cb[type])
return;
var args = Array.prototype.slice.call(arguments);
args.shift ();
var self = this;
this.cb[type].map (function (item) {
item.apply (self, args)
});
}
return events;
});
util = {};
module = {
exports: {}
};