-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.js
53 lines (43 loc) · 1.3 KB
/
debug.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
// debug plugin
module.exports = (state, emitter, app) => {
// events
state.events.DEBUG_ON = 'debug:on'
state.events.DEBUG_OFF = 'debug:off'
state.events.DEBUG_LOG = 'debug:log'
state.events.DEBUG_WARN = 'debug:warn'
state.events.DEBUG_ERROR = 'debug:error'
state.events.DEBUG_PING = 'debug:ping'
state.events.MAINTENANCE_ON = 'maintenance:on'
state.events.MAINTENANCE_OFF = 'maintenance:off'
// state
state.debug = ''
// listeners
emitter.on(state.events.DEBUG_ON, () => {
state.debug = 'debug-grid'
emitter.emit(state.events.RENDER)
})
emitter.on(state.events.DEBUG_OFF, () => {
state.debug = ''
emitter.emit(state.events.RENDER)
})
emitter.on(state.events.DEBUG_LOG, msg => {
console.log(`📜 debug:log :: ${msg}`)
})
emitter.on(state.events.DEBUG_WARN, msg => {
console.warn(`📜 debug:warn :: ${msg}`)
})
emitter.on(state.events.DEBUG_ERROR, msg => {
console.error(`📜 debug:error :: ${msg}`)
})
emitter.on(state.events.DEBUG_PING, () => {
console.log('🏓 debug:ping :: pong !')
})
emitter.on(state.events.MAINTENANCE_ON, () => {
state.maintenance = true
emitter.emit(state.events.RENDER)
})
emitter.on(state.events.MAINTENANCE_OFF, () => {
state.maintenance = false
emitter.emit(state.events.RENDER)
})
}