forked from vuejs/devtools-v6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbridge.js
45 lines (40 loc) · 960 Bytes
/
bridge.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
import { EventEmitter } from 'events'
export default class Bridge extends EventEmitter {
constructor (wall) {
super()
// Setting `this` to `self` here to fix an error in the Safari build:
// ReferenceError: Cannot access uninitialized variable.
// The error might be related to the webkit bug here:
// https://bugs.webkit.org/show_bug.cgi?id=171543
const self = this
self.setMaxListeners(Infinity)
self.wall = wall
wall.listen(message => {
if (typeof message === 'string') {
self.emit(message)
} else {
self.emit(message.event, message.payload)
}
})
}
/**
* Send an event.
*
* @param {String} event
* @param {*} payload
*/
send (event, payload) {
this.wall.send({
event,
payload
})
}
/**
* Log a message to the devtools background page.
*
* @param {String} message
*/
log (message) {
this.send('log', message)
}
}