-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsapling.js
98 lines (85 loc) · 1.63 KB
/
sapling.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
const Registry = require('./registry');
const Router = require('./router');
const Server = require('./server');
const EventEmitter = require('events');
/**
* Sapling framework application
*/
class Sapling {
constructor(opts) {
this.opts = opts;
this.registry = new Registry();
this.router = new Router(this);
this.server = new Server(this);
this.events = new EventEmitter();
}
/**
* Static constructor, incase you're lazy
*
* @param {Object} opts options
* @returns {Sapling}
*/
static app(opts) {
return new Sapling(opts);
}
/**
* Returns our base options object
*
* @returns {Object}
*/
getOpts() {
return this.opts;
}
/**
* Gets the event emitter system
*
* @returns {EventEmitter}
*/
getEvents() {
return this.events;
}
on(eventName, handler) {
return this.getEvents().on(eventName, handler);
}
use(action, handler) {
return this.router.use(action, handler);
}
/**
* Gets the arg's data
*
* @param {String} arg
* @returns {Object} null if no data, otherwise whatever the data is
*/
get(arg) {
return this.registry.get(arg);
}
/**
* Assign's an argument with its value
*
* @param {String} arg
* @param {Object} val
* @returns {Registry}
*/
set(arg, val) {
return this.registry.set(arg, val);
}
/**
* Removes the argument from registry
*
* @param {String} arg
* @return {Registry}
*/
unset(arg) {
return this.registry.unset(arg);
}
/**
* Finds the next route
*
* @param {String} action
* @param {Object} req
*/
findRoute(action, req) {
return this.router.findRoute(action, req);
}
}
module.exports = Sapling;