File size: 1,756 Bytes
4d70170 |
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 |
export const backendInjections = {
instanceMap: new Map(),
isVueInstance: (() => false) as ((value: any) => boolean),
getCustomInstanceDetails: (() => ({})) as ((instance: any) => any),
getCustomObjectDetails: (() => undefined) as (value: any, proto: string) => any,
}
export function getInstanceMap() {
return backendInjections.instanceMap
}
export function getCustomInstanceDetails(instance) {
return backendInjections.getCustomInstanceDetails(instance)
}
export function getCustomObjectDetails(value, proto: string) {
return backendInjections.getCustomObjectDetails(value, proto)
}
export function isVueInstance(value) {
return backendInjections.isVueInstance(value)
}
// @TODO refactor
export function getCustomRouterDetails(router) {
return {
_custom: {
type: 'router',
display: 'VueRouter',
value: {
options: router.options,
currentRoute: router.currentRoute,
},
fields: {
abstract: true,
},
},
}
}
// @TODO refactor
export function getCustomStoreDetails(store) {
return {
_custom: {
type: 'store',
display: 'Store',
value: {
state: store.state,
getters: getCatchedGetters(store),
},
fields: {
abstract: true,
},
},
}
}
// @TODO refactor
export function getCatchedGetters(store) {
const getters = {}
const origGetters = store.getters || {}
const keys = Object.keys(origGetters)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
Object.defineProperty(getters, key, {
enumerable: true,
get: () => {
try {
return origGetters[key]
}
catch (e) {
return e
}
},
})
}
return getters
}
|