All files / src/util perf.ts

45.45% Statements 5/11
11.11% Branches 1/9
0% Functions 0/2
45.45% Lines 5/11

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 27 28  1x 1x 1x 1x 1x                                            
import { ComponentRenderProxy, Doraemon } from '../instance/init'
import { inMiniprogram } from './env'
 
/**
E * 更新性能统计
 *
 * @param {*} vm
 * @param {*} options
 */
export let setUpdatePerformance: (vm: ComponentRenderProxy<Doraemon>, options?: {
  withDataPaths?: boolean
  showZero?: boolean
}) => void
 
if (inMiniprogram) {
  setUpdatePerformance = function (vm, options = {}) {
    if (vm.setUpdatePerformanceListener) {
      vm.setUpdatePerformanceListener({ withDataPaths: true, ...options }, (res) => {
        const cost = res.updateEndTimestamp - res.updateStartTimestamp
        const isShow = options.showZero || cost > 0
        if (isShow) {
          console.info(`doraemon ${vm.$component.$options.name} update ${cost} ms`)
        }
      })
    }
  }
}