Skip to content

Runtime Bridge API(桥接与调试)

本页覆盖 Wevu 与小程序原生运行时之间的桥接能力,以及用于排错/调优的公共 API。

1. 全局默认值与行为开关

API类型入口说明
setWevuDefaultsWevuDefaults配置 createApp/defineComponent 默认行为。
resetWevuDefaultsvoid重置默认值(测试/热更新常用)。
markNoSetDataT标记对象不参与 setData 快照。
isNoSetDataboolean判断对象是否被标记为 no-setData。

2. 调试与观测

API类型入口说明场景
addMutationRecorderMutationRecord注册 mutation 记录器。调试 state 变化来源。
removeMutationRecorderMutationRecord移除 mutation 记录器。测试结束清理。

3. 编译侧常量(wevu/compiler

wevu/compiler 主要给编译工具使用,业务代码不建议直接依赖。

常量/类型链接说明
WE_VU_MODULE_IDWE_VU_MODULE_ID运行时模块 ID(wevu)。
WE_VU_RUNTIME_APISWE_VU_RUNTIME_APIS编译器识别的运行时 API 名单。
WE_VU_PAGE_HOOK_TO_FEATUREWE_VU_PAGE_HOOK_TO_FEATURE页面 hook 与 feature 标记映射。
WevuRuntimeApiNameWevuRuntimeApiName运行时 API 名称联合类型。
WevuPageHookNameWevuPageHookName页面 hook 名称联合类型。
WevuPageFeatureFlagWevuPageFeatureFlag页面 feature 标记联合类型。

4. 示例:默认值 + mutation 记录(script setup)

vue
<script setup lang="ts">
import {
  addMutationRecorder,
  onUnmounted,
  ref,
  removeMutationRecorder,
  setWevuDefaults,
} from 'wevu'

setWevuDefaults({
  component: {
    options: {
      addGlobalClass: true,
    },
  },
})

const count = ref(0)
// [TS-only] 参数类型注解仅支持 lang="ts"
function recorder(record: any) {
  console.log('mutation:', record.path, record.type)
}

addMutationRecorder(recorder)

function inc() {
  count.value += 1
}

onUnmounted(() => {
  removeMutationRecorder(recorder)
})
</script>

<template>
  <button @tap="inc">
    count: {{ count }}
  </button>
</template>
vue
<script setup>
import {
  addMutationRecorder,
  onUnmounted,
  ref,
  removeMutationRecorder,
  setWevuDefaults,
} from 'wevu'

setWevuDefaults({
  component: {
    options: {
      addGlobalClass: true,
    },
  },
})

const count = ref(0)
function recorder(record) {
  console.log('mutation:', record.path, record.type)
}

addMutationRecorder(recorder)

function inc() {
  count.value += 1
}

onUnmounted(() => {
  removeMutationRecorder(recorder)
})
</script>

<template>
  <button @tap="inc">
    count: {{ count }}
  </button>
</template>

Released under the MIT License.