All files / runtime-core/src debug.ts

100% Statements 6/6
66.66% Branches 2/3
50% Functions 1/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 2785x 85x                                 85x 4x 4x 4x          
import {reactive} from '@vue/reactivity'
import {getCurrentInstance} from './component'
 
/**
 * this debug function is a helper for watching states in the vue devtool (it runs only in dev mode)
 * @example
 * const Component = defineComponent({
 *   setup() {
 *     const name = ref('foo')
 *     debug({
 *       // watch states in the vue devtool
 *       name,
 *     })
 *     return h('div', name.value)
 *   },
 * })
 * @param states any states you want to see in the vue devtool
 */
export const debug = __DEV__ ? (states: Record<string, any>) => {
  const instance = getCurrentInstance()
  if (instance) {
    instance.setupState = reactive(Object.assign({}, states, instance.setupState))
  }
} : (states: Record<string, any>) => {
  // empty
}