-
Notifications
You must be signed in to change notification settings - Fork 43
/
protoload.js
50 lines (40 loc) · 1.12 KB
/
protoload.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
// I can't remember why I was writing this... im sure I will need it sometime in the future though.
var system = {};
function Register(name,prototype) {
if (typeof (prototype.shutdown) !== 'function') {
console.log('Prototype must have a shutdown function');
}
// If not registered before then register
if (system[name] === undefined) {
system[name] = {};
system[name].__proto__ = prototype;
} else {
console.log('already exists');
// See if we can back up anything to transfer to new instance
var transfer;
if (typeof(system[name].transfer) === 'function') {
transfer = system[name].transfer();
}
system[name].__proto__ = prototype;
// If possible transfer our data we backed up
if (transfer !== undefined && typeof(system[name].transfer) === 'function' ) {
system[name].transfer(transfer);
}
}
return system[name];
}
function Unregister(name) {
if (system[name]) {
if (typeof(system[name].Unregister) === 'function') {
return system[name].Unregister();
}
}
}
function Get(name) {
return system[name];
}
module.exports = {
Register: Register,
Unregister: Unregister,
Get: Get
};