/
app.ts
22 lines (20 loc) · 932 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { devtools, stringify } from '@vue/devtools-kit'
import { BridgeInstanceType } from './core'
import { BRIDGE_DEVTOOLS_ACTION_KEY, BRIDGE_DEVTOOLS_LISTENER_KEY } from './shared'
export function setupAppBridge(bridge: BridgeInstanceType) {
bridge.on(BRIDGE_DEVTOOLS_ACTION_KEY, async (payload) => {
// eslint-disable-next-line no-new-func
const action = new Function('devtools', '...args', `return (${payload.action})(devtools, ...args)`)
const result = await action(devtools, ...payload.args)
bridge.emit(payload.key, result)
})
bridge.on(BRIDGE_DEVTOOLS_LISTENER_KEY, async (payload) => {
// eslint-disable-next-line no-new-func
const action = new Function(`return ${payload.action}`)
const callback = action()
callback(devtools, (res) => {
const stringifyFn = payload.parser === 'devtools' ? stringify : JSON.stringify
bridge.emit(payload.key, stringifyFn(res))
})
})
}