-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistry.js
71 lines (62 loc) · 1.11 KB
/
registry.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
/**
* Registry is an overkill way to store and reuse data
* across all of our routes
*/
class Registry {
constructor() {
this.data = [];
}
static app() {
return new Registry();
}
/**
* Checks to see if a parameter is defined
*
* @param {String} arg
* @returns {Boolean} true if arg exists, false otherwises
*/
exists(arg) {
return this.data[arg] && this.data[arg] !== null;
}
/**
* Gets the arg's data
*
* @param {String} arg
* @returns {Object} null if no data, otherwise whatever the data is
*/
get(arg) {
return this.exists(arg) ? this.data[arg] : null;
}
/**
* Assign's an argument with its value
*
* @param {String} arg
* @param {Object} val
* @returns {Registry}
*/
set(arg, val) {
this.data[arg] = val;
return this;
}
/**
* Removes the argument from registry
*
* @param {String} arg
* @return {Registry}
*/
unset(arg) {
if (this.exists(arg))
delete this.data[arg];
return this;
}
/**
* Merges an object into the registry
*
* @param {Object} object
* @todo
*/
mergeObject(object) {
// ...
}
}
module.exports = Registry;