wevu 7.2.1 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/defineProperty.mjs +1 -1
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/toPrimitive.mjs +1 -1
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/toPropertyKey.mjs +1 -1
- package/dist/dev/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/typeof.mjs +1 -1
- package/dist/dev/api/vitest/setup.d.mts +1 -0
- package/dist/dev/api/vitest.d.mts +1 -0
- package/dist/dev/api.d.mts +1 -0
- package/dist/dev/compiler.d.mts +1 -0
- package/dist/dev/fetch.d.mts +9 -0
- package/dist/dev/index.d.mts +72 -0
- package/dist/dev/internal-reactivity.d.mts +18 -0
- package/dist/dev/internal-runtime.d.mts +45 -0
- package/dist/dev/internal-runtime.mjs +3 -2
- package/dist/dev/internal-template.d.mts +2 -0
- package/dist/dev/jsxTypes.d.mts +9 -0
- package/dist/dev/macros/shared.d.mts +83 -0
- package/dist/dev/macros.d.mts +71 -0
- package/dist/dev/package.mjs +1 -1
- package/dist/dev/reactivity/asyncDerivation.d.mts +41 -0
- package/dist/dev/reactivity/asyncDerivation.mjs +8 -10
- package/dist/dev/reactivity/asyncDerivation.mjs.map +1 -1
- package/dist/dev/reactivity/computed.d.mts +25 -0
- package/dist/dev/reactivity/core.d.mts +35 -0
- package/dist/dev/reactivity/core.mjs +5 -8
- package/dist/dev/reactivity/core.mjs.map +1 -1
- package/dist/dev/reactivity/index.d.mts +16 -0
- package/dist/dev/reactivity/reactive/mutation.d.mts +21 -0
- package/dist/dev/reactivity/reactive/patch.d.mts +18 -0
- package/dist/dev/reactivity/reactive/patch.mjs +3 -3
- package/dist/dev/reactivity/reactive/patch.mjs.map +1 -1
- package/dist/dev/reactivity/reactive/patchState.mjs +4 -8
- package/dist/dev/reactivity/reactive/patchState.mjs.map +1 -1
- package/dist/dev/reactivity/reactive/shallow.d.mts +22 -0
- package/dist/dev/reactivity/reactive/shared.d.mts +4 -0
- package/dist/dev/reactivity/reactive/shared.mjs +1 -2
- package/dist/dev/reactivity/reactive/shared.mjs.map +1 -1
- package/dist/dev/reactivity/reactive.d.mts +42 -0
- package/dist/dev/reactivity/reactive.mjs +5 -10
- package/dist/dev/reactivity/reactive.mjs.map +1 -1
- package/dist/dev/reactivity/readonly.d.mts +27 -0
- package/dist/dev/reactivity/ref.d.mts +27 -0
- package/dist/dev/reactivity/ref.mjs +2 -2
- package/dist/dev/reactivity/ref.mjs.map +1 -1
- package/dist/dev/reactivity/shallowRef.d.mts +19 -0
- package/dist/dev/reactivity/shallowRef.mjs +1 -1
- package/dist/dev/reactivity/shallowRef.mjs.map +1 -1
- package/dist/dev/reactivity/toRefs.d.mts +43 -0
- package/dist/dev/reactivity/traverse.d.mts +8 -0
- package/dist/dev/reactivity/watch/helpers.mjs +1 -1
- package/dist/dev/reactivity/watch/helpers.mjs.map +1 -1
- package/dist/dev/reactivity/watch/types.d.mts +43 -0
- package/dist/dev/reactivity/watch.d.mts +22 -0
- package/dist/dev/reactivity/watch.mjs +6 -8
- package/dist/dev/reactivity/watch.mjs.map +1 -1
- package/dist/dev/router/auto-routes.d.mts +8 -0
- package/dist/dev/router/createRouter.d.mts +9 -0
- package/dist/dev/router/createRouter.mjs +17 -24
- package/dist/dev/router/createRouter.mjs.map +1 -1
- package/dist/dev/router/initialNavigation.mjs +18 -16
- package/dist/dev/router/initialNavigation.mjs.map +1 -1
- package/dist/dev/router/instance.mjs +1 -2
- package/dist/dev/router/instance.mjs.map +1 -1
- package/dist/dev/router/navigationCore.d.mts +7 -0
- package/dist/dev/router/navigationCore.mjs +2 -2
- package/dist/dev/router/navigationCore.mjs.map +1 -1
- package/dist/dev/router/navigationResult.mjs +7 -10
- package/dist/dev/router/navigationResult.mjs.map +1 -1
- package/dist/dev/router/navigationTarget.mjs +1 -3
- package/dist/dev/router/navigationTarget.mjs.map +1 -1
- package/dist/dev/router/resolve.d.mts +7 -0
- package/dist/dev/router/resolve.mjs +3 -4
- package/dist/dev/router/resolve.mjs.map +1 -1
- package/dist/dev/router/routeRegistry.mjs +1 -1
- package/dist/dev/router/routeRegistry.mjs.map +1 -1
- package/dist/dev/router/routeSync.d.mts +2 -0
- package/dist/dev/router/routeSync.mjs +1 -1
- package/dist/dev/router/routeSync.mjs.map +1 -1
- package/dist/dev/router/types.d.mts +267 -0
- package/dist/dev/router/useRoute.d.mts +20 -0
- package/dist/dev/router/useRoute.mjs +12 -19
- package/dist/dev/router/useRoute.mjs.map +1 -1
- package/dist/dev/router/useRouter.d.mts +9 -0
- package/dist/dev/router.d.mts +26 -0
- package/dist/dev/routerInternal/location.d.mts +2 -0
- package/dist/dev/routerInternal/location.mjs +2 -3
- package/dist/dev/routerInternal/location.mjs.map +1 -1
- package/dist/dev/routerInternal/matching.d.mts +2 -0
- package/dist/dev/routerInternal/params.d.mts +2 -0
- package/dist/dev/routerInternal/params.mjs +2 -3
- package/dist/dev/routerInternal/params.mjs.map +1 -1
- package/dist/dev/routerInternal/query.d.mts +7 -0
- package/dist/dev/routerInternal/records.d.mts +2 -0
- package/dist/dev/routerInternal/records.mjs +1 -1
- package/dist/dev/routerInternal/records.mjs.map +1 -1
- package/dist/dev/routerInternal/recordsWarnings.d.mts +2 -0
- package/dist/dev/routerInternal/recordsWarnings.mjs +1 -2
- package/dist/dev/routerInternal/recordsWarnings.mjs.map +1 -1
- package/dist/dev/routerInternal/shared.d.mts +9 -0
- package/dist/dev/routerInternal/snapshots.d.mts +2 -0
- package/dist/dev/routerInternal/types.d.mts +9 -0
- package/dist/dev/runtime/app/context.mjs +13 -26
- package/dist/dev/runtime/app/context.mjs.map +1 -1
- package/dist/dev/runtime/app/diagnostics.mjs +2 -4
- package/dist/dev/runtime/app/diagnostics.mjs.map +1 -1
- package/dist/dev/runtime/app/mount.mjs +27 -33
- package/dist/dev/runtime/app/mount.mjs.map +1 -1
- package/dist/dev/runtime/app/pending.d.mts +10 -0
- package/dist/dev/runtime/app/setData/commitTracker.d.mts +13 -0
- package/dist/dev/runtime/app/setData/commitTracker.mjs +5 -9
- package/dist/dev/runtime/app/setData/commitTracker.mjs.map +1 -1
- package/dist/dev/runtime/app/setData/patchScheduler.mjs +2 -4
- package/dist/dev/runtime/app/setData/patchScheduler.mjs.map +1 -1
- package/dist/dev/runtime/app/setData/payload.mjs +2 -3
- package/dist/dev/runtime/app/setData/payload.mjs.map +1 -1
- package/dist/dev/runtime/app/setData/scheduler.d.mts +51 -0
- package/dist/dev/runtime/app/setData/scheduler.mjs +7 -9
- package/dist/dev/runtime/app/setData/scheduler.mjs.map +1 -1
- package/dist/dev/runtime/app/setData/snapshot.mjs +5 -6
- package/dist/dev/runtime/app/setData/snapshot.mjs.map +1 -1
- package/dist/dev/runtime/app/setDataOptions.mjs +26 -27
- package/dist/dev/runtime/app/setDataOptions.mjs.map +1 -1
- package/dist/dev/runtime/app.d.mts +8 -0
- package/dist/dev/runtime/app.mjs +9 -9
- package/dist/dev/runtime/app.mjs.map +1 -1
- package/dist/dev/runtime/bindingManifest.mjs +6 -14
- package/dist/dev/runtime/bindingManifest.mjs.map +1 -1
- package/dist/dev/runtime/capabilities.d.mts +78 -0
- package/dist/dev/runtime/capabilities.mjs.map +1 -1
- package/dist/dev/runtime/css.d.mts +14 -0
- package/dist/dev/runtime/css.mjs +4 -8
- package/dist/dev/runtime/css.mjs.map +1 -1
- package/dist/dev/runtime/defaults.d.mts +12 -0
- package/dist/dev/runtime/defaults.mjs +4 -4
- package/dist/dev/runtime/defaults.mjs.map +1 -1
- package/dist/dev/runtime/define/initialComputed.mjs +5 -5
- package/dist/dev/runtime/define/initialComputed.mjs.map +1 -1
- package/dist/dev/runtime/define/options.mjs +10 -12
- package/dist/dev/runtime/define/options.mjs.map +1 -1
- package/dist/dev/runtime/define/props.mjs +4 -5
- package/dist/dev/runtime/define/props.mjs.map +1 -1
- package/dist/dev/runtime/define/scopedSlotOptions.mjs +43 -61
- package/dist/dev/runtime/define/scopedSlotOptions.mjs.map +1 -1
- package/dist/dev/runtime/define/setupResult.mjs +17 -28
- package/dist/dev/runtime/define/setupResult.mjs.map +1 -1
- package/dist/dev/runtime/define.d.mts +118 -0
- package/dist/dev/runtime/define.mjs +9 -12
- package/dist/dev/runtime/define.mjs.map +1 -1
- package/dist/dev/runtime/diff.mjs +9 -11
- package/dist/dev/runtime/diff.mjs.map +1 -1
- package/dist/dev/runtime/disposables.d.mts +31 -0
- package/dist/dev/runtime/disposables.mjs +2 -2
- package/dist/dev/runtime/disposables.mjs.map +1 -1
- package/dist/dev/runtime/elementIntersectionObserver.d.mts +26 -0
- package/dist/dev/runtime/elementIntersectionObserver.mjs +16 -24
- package/dist/dev/runtime/elementIntersectionObserver.mjs.map +1 -1
- package/dist/dev/runtime/features/inlineEvents.d.mts +7 -0
- package/dist/dev/runtime/features/inlineEvents.mjs +2 -3
- package/dist/dev/runtime/features/inlineEvents.mjs.map +1 -1
- package/dist/dev/runtime/features/jsxIslands.d.mts +7 -0
- package/dist/dev/runtime/features/jsxIslands.mjs +20 -0
- package/dist/dev/runtime/features/jsxIslands.mjs.map +1 -0
- package/dist/dev/runtime/features/layout.d.mts +7 -0
- package/dist/dev/runtime/features/layout.mjs +2 -3
- package/dist/dev/runtime/features/layout.mjs.map +1 -1
- package/dist/dev/runtime/features/patchStrategy.d.mts +7 -0
- package/dist/dev/runtime/features/publicLayout.d.mts +24 -0
- package/dist/dev/runtime/features/publicLayout.mjs +2 -6
- package/dist/dev/runtime/features/publicLayout.mjs.map +1 -1
- package/dist/dev/runtime/features/scopedSlots.d.mts +23 -0
- package/dist/dev/runtime/features/scopedSlots.mjs +5 -9
- package/dist/dev/runtime/features/scopedSlots.mjs.map +1 -1
- package/dist/dev/runtime/features/setDataHighFrequencyWarning.d.mts +7 -0
- package/dist/dev/runtime/features/templateRefs.d.mts +7 -0
- package/dist/dev/runtime/features/templateRefs.mjs +1 -1
- package/dist/dev/runtime/features/templateRefs.mjs.map +1 -1
- package/dist/dev/runtime/hooks/base.d.mts +27 -0
- package/dist/dev/runtime/hooks/base.mjs +21 -32
- package/dist/dev/runtime/hooks/base.mjs.map +1 -1
- package/dist/dev/runtime/hooks/register.d.mts +30 -0
- package/dist/dev/runtime/hooks/vue.d.mts +52 -0
- package/dist/dev/runtime/hooks.d.mts +4 -0
- package/dist/dev/runtime/index.d.mts +46 -0
- package/dist/dev/runtime/inlineDataset.mjs +1 -2
- package/dist/dev/runtime/inlineDataset.mjs.map +1 -1
- package/dist/dev/runtime/intersectionObserver.d.mts +14 -0
- package/dist/dev/runtime/intersectionObserver.mjs +6 -6
- package/dist/dev/runtime/intersectionObserver.mjs.map +1 -1
- package/dist/dev/runtime/jsxIsland.d.mts +37 -0
- package/dist/dev/runtime/jsxIsland.mjs +16 -33
- package/dist/dev/runtime/jsxIsland.mjs.map +1 -1
- package/dist/dev/runtime/layoutBridge.d.mts +55 -0
- package/dist/dev/runtime/layoutBridge.mjs +32 -62
- package/dist/dev/runtime/layoutBridge.mjs.map +1 -1
- package/dist/dev/runtime/nativeBridge.mjs +1 -1
- package/dist/dev/runtime/nativeBridge.mjs.map +1 -1
- package/dist/dev/runtime/navigationLifecycle.mjs +24 -0
- package/dist/dev/runtime/navigationLifecycle.mjs.map +1 -0
- package/dist/dev/runtime/noSetData.d.mts +5 -0
- package/dist/dev/runtime/pageEnvironment.d.mts +50 -0
- package/dist/dev/runtime/pageEnvironment.mjs +15 -18
- package/dist/dev/runtime/pageEnvironment.mjs.map +1 -1
- package/dist/dev/runtime/pageLayout.d.mts +25 -0
- package/dist/dev/runtime/pageLayout.mjs +7 -11
- package/dist/dev/runtime/pageLayout.mjs.map +1 -1
- package/dist/dev/runtime/pageScroll.d.mts +29 -0
- package/dist/dev/runtime/pageScroll.mjs +2 -3
- package/dist/dev/runtime/pageScroll.mjs.map +1 -1
- package/dist/dev/runtime/platform/current.mjs +12 -0
- package/dist/dev/runtime/platform/current.mjs.map +1 -0
- package/dist/dev/runtime/platform/generic.mjs +36 -0
- package/dist/dev/runtime/platform/generic.mjs.map +1 -0
- package/dist/dev/runtime/platform/globals.mjs +29 -0
- package/dist/dev/runtime/platform/globals.mjs.map +1 -0
- package/dist/dev/runtime/platform.mjs +15 -60
- package/dist/dev/runtime/platform.mjs.map +1 -1
- package/dist/dev/runtime/provide.d.mts +60 -0
- package/dist/dev/runtime/provideContext.mjs +7 -9
- package/dist/dev/runtime/provideContext.mjs.map +1 -1
- package/dist/dev/runtime/provideStore.d.mts +7 -0
- package/dist/dev/runtime/publicRuntime.d.mts +22 -0
- package/dist/dev/runtime/publicRuntime.mjs +4 -0
- package/dist/dev/runtime/publicRuntime.mjs.map +1 -1
- package/dist/dev/runtime/pullDownRefresh.d.mts +12 -0
- package/dist/dev/runtime/pullDownRefresh.mjs +2 -4
- package/dist/dev/runtime/pullDownRefresh.mjs.map +1 -1
- package/dist/dev/runtime/register/app.d.mts +14 -0
- package/dist/dev/runtime/register/app.mjs +18 -19
- package/dist/dev/runtime/register/app.mjs.map +1 -1
- package/dist/dev/runtime/register/component/alipay.mjs +9 -18
- package/dist/dev/runtime/register/component/alipay.mjs.map +1 -1
- package/dist/dev/runtime/register/component/alipayRegistration.mjs +60 -0
- package/dist/dev/runtime/register/component/alipayRegistration.mjs.map +1 -0
- package/dist/dev/runtime/register/component/lifecycle/platform.mjs +8 -9
- package/dist/dev/runtime/register/component/lifecycle/platform.mjs.map +1 -1
- package/dist/dev/runtime/register/component/lifecycle.mjs +7 -12
- package/dist/dev/runtime/register/component/lifecycle.mjs.map +1 -1
- package/dist/dev/runtime/register/component/methods.mjs +13 -18
- package/dist/dev/runtime/register/component/methods.mjs.map +1 -1
- package/dist/dev/runtime/register/component/options.mjs +3 -4
- package/dist/dev/runtime/register/component/options.mjs.map +1 -1
- package/dist/dev/runtime/register/component/props.mjs +25 -31
- package/dist/dev/runtime/register/component/props.mjs.map +1 -1
- package/dist/dev/runtime/register/component/registerDefinition.mjs +18 -40
- package/dist/dev/runtime/register/component/registerDefinition.mjs.map +1 -1
- package/dist/dev/runtime/register/component/registerNativeDefinition.mjs +18 -60
- package/dist/dev/runtime/register/component/registerNativeDefinition.mjs.map +1 -1
- package/dist/dev/runtime/register/component.d.mts +17 -0
- package/dist/dev/runtime/register/component.mjs +3 -5
- package/dist/dev/runtime/register/component.mjs.map +1 -1
- package/dist/dev/runtime/register/inline.d.mts +15 -0
- package/dist/dev/runtime/register/inline.mjs +8 -10
- package/dist/dev/runtime/register/inline.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs +7 -8
- package/dist/dev/runtime/register/runtimeInstance/methodBridge.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs +1 -1
- package/dist/dev/runtime/register/runtimeInstance/provideContext.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance/setupContext.mjs +25 -34
- package/dist/dev/runtime/register/runtimeInstance/setupContext.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance/setupPhase.mjs +6 -13
- package/dist/dev/runtime/register/runtimeInstance/setupPhase.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance/setupSnapshot.mjs +2 -2
- package/dist/dev/runtime/register/runtimeInstance/setupSnapshot.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance/utils.mjs +9 -9
- package/dist/dev/runtime/register/runtimeInstance/utils.mjs.map +1 -1
- package/dist/dev/runtime/register/runtimeInstance.d.mts +26 -0
- package/dist/dev/runtime/register/runtimeInstance.mjs +74 -100
- package/dist/dev/runtime/register/runtimeInstance.mjs.map +1 -1
- package/dist/dev/runtime/register/setDataFrequencyWarning.mjs +12 -15
- package/dist/dev/runtime/register/setDataFrequencyWarning.mjs.map +1 -1
- package/dist/dev/runtime/register/setup.d.mts +11 -0
- package/dist/dev/runtime/register/setup.mjs +2 -3
- package/dist/dev/runtime/register/setup.mjs.map +1 -1
- package/dist/dev/runtime/register/snapshot.mjs +1 -4
- package/dist/dev/runtime/register/snapshot.mjs.map +1 -1
- package/dist/dev/runtime/register/watch.d.mts +12 -0
- package/dist/dev/runtime/register/watch.mjs +3 -5
- package/dist/dev/runtime/register/watch.mjs.map +1 -1
- package/dist/dev/runtime/register.d.mts +5 -0
- package/dist/dev/runtime/scopedSlots.mjs +14 -21
- package/dist/dev/runtime/scopedSlots.mjs.map +1 -1
- package/dist/dev/runtime/selectorQuery.d.mts +54 -0
- package/dist/dev/runtime/selectorQuery.mjs +5 -9
- package/dist/dev/runtime/selectorQuery.mjs.map +1 -1
- package/dist/dev/runtime/template.d.mts +6 -0
- package/dist/dev/runtime/template.mjs +1 -1
- package/dist/dev/runtime/template.mjs.map +1 -1
- package/dist/dev/runtime/templateRefTypes.d.mts +12 -0
- package/dist/dev/runtime/templateRefs/helpers.mjs +14 -24
- package/dist/dev/runtime/templateRefs/helpers.mjs.map +1 -1
- package/dist/dev/runtime/templateRefs.mjs +8 -15
- package/dist/dev/runtime/templateRefs.mjs.map +1 -1
- package/dist/dev/runtime/types/core.d.mts +35 -0
- package/dist/dev/runtime/types/miniprogram.d.mts +84 -0
- package/dist/dev/runtime/types/miniprogramHost.d.mts +45 -0
- package/dist/dev/runtime/types/miniprogramHostSources.d.mts +112 -0
- package/dist/dev/runtime/types/options.d.mts +138 -0
- package/dist/dev/runtime/types/props/propTypes.d.mts +79 -0
- package/dist/dev/runtime/types/props/router.d.mts +51 -0
- package/dist/dev/runtime/types/props/setup.d.mts +96 -0
- package/dist/dev/runtime/types/props.d.mts +4 -0
- package/dist/dev/runtime/types/runtime.d.mts +59 -0
- package/dist/dev/runtime/types/setData.d.mts +237 -0
- package/dist/dev/runtime/types.d.mts +29 -0
- package/dist/dev/runtime/uniAppHost.d.mts +8 -0
- package/dist/dev/runtime/uniAppHost.mjs +6 -14
- package/dist/dev/runtime/uniAppHost.mjs.map +1 -1
- package/dist/dev/runtime/updatePerformance.d.mts +13 -0
- package/dist/dev/runtime/updatePerformance.mjs +1 -1
- package/dist/dev/runtime/updatePerformance.mjs.map +1 -1
- package/dist/dev/runtime/use.d.mts +13 -0
- package/dist/dev/runtime/use.mjs +1 -1
- package/dist/dev/runtime/use.mjs.map +1 -1
- package/dist/dev/runtime/vueCompat/context.d.mts +8 -0
- package/dist/dev/runtime/vueCompat/context.mjs +3 -5
- package/dist/dev/runtime/vueCompat/context.mjs.map +1 -1
- package/dist/dev/runtime/vueCompat/model.d.mts +30 -0
- package/dist/dev/runtime/vueCompat/model.mjs +9 -13
- package/dist/dev/runtime/vueCompat/model.mjs.map +1 -1
- package/dist/dev/runtime/vueCompat/router.d.mts +29 -0
- package/dist/dev/runtime/vueCompat/router.mjs +4 -4
- package/dist/dev/runtime/vueCompat/router.mjs.map +1 -1
- package/dist/dev/runtime/vueCompat/templateRef.d.mts +9 -0
- package/dist/dev/runtime/vueCompat/templateRef.mjs +1 -1
- package/dist/dev/runtime/vueCompat/templateRef.mjs.map +1 -1
- package/dist/dev/runtime/vueCompat.d.mts +5 -0
- package/dist/dev/scheduler.d.mts +4 -0
- package/dist/dev/scheduler.mjs +3 -4
- package/dist/dev/scheduler.mjs.map +1 -1
- package/dist/dev/store/base.mjs +1 -2
- package/dist/dev/store/base.mjs.map +1 -1
- package/dist/dev/store/define/create.mjs +11 -22
- package/dist/dev/store/define/create.mjs.map +1 -1
- package/dist/dev/store/define.d.mts +8 -0
- package/dist/dev/store/define.mjs +1 -1
- package/dist/dev/store/define.mjs.map +1 -1
- package/dist/dev/store/manager.d.mts +16 -0
- package/dist/dev/store/storeToRefs.d.mts +11 -0
- package/dist/dev/store/types.d.mts +106 -0
- package/dist/dev/store/view.mjs +1 -1
- package/dist/dev/store/view.mjs.map +1 -1
- package/dist/dev/store.d.mts +5 -0
- package/dist/dev/version.d.mts +4 -0
- package/dist/dev/vue-augment.d.mts +8 -0
- package/dist/dev/vue-demi.d.mts +87 -0
- package/dist/dev/vue-types.d.mts +19 -0
- package/dist/dev/web-apis.d.mts +3 -0
- package/dist/internal-runtime.d.mts +2 -1
- package/dist/internal-runtime.mjs +1 -1
- package/dist/package.mjs +1 -1
- package/dist/reactivity/asyncDerivation.mjs +1 -1
- package/dist/reactivity/core.mjs +1 -1
- package/dist/reactivity/reactive/patch.mjs +1 -1
- package/dist/reactivity/reactive/patchState.mjs +1 -1
- package/dist/reactivity/reactive/shared.mjs +1 -1
- package/dist/reactivity/reactive.mjs +1 -1
- package/dist/reactivity/ref.mjs +1 -1
- package/dist/reactivity/shallowRef.mjs +1 -1
- package/dist/reactivity/watch/helpers.mjs +1 -1
- package/dist/reactivity/watch.mjs +1 -1
- package/dist/router/createRouter.mjs +1 -1
- package/dist/router/initialNavigation.mjs +1 -1
- package/dist/router/instance.mjs +1 -1
- package/dist/router/navigationCore.mjs +1 -1
- package/dist/router/navigationResult.mjs +1 -1
- package/dist/router/navigationTarget.mjs +1 -1
- package/dist/router/resolve.mjs +1 -1
- package/dist/router/routeRegistry.mjs +1 -1
- package/dist/router/routeSync.mjs +1 -1
- package/dist/router/useRoute.mjs +1 -1
- package/dist/routerInternal/location.mjs +1 -1
- package/dist/routerInternal/params.mjs +1 -1
- package/dist/routerInternal/records.mjs +1 -1
- package/dist/routerInternal/recordsWarnings.mjs +1 -1
- package/dist/runtime/app/context.mjs +1 -1
- package/dist/runtime/app/diagnostics.mjs +1 -1
- package/dist/runtime/app/mount.mjs +1 -1
- package/dist/runtime/app/setData/commitTracker.mjs +1 -1
- package/dist/runtime/app/setData/patchScheduler.mjs +1 -1
- package/dist/runtime/app/setData/payload.mjs +1 -1
- package/dist/runtime/app/setData/scheduler.mjs +1 -1
- package/dist/runtime/app/setData/snapshot.mjs +1 -1
- package/dist/runtime/app/setDataOptions.mjs +1 -1
- package/dist/runtime/app.mjs +1 -1
- package/dist/runtime/bindingManifest.mjs +1 -1
- package/dist/runtime/capabilities.d.mts +4 -1
- package/dist/runtime/css.mjs +1 -1
- package/dist/runtime/defaults.mjs +1 -1
- package/dist/runtime/define/initialComputed.mjs +1 -1
- package/dist/runtime/define/options.mjs +1 -1
- package/dist/runtime/define/props.mjs +1 -1
- package/dist/runtime/define/scopedSlotOptions.mjs +1 -1
- package/dist/runtime/define/setupResult.mjs +1 -1
- package/dist/runtime/define.mjs +1 -1
- package/dist/runtime/diff.mjs +1 -1
- package/dist/runtime/disposables.mjs +1 -1
- package/dist/runtime/elementIntersectionObserver.mjs +1 -1
- package/dist/runtime/features/inlineEvents.mjs +1 -1
- package/dist/runtime/features/jsxIslands.d.mts +6 -0
- package/dist/runtime/features/jsxIslands.mjs +1 -0
- package/dist/runtime/features/layout.mjs +1 -1
- package/dist/runtime/features/publicLayout.mjs +1 -1
- package/dist/runtime/features/scopedSlots.mjs +1 -1
- package/dist/runtime/features/templateRefs.mjs +1 -1
- package/dist/runtime/hooks/base.mjs +1 -1
- package/dist/runtime/inlineDataset.mjs +1 -1
- package/dist/runtime/intersectionObserver.mjs +1 -1
- package/dist/runtime/jsxIsland.mjs +1 -1
- package/dist/runtime/layoutBridge.mjs +1 -1
- package/dist/runtime/nativeBridge.mjs +1 -1
- package/dist/runtime/navigationLifecycle.mjs +1 -0
- package/dist/runtime/pageEnvironment.mjs +1 -1
- package/dist/runtime/pageLayout.mjs +1 -1
- package/dist/runtime/pageScroll.mjs +1 -1
- package/dist/runtime/platform/current.mjs +1 -0
- package/dist/runtime/platform/generic.mjs +1 -0
- package/dist/runtime/platform/globals.mjs +1 -0
- package/dist/runtime/platform.mjs +1 -1
- package/dist/runtime/provideContext.mjs +1 -1
- package/dist/runtime/publicRuntime.mjs +1 -1
- package/dist/runtime/pullDownRefresh.mjs +1 -1
- package/dist/runtime/register/app.mjs +1 -1
- package/dist/runtime/register/component/alipay.mjs +1 -1
- package/dist/runtime/register/component/alipayRegistration.mjs +1 -0
- package/dist/runtime/register/component/lifecycle/platform.mjs +1 -1
- package/dist/runtime/register/component/lifecycle.mjs +1 -1
- package/dist/runtime/register/component/methods.mjs +1 -1
- package/dist/runtime/register/component/options.mjs +1 -1
- package/dist/runtime/register/component/props.mjs +1 -1
- package/dist/runtime/register/component/registerDefinition.mjs +1 -1
- package/dist/runtime/register/component/registerNativeDefinition.mjs +1 -1
- package/dist/runtime/register/component.mjs +1 -1
- package/dist/runtime/register/inline.mjs +1 -1
- package/dist/runtime/register/runtimeInstance/methodBridge.mjs +1 -1
- package/dist/runtime/register/runtimeInstance/provideContext.mjs +1 -1
- package/dist/runtime/register/runtimeInstance/setupContext.mjs +1 -1
- package/dist/runtime/register/runtimeInstance/setupPhase.mjs +1 -1
- package/dist/runtime/register/runtimeInstance/setupSnapshot.mjs +1 -1
- package/dist/runtime/register/runtimeInstance/utils.mjs +1 -1
- package/dist/runtime/register/runtimeInstance.mjs +1 -1
- package/dist/runtime/register/setDataFrequencyWarning.mjs +1 -1
- package/dist/runtime/register/setup.mjs +1 -1
- package/dist/runtime/register/snapshot.mjs +1 -1
- package/dist/runtime/register/watch.mjs +1 -1
- package/dist/runtime/scopedSlots.mjs +1 -1
- package/dist/runtime/selectorQuery.mjs +1 -1
- package/dist/runtime/template.mjs +1 -1
- package/dist/runtime/templateRefs/helpers.mjs +1 -1
- package/dist/runtime/templateRefs.mjs +1 -1
- package/dist/runtime/uniAppHost.mjs +1 -1
- package/dist/runtime/updatePerformance.mjs +1 -1
- package/dist/runtime/use.mjs +1 -1
- package/dist/runtime/vueCompat/context.mjs +1 -1
- package/dist/runtime/vueCompat/model.mjs +1 -1
- package/dist/runtime/vueCompat/router.mjs +1 -1
- package/dist/runtime/vueCompat/templateRef.mjs +1 -1
- package/dist/scheduler.mjs +1 -1
- package/dist/store/base.mjs +1 -1
- package/dist/store/define/create.mjs +1 -1
- package/dist/store/define.mjs +1 -1
- package/dist/store/view.mjs +1 -1
- package/package.json +7 -7
- /package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/defineProperty.mjs +0 -0
- /package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/toPrimitive.mjs +0 -0
- /package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/toPropertyKey.mjs +0 -0
- /package/dist/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.151.0}/helpers/esm/typeof.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncDerivation.mjs","names":[],"sources":["../../../src/reactivity/asyncDerivation.ts"],"sourcesContent":["import { AbortControllerPolyfill } from '@wevu/web-apis/abort'\nimport { batch, onScopeDispose, runWithoutTracking } from './core'\nimport { reactive } from './reactive'\nimport { readonly } from './readonly'\n\n/** 异步派生状态的生命周期阶段。 */\nexport type AsyncDerivationStatus\n = | 'idle'\n | 'initial-pending'\n | 'ready'\n | 'refreshing'\n | 'error'\n | 'disposed'\n\n/** 传给异步加载函数的当前任务上下文。 */\nexport interface AsyncDerivationContext {\n readonly signal: AbortSignal\n}\n\n/** `useAsyncDerivation()` 的配置。 */\nexport interface UseAsyncDerivationOptions {\n immediate?: boolean\n}\n\ntype AsyncDerivationIdleState<TStatus extends 'idle' | 'initial-pending' | 'disposed'> = Readonly<{\n status: TStatus\n value: undefined\n error: undefined\n}>\n\ntype AsyncDerivationReadyState<T, TStatus extends 'ready' | 'refreshing'> = Readonly<{\n status: TStatus\n value: T\n error: undefined\n}>\n\ntype AsyncDerivationErrorState<T> = Readonly<{\n status: 'error'\n value: T | undefined\n error: unknown\n}>\n\n/** 模板可观察的只读异步派生状态。 */\nexport type AsyncDerivationState<T>\n = | AsyncDerivationIdleState<'idle'>\n | AsyncDerivationIdleState<'initial-pending'>\n | AsyncDerivationIdleState<'disposed'>\n | AsyncDerivationReadyState<T, 'ready'>\n | AsyncDerivationReadyState<T, 'refreshing'>\n | AsyncDerivationErrorState<T>\n\ntype AsyncDerivationControls = Readonly<{\n refresh: () => Promise<void>\n dispose: () => void\n}>\n\n/** 异步派生状态及其非枚举控制方法。 */\nexport type AsyncDerivation<T> = AsyncDerivationState<T> & AsyncDerivationControls\n\ninterface MutableAsyncDerivationState<T> {\n status: AsyncDerivationStatus\n value: T | undefined\n error: unknown\n}\n\ninterface AsyncDerivationCycle {\n readonly promise: Promise<void>\n readonly resolve: () => void\n}\n\nconst RESOLVED_PROMISE: Promise<void> = Promise.resolve()\n\nfunction createAsyncDerivationCycle(): AsyncDerivationCycle {\n let resolve!: () => void\n const promise = new Promise<void>((settle) => {\n resolve = settle\n })\n return { promise, resolve }\n}\n\n/**\n * 创建面向静态 WXML 数据绑定的异步派生状态。\n * 加载错误通过 `status` 与 `error` 暴露,`refresh()` 始终正常完成。\n */\nexport function useAsyncDerivation<T>(\n loader: (context: AsyncDerivationContext) => T | PromiseLike<T>,\n options: UseAsyncDerivationOptions = {},\n): AsyncDerivation<T> {\n const storage: MutableAsyncDerivationState<T> = {\n status: 'idle',\n value: undefined,\n error: undefined,\n }\n const state = reactive(storage)\n let activeController: AbortController | undefined\n let activeCycle: AsyncDerivationCycle | undefined\n let generation = 0\n let hasValue = false\n let disposed = false\n\n function settleLatestCycle(completedGeneration: number) {\n if (disposed || completedGeneration !== generation) {\n return\n }\n const cycle = activeCycle\n activeCycle = undefined\n cycle?.resolve()\n }\n\n function commitValue(completedGeneration: number, value: T) {\n if (disposed || completedGeneration !== generation) {\n return\n }\n activeController = undefined\n hasValue = true\n try {\n batch(() => {\n state.status = 'ready'\n state.value = value\n state.error = undefined\n })\n }\n finally {\n settleLatestCycle(completedGeneration)\n }\n }\n\n function commitError(completedGeneration: number, error: unknown) {\n if (disposed || completedGeneration !== generation) {\n return\n }\n activeController = undefined\n try {\n batch(() => {\n state.status = 'error'\n state.error = error\n if (!hasValue) {\n state.value = undefined\n }\n })\n }\n finally {\n settleLatestCycle(completedGeneration)\n }\n }\n\n function refresh(): Promise<void> {\n if (disposed) {\n return RESOLVED_PROMISE\n }\n\n const cycle = activeCycle ?? createAsyncDerivationCycle()\n activeCycle = cycle\n const currentGeneration = ++generation\n const previousController = activeController\n // eslint-disable-next-line mini-program/no-implicit-runtime-polyfill -- 缺失宿主实现时显式回退兼容层。\n const Controller = typeof AbortController === 'function' ? AbortController : AbortControllerPolyfill\n const controller = new Controller() as unknown as AbortController\n activeController = controller\n try {\n previousController?.abort()\n }\n catch {\n // 原生 EventTarget 不把 abort listener 异常传播给调用者,兼容实现保持相同控制流。\n }\n\n if (disposed || currentGeneration !== generation) {\n return cycle.promise\n }\n\n batch(() => {\n state.status = hasValue ? 'refreshing' : 'initial-pending'\n state.error = undefined\n })\n\n if (disposed || currentGeneration !== generation) {\n return cycle.promise\n }\n\n runWithoutTracking(() => {\n // 自有 Promise 避免原生 Promise 的身份快路径把 then 访问移出收养边界。\n const task = new Promise<T>((resolve) => {\n resolve(loader({ signal: controller.signal }))\n })\n void task.then(\n value => commitValue(currentGeneration, value),\n error => commitError(currentGeneration, error),\n ).catch((error) => {\n // 观察者异常交给宿主报告,不改写加载结果,也不阻塞 refresh 的完成。\n setTimeout(() => {\n throw error\n }, 0)\n })\n })\n return cycle.promise\n }\n\n function dispose() {\n if (disposed) {\n return\n }\n disposed = true\n generation += 1\n const controller = activeController\n activeController = undefined\n try {\n controller?.abort()\n }\n catch {\n // dispose 必须完成状态清理和 waiter 结算,不能被 listener 异常中断。\n }\n try {\n batch(() => {\n state.status = 'disposed'\n state.value = undefined\n state.error = undefined\n })\n }\n finally {\n hasValue = false\n const cycle = activeCycle\n activeCycle = undefined\n cycle?.resolve()\n }\n }\n\n Object.defineProperties(storage, {\n refresh: {\n value: refresh,\n },\n dispose: {\n value: dispose,\n },\n })\n\n const result = readonly(state) as AsyncDerivation<T>\n onScopeDispose(dispose)\n if (options.immediate ?? true) {\n void refresh()\n }\n return result\n}\n"],"mappings":";;;;;;AAsEA,MAAM,mBAAkC,QAAQ,QAAQ;AAExD,SAAS,6BAAmD;CAC1D,IAAI;CAIJ,OAAO;EAAE,aAHW,SAAe,WAAW;GAC5C,UAAU;EACZ,CACe;EAAG;CAAQ;AAC5B;;;;;AAMA,SAAgB,mBACd,QACA,UAAqC,CAAC,GAClB
|
|
1
|
+
{"version":3,"file":"asyncDerivation.mjs","names":[],"sources":["../../../src/reactivity/asyncDerivation.ts"],"sourcesContent":["import { AbortControllerPolyfill } from '@wevu/web-apis/abort'\nimport { batch, onScopeDispose, runWithoutTracking } from './core'\nimport { reactive } from './reactive'\nimport { readonly } from './readonly'\n\n/** 异步派生状态的生命周期阶段。 */\nexport type AsyncDerivationStatus\n = | 'idle'\n | 'initial-pending'\n | 'ready'\n | 'refreshing'\n | 'error'\n | 'disposed'\n\n/** 传给异步加载函数的当前任务上下文。 */\nexport interface AsyncDerivationContext {\n readonly signal: AbortSignal\n}\n\n/** `useAsyncDerivation()` 的配置。 */\nexport interface UseAsyncDerivationOptions {\n immediate?: boolean\n}\n\ntype AsyncDerivationIdleState<TStatus extends 'idle' | 'initial-pending' | 'disposed'> = Readonly<{\n status: TStatus\n value: undefined\n error: undefined\n}>\n\ntype AsyncDerivationReadyState<T, TStatus extends 'ready' | 'refreshing'> = Readonly<{\n status: TStatus\n value: T\n error: undefined\n}>\n\ntype AsyncDerivationErrorState<T> = Readonly<{\n status: 'error'\n value: T | undefined\n error: unknown\n}>\n\n/** 模板可观察的只读异步派生状态。 */\nexport type AsyncDerivationState<T>\n = | AsyncDerivationIdleState<'idle'>\n | AsyncDerivationIdleState<'initial-pending'>\n | AsyncDerivationIdleState<'disposed'>\n | AsyncDerivationReadyState<T, 'ready'>\n | AsyncDerivationReadyState<T, 'refreshing'>\n | AsyncDerivationErrorState<T>\n\ntype AsyncDerivationControls = Readonly<{\n refresh: () => Promise<void>\n dispose: () => void\n}>\n\n/** 异步派生状态及其非枚举控制方法。 */\nexport type AsyncDerivation<T> = AsyncDerivationState<T> & AsyncDerivationControls\n\ninterface MutableAsyncDerivationState<T> {\n status: AsyncDerivationStatus\n value: T | undefined\n error: unknown\n}\n\ninterface AsyncDerivationCycle {\n readonly promise: Promise<void>\n readonly resolve: () => void\n}\n\nconst RESOLVED_PROMISE: Promise<void> = Promise.resolve()\n\nfunction createAsyncDerivationCycle(): AsyncDerivationCycle {\n let resolve!: () => void\n const promise = new Promise<void>((settle) => {\n resolve = settle\n })\n return { promise, resolve }\n}\n\n/**\n * 创建面向静态 WXML 数据绑定的异步派生状态。\n * 加载错误通过 `status` 与 `error` 暴露,`refresh()` 始终正常完成。\n */\nexport function useAsyncDerivation<T>(\n loader: (context: AsyncDerivationContext) => T | PromiseLike<T>,\n options: UseAsyncDerivationOptions = {},\n): AsyncDerivation<T> {\n const storage: MutableAsyncDerivationState<T> = {\n status: 'idle',\n value: undefined,\n error: undefined,\n }\n const state = reactive(storage)\n let activeController: AbortController | undefined\n let activeCycle: AsyncDerivationCycle | undefined\n let generation = 0\n let hasValue = false\n let disposed = false\n\n function settleLatestCycle(completedGeneration: number) {\n if (disposed || completedGeneration !== generation) {\n return\n }\n const cycle = activeCycle\n activeCycle = undefined\n cycle?.resolve()\n }\n\n function commitValue(completedGeneration: number, value: T) {\n if (disposed || completedGeneration !== generation) {\n return\n }\n activeController = undefined\n hasValue = true\n try {\n batch(() => {\n state.status = 'ready'\n state.value = value\n state.error = undefined\n })\n }\n finally {\n settleLatestCycle(completedGeneration)\n }\n }\n\n function commitError(completedGeneration: number, error: unknown) {\n if (disposed || completedGeneration !== generation) {\n return\n }\n activeController = undefined\n try {\n batch(() => {\n state.status = 'error'\n state.error = error\n if (!hasValue) {\n state.value = undefined\n }\n })\n }\n finally {\n settleLatestCycle(completedGeneration)\n }\n }\n\n function refresh(): Promise<void> {\n if (disposed) {\n return RESOLVED_PROMISE\n }\n\n const cycle = activeCycle ?? createAsyncDerivationCycle()\n activeCycle = cycle\n const currentGeneration = ++generation\n const previousController = activeController\n // eslint-disable-next-line mini-program/no-implicit-runtime-polyfill -- 缺失宿主实现时显式回退兼容层。\n const Controller = typeof AbortController === 'function' ? AbortController : AbortControllerPolyfill\n const controller = new Controller() as unknown as AbortController\n activeController = controller\n try {\n previousController?.abort()\n }\n catch {\n // 原生 EventTarget 不把 abort listener 异常传播给调用者,兼容实现保持相同控制流。\n }\n\n if (disposed || currentGeneration !== generation) {\n return cycle.promise\n }\n\n batch(() => {\n state.status = hasValue ? 'refreshing' : 'initial-pending'\n state.error = undefined\n })\n\n if (disposed || currentGeneration !== generation) {\n return cycle.promise\n }\n\n runWithoutTracking(() => {\n // 自有 Promise 避免原生 Promise 的身份快路径把 then 访问移出收养边界。\n const task = new Promise<T>((resolve) => {\n resolve(loader({ signal: controller.signal }))\n })\n void task.then(\n value => commitValue(currentGeneration, value),\n error => commitError(currentGeneration, error),\n ).catch((error) => {\n // 观察者异常交给宿主报告,不改写加载结果,也不阻塞 refresh 的完成。\n setTimeout(() => {\n throw error\n }, 0)\n })\n })\n return cycle.promise\n }\n\n function dispose() {\n if (disposed) {\n return\n }\n disposed = true\n generation += 1\n const controller = activeController\n activeController = undefined\n try {\n controller?.abort()\n }\n catch {\n // dispose 必须完成状态清理和 waiter 结算,不能被 listener 异常中断。\n }\n try {\n batch(() => {\n state.status = 'disposed'\n state.value = undefined\n state.error = undefined\n })\n }\n finally {\n hasValue = false\n const cycle = activeCycle\n activeCycle = undefined\n cycle?.resolve()\n }\n }\n\n Object.defineProperties(storage, {\n refresh: {\n value: refresh,\n },\n dispose: {\n value: dispose,\n },\n })\n\n const result = readonly(state) as AsyncDerivation<T>\n onScopeDispose(dispose)\n if (options.immediate ?? true) {\n void refresh()\n }\n return result\n}\n"],"mappings":";;;;;;AAsEA,MAAM,mBAAkC,QAAQ,QAAQ;AAExD,SAAS,6BAAmD;CAC1D,IAAI;CAIJ,OAAO;EAAE,aAHW,SAAe,WAAW;GAC5C,UAAU;EACZ,CACe;EAAG;CAAQ;AAC5B;;;;;AAM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Y,YAAY;IACvC,QAAQ,OAAO,EAAE,QAAQ,WAAW,OAAO,CAAC,CAAC;GAC/C,CACQ,CAAC,CAAC,MACR,UAAS,YAAY,mBAAmB,KAAK,IAC7C,UAAS,YAAY,mBAAmB,KAAK,CAC/C,CAAC,CAAC,OAAO,UAAU;IAEjB,iBAAiB;KACf,MAAM;IACR,GAAG,CAAC;GACN,CAAC;EACH,CAAC;EACD,OAAO,MAAM;CACf;CAEA,SAAS,UAAU;EACjB,IAAI,UACF;EAEF,WAAW;EACX,cAAc;EACd,MAAM,aAAa;EACnB,mBAAmB;EACnB,IAAI;GACF,YAAY,MAAM;EACpB,QACM,CAEN;EACA,IAAI;GACF,YAAY;IACV,MAAM,SAAS;IACf,MAAM,QAAQ;IACd,MAAM,QAAQ;GAChB,CAAC;EACH,UACQ;GACN,WAAW;GACX,MAAM,QAAQ;GACd,cAAc;GACd,OAAO,QAAQ;EACjB;CACF;CAEA,OAAO,iBAAiB,SAAS;EAC/B,SAAS,EACP,OAAO,QACT;EACA,SAAS,EACP,OAAO,QACT;CACF,CAAC;CAED,MAAM,SAAS,SAAS,KAAK;CAC7B,eAAe,OAAO;CACtB,IAAI,QAAQ,aAAa,MACvB,AAAK,QAAQ;CAEf,OAAO;AACT"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Ref } from "./ref.mjs";
|
|
2
|
+
//#region src/reactivity/computed.d.ts
|
|
3
|
+
export type ComputedGetter<T> = () => T;
|
|
4
|
+
export type ComputedSetter<T> = (value: T) => void;
|
|
5
|
+
declare const computedBrand: unique symbol;
|
|
6
|
+
declare const writableComputedBrand: unique symbol;
|
|
7
|
+
interface BaseComputedRef<T, S = T> extends Ref<T, S> {
|
|
8
|
+
[key: symbol]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface ComputedRef<T = any> extends BaseComputedRef<T> {
|
|
11
|
+
readonly [computedBrand]: true;
|
|
12
|
+
readonly value: T;
|
|
13
|
+
}
|
|
14
|
+
export interface WritableComputedRef<T, S = T> extends BaseComputedRef<T, S> {
|
|
15
|
+
readonly [writableComputedBrand]: true;
|
|
16
|
+
value: T;
|
|
17
|
+
}
|
|
18
|
+
export interface WritableComputedOptions<T> {
|
|
19
|
+
get: ComputedGetter<T>;
|
|
20
|
+
set: ComputedSetter<T>;
|
|
21
|
+
}
|
|
22
|
+
export declare function computed<T>(getter: ComputedGetter<T>): ComputedRef<T>;
|
|
23
|
+
export declare function computed<T>(options: WritableComputedOptions<T>): WritableComputedRef<T>;
|
|
24
|
+
//#endregion
|
|
25
|
+
//# sourceMappingURL=computed.d.mts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/reactivity/core.d.ts
|
|
2
|
+
export type EffectScheduler = () => void;
|
|
3
|
+
export type Dep = Set<ReactiveEffect>;
|
|
4
|
+
export interface ReactiveEffect<T = any> {
|
|
5
|
+
(): T;
|
|
6
|
+
deps: Dep[];
|
|
7
|
+
scheduler?: EffectScheduler;
|
|
8
|
+
active: boolean;
|
|
9
|
+
_running: boolean;
|
|
10
|
+
_fn: () => T;
|
|
11
|
+
_computed?: boolean;
|
|
12
|
+
onStop?: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function startBatch(): void;
|
|
15
|
+
export declare function endBatch(): void;
|
|
16
|
+
export declare function batch<T>(fn: () => T): T;
|
|
17
|
+
export declare function stop(runner: ReactiveEffect): void;
|
|
18
|
+
export interface EffectScope {
|
|
19
|
+
active: boolean;
|
|
20
|
+
effects: ReactiveEffect[];
|
|
21
|
+
cleanups: (() => void)[];
|
|
22
|
+
run: <T>(fn: () => T) => T | undefined;
|
|
23
|
+
stop: () => void;
|
|
24
|
+
}
|
|
25
|
+
export declare function effectScope(detached?: boolean): EffectScope;
|
|
26
|
+
export declare function getCurrentScope(): EffectScope | undefined;
|
|
27
|
+
export declare function onScopeDispose(fn: () => void): void;
|
|
28
|
+
export interface EffectOptions {
|
|
29
|
+
scheduler?: EffectScheduler;
|
|
30
|
+
lazy?: boolean;
|
|
31
|
+
onStop?: () => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function effect<T = any>(fn: () => T, options?: EffectOptions): ReactiveEffect<T>;
|
|
34
|
+
//#endregion
|
|
35
|
+
//# sourceMappingURL=core.d.mts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { queueJob } from "../scheduler.mjs";
|
|
2
|
-
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.151.0/helpers/esm/defineProperty.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/reactivity/core.ts
|
|
5
5
|
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -96,11 +96,10 @@ function cleanupEffect(effect) {
|
|
|
96
96
|
deps.length = 0;
|
|
97
97
|
}
|
|
98
98
|
function stop(runner) {
|
|
99
|
-
var _runner$onStop;
|
|
100
99
|
if (!runner.active) return;
|
|
101
100
|
runner.active = false;
|
|
102
101
|
cleanupEffect(runner);
|
|
103
|
-
|
|
102
|
+
runner.onStop?.();
|
|
104
103
|
}
|
|
105
104
|
var EffectScopeImpl = class {
|
|
106
105
|
constructor(detached = false) {
|
|
@@ -166,8 +165,7 @@ var EffectScopeImpl = class {
|
|
|
166
165
|
scopes.length = 0;
|
|
167
166
|
}
|
|
168
167
|
} finally {
|
|
169
|
-
|
|
170
|
-
if ((_this$parent = this.parent) === null || _this$parent === void 0 ? void 0 : _this$parent.scopes) {
|
|
168
|
+
if (this.parent?.scopes) {
|
|
171
169
|
const index = this.parent.scopes.indexOf(this);
|
|
172
170
|
if (index >= 0) this.parent.scopes.splice(index, 1);
|
|
173
171
|
}
|
|
@@ -184,7 +182,7 @@ function getCurrentScope() {
|
|
|
184
182
|
return activeEffectScope;
|
|
185
183
|
}
|
|
186
184
|
function onScopeDispose(fn) {
|
|
187
|
-
if (activeEffectScope
|
|
185
|
+
if (activeEffectScope?.active) activeEffectScope.cleanups.push(fn);
|
|
188
186
|
}
|
|
189
187
|
/**
|
|
190
188
|
* 在不把读取记录到当前副作用的情况下执行函数。
|
|
@@ -222,9 +220,8 @@ function createReactiveEffect(fn, options = {}) {
|
|
|
222
220
|
activeEffect = effect;
|
|
223
221
|
return fn();
|
|
224
222
|
} finally {
|
|
225
|
-
var _effectStack;
|
|
226
223
|
effectStack.pop();
|
|
227
|
-
activeEffect =
|
|
224
|
+
activeEffect = effectStack[effectStack.length - 1] ?? null;
|
|
228
225
|
effect._running = false;
|
|
229
226
|
activeEffectScope = previousScope;
|
|
230
227
|
shouldTrack = previousShouldTrack;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.mjs","names":[],"sources":["../../../src/reactivity/core.ts"],"sourcesContent":["import { queueJob } from '../scheduler'\n\nexport type EffectScheduler = () => void\n\nexport type Dep = Set<ReactiveEffect>\n\nexport interface ReactiveEffect<T = any> {\n (): T\n deps: Dep[]\n scheduler?: EffectScheduler\n active: boolean\n _running: boolean\n _fn: () => T\n _computed?: boolean\n onStop?: () => void\n}\n\nconst targetMap = new WeakMap<object, Map<PropertyKey, Dep>>()\n\nlet activeEffect: ReactiveEffect | null = null\nconst effectStack: ReactiveEffect[] = []\nlet shouldTrack = true\nlet activeEffectScope: EffectScopeImpl | undefined\n\nlet batchDepth = 0\nlet isFlushingBatch = false\nconst batchedEffects = new Set<ReactiveEffect>()\nconst batchedCallbacks = new Set<() => void>()\n\nfunction runScheduledEffect(ef: ReactiveEffect) {\n if (!ef.active) {\n return\n }\n if (ef.scheduler) {\n const previousScope = activeEffectScope\n activeEffectScope = (ef as ScopedReactiveEffect)._scope\n try {\n ef.scheduler()\n }\n finally {\n activeEffectScope = previousScope\n }\n return\n }\n ef()\n}\n\n/** 在当前批次的同步副作用全部完成后执行包内通知。 */\nexport function queueBatchCallback(callback: () => void) {\n if (batchDepth > 0 || isFlushingBatch) {\n batchedCallbacks.add(callback)\n return\n }\n batchedCallbacks.delete(callback)\n callback()\n}\n\nexport function startBatch() {\n batchDepth++\n}\n\nfunction takeBatchedEffect(effects: Set<ReactiveEffect>): ReactiveEffect | undefined {\n const next = effects.values().next()\n if (next.done) {\n return undefined\n }\n effects.delete(next.value)\n return next.value\n}\n\nfunction flushBatchedEffects() {\n let firstError: unknown\n let hasError = false\n isFlushingBatch = true\n try {\n while (batchedEffects.size) {\n const effect = takeBatchedEffect(batchedEffects)\n if (!effect) {\n continue\n }\n try {\n runScheduledEffect(effect)\n }\n catch (error) {\n if (!hasError) {\n firstError = error\n hasError = true\n }\n }\n }\n }\n finally {\n isFlushingBatch = false\n }\n // 通知属于已完成批次之后的操作,保留订阅回调内同步变更的重入保护。\n while (batchedCallbacks.size) {\n const callback = batchedCallbacks.values().next().value!\n batchedCallbacks.delete(callback)\n try {\n callback()\n }\n catch (error) {\n if (!hasError) {\n firstError = error\n hasError = true\n }\n }\n }\n if (hasError) {\n throw firstError\n }\n}\n\nexport function endBatch() {\n if (batchDepth === 0) {\n return\n }\n batchDepth--\n if (batchDepth === 0 && !isFlushingBatch) {\n flushBatchedEffects()\n }\n}\n\nexport function batch<T>(fn: () => T): T {\n startBatch()\n try {\n return fn()\n }\n finally {\n endBatch()\n }\n}\n\nfunction cleanupEffect(effect: ReactiveEffect) {\n const { deps } = effect\n for (let i = 0; i < deps.length; i++) {\n deps[i].delete(effect)\n }\n deps.length = 0\n}\n\nexport function stop(runner: ReactiveEffect) {\n if (!runner.active) {\n return\n }\n runner.active = false\n cleanupEffect(runner)\n runner.onStop?.()\n}\n\nexport interface EffectScope {\n active: boolean\n effects: ReactiveEffect[]\n cleanups: (() => void)[]\n run: <T>(fn: () => T) => T | undefined\n stop: () => void\n}\n\nclass EffectScopeImpl implements EffectScope {\n active = true\n effects: ReactiveEffect[] = []\n cleanups: (() => void)[] = []\n private parent: EffectScopeImpl | undefined\n private scopes: EffectScopeImpl[] | undefined\n\n constructor(private detached = false) {\n if (!detached && activeEffectScope) {\n if (!activeEffectScope.active) {\n this.active = false\n return\n }\n this.parent = activeEffectScope\n ;(activeEffectScope.scopes ||= []).push(this)\n }\n }\n\n run<T>(fn: () => T): T | undefined {\n if (!this.active) {\n return\n }\n const prev = activeEffectScope\n // eslint-disable-next-line ts/no-this-alias -- 允许 this 临时别名\n activeEffectScope = this\n try {\n return fn()\n }\n finally {\n activeEffectScope = prev\n }\n }\n\n stop(): void {\n if (!this.active) {\n return\n }\n this.active = false\n const prev = activeEffectScope\n // eslint-disable-next-line ts/no-this-alias -- teardown 期间需要把新建 scope 绑定到当前停止中的 scope\n activeEffectScope = this\n\n let firstError: unknown\n let hasError = false\n const recordError = (error: unknown) => {\n if (hasError) {\n return\n }\n firstError = error\n hasError = true\n }\n\n try {\n const effects = this.effects.splice(0)\n for (const effect of effects) {\n try {\n stop(effect)\n }\n catch (error) {\n recordError(error)\n }\n }\n\n const cleanups = this.cleanups.splice(0)\n for (const cleanup of cleanups) {\n try {\n cleanup()\n }\n catch (error) {\n recordError(error)\n }\n }\n\n const scopes = this.scopes\n this.scopes = undefined\n if (scopes) {\n for (const scope of scopes) {\n try {\n scope.stop()\n }\n catch (error) {\n recordError(error)\n }\n }\n scopes.length = 0\n }\n }\n finally {\n if (this.parent?.scopes) {\n const index = this.parent.scopes.indexOf(this)\n if (index >= 0) {\n this.parent.scopes.splice(index, 1)\n }\n }\n this.parent = undefined\n activeEffectScope = prev\n }\n\n if (hasError) {\n throw firstError\n }\n }\n}\n\ninterface ScopedReactiveEffect<T = any> extends ReactiveEffect<T> {\n _scope: EffectScopeImpl | undefined\n}\n\nexport function effectScope(detached = false): EffectScope {\n return new EffectScopeImpl(detached)\n}\n\nexport function getCurrentScope(): EffectScope | undefined {\n return activeEffectScope\n}\n\nexport function onScopeDispose(fn: () => void): void {\n if (activeEffectScope?.active) {\n activeEffectScope.cleanups.push(fn)\n }\n}\n\n/**\n * 在不把读取记录到当前副作用的情况下执行函数。\n * 函数内部主动运行的新副作用仍会正常收集自己的依赖。\n */\nexport function runWithoutTracking<T>(fn: () => T): T {\n const previousShouldTrack = shouldTrack\n shouldTrack = false\n try {\n return fn()\n }\n finally {\n shouldTrack = previousShouldTrack\n }\n}\n\nfunction recordEffectScope(effect: ReactiveEffect) {\n if (!activeEffectScope) {\n return\n }\n if (activeEffectScope.active) {\n activeEffectScope.effects.push(effect)\n return\n }\n stop(effect)\n}\n\nexport interface EffectOptions {\n scheduler?: EffectScheduler\n lazy?: boolean\n onStop?: () => void\n}\n\nexport function createReactiveEffect<T>(fn: () => T, options: EffectOptions = {}): ReactiveEffect<T> {\n const effect = function reactiveEffect() {\n if (!effect.active) {\n return fn()\n }\n if (effect._running) {\n return fn()\n }\n cleanupEffect(effect)\n const previousScope = activeEffectScope\n activeEffectScope = effect._scope\n const previousShouldTrack = shouldTrack\n try {\n shouldTrack = true\n effect._running = true\n effectStack.push(effect)\n activeEffect = effect\n return fn()\n }\n finally {\n effectStack.pop()\n activeEffect = effectStack[effectStack.length - 1] ?? null\n effect._running = false\n activeEffectScope = previousScope\n shouldTrack = previousShouldTrack\n }\n } as ScopedReactiveEffect<T>\n\n effect.deps = []\n effect.scheduler = options.scheduler\n effect.onStop = options.onStop\n effect.active = true\n effect._running = false\n effect._fn = fn\n effect._scope = activeEffectScope\n\n return effect\n}\n\nfunction createEffect<T>(\n fn: () => T,\n options: EffectOptions,\n computed: boolean,\n): ReactiveEffect<T> {\n const runner = createReactiveEffect(fn, options)\n runner._computed = computed\n recordEffectScope(runner)\n if (!options.lazy) {\n runner()\n }\n return runner\n}\n\nexport function effect<T = any>(fn: () => T, options: EffectOptions = {}): ReactiveEffect<T> {\n return createEffect(fn, options, false)\n}\n\nexport function createComputedEffect<T>(\n fn: () => T,\n options: EffectOptions = {},\n): ReactiveEffect<T> {\n return createEffect(fn, options, true)\n}\n\nexport function track(target: object, key: PropertyKey) {\n if (!shouldTrack || !activeEffect) {\n return\n }\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n depsMap = new Map()\n targetMap.set(target, depsMap)\n }\n let dep = depsMap.get(key)\n if (!dep) {\n dep = new Set()\n depsMap.set(key, dep)\n }\n if (!dep.has(activeEffect)) {\n dep.add(activeEffect)\n activeEffect.deps.push(dep)\n }\n}\n\nfunction scheduleEffect(ef: ReactiveEffect) {\n if (ef._running) {\n return\n }\n // 计算属性只同步失效缓存,普通消费者仍由批处理队列合并。\n if (ef._computed) {\n runScheduledEffect(ef)\n return\n }\n if (batchDepth > 0 || isFlushingBatch) {\n batchedEffects.add(ef)\n return\n }\n runScheduledEffect(ef)\n}\n\nexport function trigger(target: object, key: PropertyKey) {\n const depsMap = targetMap.get(target)\n if (!depsMap) {\n return\n }\n const effects = depsMap.get(key)\n if (!effects) {\n return\n }\n const effectsToRun = new Set<ReactiveEffect>()\n effects.forEach((ef) => {\n if (ef !== activeEffect) {\n effectsToRun.add(ef)\n }\n })\n effectsToRun.forEach(scheduleEffect)\n}\n\nexport function trackEffects(dep: Dep) {\n if (!shouldTrack || !activeEffect) {\n return\n }\n if (!dep.has(activeEffect)) {\n dep.add(activeEffect)\n activeEffect.deps.push(dep)\n }\n}\n\nexport function triggerEffects(dep: Dep) {\n // 迭代时复制依赖集合,避免遍历过程中被重新加入导致死循环。\n const effectsToRun = new Set(dep)\n effectsToRun.forEach(scheduleEffect)\n}\n\n// 导出队列调度工具,供 watch/watchEffect 等高层 API 复用同一批处理逻辑\nexport { queueJob }\n"],"mappings":";;;;AAiBA,MAAM,4BAAY,IAAI,QAAuC;AAE7D,IAAI,eAAsC;AAC1C,MAAM,cAAgC,CAAC;AACvC,IAAI,cAAc;AAClB,IAAI;AAEJ,IAAI,aAAa;AACjB,IAAI,kBAAkB;AACtB,MAAM,iCAAiB,IAAI,IAAoB;AAC/C,MAAM,mCAAmB,IAAI,IAAgB;AAE7C,SAAS,mBAAmB,IAAoB;CAC9C,IAAI,CAAC,GAAG,QACN;CAEF,IAAI,GAAG,WAAW;EAChB,MAAM,gBAAgB;EACtB,oBAAqB,GAA4B;EACjD,IAAI;GACF,GAAG,UAAU;EACf,UACQ;GACN,oBAAoB;EACtB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MAAM,+BAAe,IAAI,IAAoB;CAC7C,QAAQ,SAAS,OAAO;EACtB,IAAI,OAAO,cACT,aAAa,IAAI,EAAE;CAEvB,CAAC;CACD,aAAa,QAAQ,cAAc;AACrC;AAEA,SAAgB,aAAa,KAAU;CACrC,IAAI,CAAC,eAAe,CAAC,cACnB;CAEF,IAAI,CAAC,IAAI,IAAI,YAAY,GAAG;EAC1B,IAAI,IAAI,YAAY;EACpB,aAAa,KAAK,KAAK,GAAG;CAC5B;AACF;AAEA,SAAgB,eAAe,KAAU;CAGvC,IADyB,IAAI,GAClB,CAAC,CAAC,QAAQ,cAAc;AACrC"}
|
|
1
|
+
{"version":3,"file":"core.mjs","names":[],"sources":["../../../src/reactivity/core.ts"],"sourcesContent":["import { queueJob } from '../scheduler'\n\nexport type EffectScheduler = () => void\n\nexport type Dep = Set<ReactiveEffect>\n\nexport interface ReactiveEffect<T = any> {\n (): T\n deps: Dep[]\n scheduler?: EffectScheduler\n active: boolean\n _running: boolean\n _fn: () => T\n _computed?: boolean\n onStop?: () => void\n}\n\nconst targetMap = new WeakMap<object, Map<PropertyKey, Dep>>()\n\nlet activeEffect: ReactiveEffect | null = null\nconst effectStack: ReactiveEffect[] = []\nlet shouldTrack = true\nlet activeEffectScope: EffectScopeImpl | undefined\n\nlet batchDepth = 0\nlet isFlushingBatch = false\nconst batchedEffects = new Set<ReactiveEffect>()\nconst batchedCallbacks = new Set<() => void>()\n\nfunction runScheduledEffect(ef: ReactiveEffect) {\n if (!ef.active) {\n return\n }\n if (ef.scheduler) {\n const previousScope = activeEffectScope\n activeEffectScope = (ef as ScopedReactiveEffect)._scope\n try {\n ef.scheduler()\n }\n finally {\n activeEffectScope = previousScope\n }\n return\n }\n ef()\n}\n\n/** 在当前批次的同步副作用全部完成后执行包内通知。 */\nexport function queueBatchCallback(callback: () => void) {\n if (batchDepth > 0 || isFlushingBatch) {\n batchedCallbacks.add(callback)\n return\n }\n batchedCallbacks.delete(callback)\n callback()\n}\n\nexport function startBatch() {\n batchDepth++\n}\n\nfunction takeBatchedEffect(effects: Set<ReactiveEffect>): ReactiveEffect | undefined {\n const next = effects.values().next()\n if (next.done) {\n return undefined\n }\n effects.delete(next.value)\n return next.value\n}\n\nfunction flushBatchedEffects() {\n let firstError: unknown\n let hasError = false\n isFlushingBatch = true\n try {\n while (batchedEffects.size) {\n const effect = takeBatchedEffect(batchedEffects)\n if (!effect) {\n continue\n }\n try {\n runScheduledEffect(effect)\n }\n catch (error) {\n if (!hasError) {\n firstError = error\n hasError = true\n }\n }\n }\n }\n finally {\n isFlushingBatch = false\n }\n // 通知属于已完成批次之后的操作,保留订阅回调内同步变更的重入保护。\n while (batchedCallbacks.size) {\n const callback = batchedCallbacks.values().next().value!\n batchedCallbacks.delete(callback)\n try {\n callback()\n }\n catch (error) {\n if (!hasError) {\n firstError = error\n hasError = true\n }\n }\n }\n if (hasError) {\n throw firstError\n }\n}\n\nexport function endBatch() {\n if (batchDepth === 0) {\n return\n }\n batchDepth--\n if (batchDepth === 0 && !isFlushingBatch) {\n flushBatchedEffects()\n }\n}\n\nexport function batch<T>(fn: () => T): T {\n startBatch()\n try {\n return fn()\n }\n finally {\n endBatch()\n }\n}\n\nfunction cleanupEffect(effect: ReactiveEffect) {\n const { deps } = effect\n for (let i = 0; i < deps.length; i++) {\n deps[i].delete(effect)\n }\n deps.length = 0\n}\n\nexport function stop(runner: ReactiveEffect) {\n if (!runner.active) {\n return\n }\n runner.active = false\n cleanupEffect(runner)\n runner.onStop?.()\n}\n\nexport interface EffectScope {\n active: boolean\n effects: ReactiveEffect[]\n cleanups: (() => void)[]\n run: <T>(fn: () => T) => T | undefined\n stop: () => void\n}\n\nclass EffectScopeImpl implements EffectScope {\n active = true\n effects: ReactiveEffect[] = []\n cleanups: (() => void)[] = []\n private parent: EffectScopeImpl | undefined\n private scopes: EffectScopeImpl[] | undefined\n\n constructor(private detached = false) {\n if (!detached && activeEffectScope) {\n if (!activeEffectScope.active) {\n this.active = false\n return\n }\n this.parent = activeEffectScope\n ;(activeEffectScope.scopes ||= []).push(this)\n }\n }\n\n run<T>(fn: () => T): T | undefined {\n if (!this.active) {\n return\n }\n const prev = activeEffectScope\n // eslint-disable-next-line ts/no-this-alias -- 允许 this 临时别名\n activeEffectScope = this\n try {\n return fn()\n }\n finally {\n activeEffectScope = prev\n }\n }\n\n stop(): void {\n if (!this.active) {\n return\n }\n this.active = false\n const prev = activeEffectScope\n // eslint-disable-next-line ts/no-this-alias -- teardown 期间需要把新建 scope 绑定到当前停止中的 scope\n activeEffectScope = this\n\n let firstError: unknown\n let hasError = false\n const recordError = (error: unknown) => {\n if (hasError) {\n return\n }\n firstError = error\n hasError = true\n }\n\n try {\n const effects = this.effects.splice(0)\n for (const effect of effects) {\n try {\n stop(effect)\n }\n catch (error) {\n recordError(error)\n }\n }\n\n const cleanups = this.cleanups.splice(0)\n for (const cleanup of cleanups) {\n try {\n cleanup()\n }\n catch (error) {\n recordError(error)\n }\n }\n\n const scopes = this.scopes\n this.scopes = undefined\n if (scopes) {\n for (const scope of scopes) {\n try {\n scope.stop()\n }\n catch (error) {\n recordError(error)\n }\n }\n scopes.length = 0\n }\n }\n finally {\n if (this.parent?.scopes) {\n const index = this.parent.scopes.indexOf(this)\n if (index >= 0) {\n this.parent.scopes.splice(index, 1)\n }\n }\n this.parent = undefined\n activeEffectScope = prev\n }\n\n if (hasError) {\n throw firstError\n }\n }\n}\n\ninterface ScopedReactiveEffect<T = any> extends ReactiveEffect<T> {\n _scope: EffectScopeImpl | undefined\n}\n\nexport function effectScope(detached = false): EffectScope {\n return new EffectScopeImpl(detached)\n}\n\nexport function getCurrentScope(): EffectScope | undefined {\n return activeEffectScope\n}\n\nexport function onScopeDispose(fn: () => void): void {\n if (activeEffectScope?.active) {\n activeEffectScope.cleanups.push(fn)\n }\n}\n\n/**\n * 在不把读取记录到当前副作用的情况下执行函数。\n * 函数内部主动运行的新副作用仍会正常收集自己的依赖。\n */\nexport function runWithoutTracking<T>(fn: () => T): T {\n const previousShouldTrack = shouldTrack\n shouldTrack = false\n try {\n return fn()\n }\n finally {\n shouldTrack = previousShouldTrack\n }\n}\n\nfunction recordEffectScope(effect: ReactiveEffect) {\n if (!activeEffectScope) {\n return\n }\n if (activeEffectScope.active) {\n activeEffectScope.effects.push(effect)\n return\n }\n stop(effect)\n}\n\nexport interface EffectOptions {\n scheduler?: EffectScheduler\n lazy?: boolean\n onStop?: () => void\n}\n\nexport function createReactiveEffect<T>(fn: () => T, options: EffectOptions = {}): ReactiveEffect<T> {\n const effect = function reactiveEffect() {\n if (!effect.active) {\n return fn()\n }\n if (effect._running) {\n return fn()\n }\n cleanupEffect(effect)\n const previousScope = activeEffectScope\n activeEffectScope = effect._scope\n const previousShouldTrack = shouldTrack\n try {\n shouldTrack = true\n effect._running = true\n effectStack.push(effect)\n activeEffect = effect\n return fn()\n }\n finally {\n effectStack.pop()\n activeEffect = effectStack[effectStack.length - 1] ?? null\n effect._running = false\n activeEffectScope = previousScope\n shouldTrack = previousShouldTrack\n }\n } as ScopedReactiveEffect<T>\n\n effect.deps = []\n effect.scheduler = options.scheduler\n effect.onStop = options.onStop\n effect.active = true\n effect._running = false\n effect._fn = fn\n effect._scope = activeEffectScope\n\n return effect\n}\n\nfunction createEffect<T>(\n fn: () => T,\n options: EffectOptions,\n computed: boolean,\n): ReactiveEffect<T> {\n const runner = createReactiveEffect(fn, options)\n runner._computed = computed\n recordEffectScope(runner)\n if (!options.lazy) {\n runner()\n }\n return runner\n}\n\nexport function effect<T = any>(fn: () => T, options: EffectOptions = {}): ReactiveEffect<T> {\n return createEffect(fn, options, false)\n}\n\nexport function createComputedEffect<T>(\n fn: () => T,\n options: EffectOptions = {},\n): ReactiveEffect<T> {\n return createEffect(fn, options, true)\n}\n\nexport function track(target: object, key: PropertyKey) {\n if (!shouldTrack || !activeEffect) {\n return\n }\n let depsMap = targetMap.get(target)\n if (!depsMap) {\n depsMap = new Map()\n targetMap.set(target, depsMap)\n }\n let dep = depsMap.get(key)\n if (!dep) {\n dep = new Set()\n depsMap.set(key, dep)\n }\n if (!dep.has(activeEffect)) {\n dep.add(activeEffect)\n activeEffect.deps.push(dep)\n }\n}\n\nfunction scheduleEffect(ef: ReactiveEffect) {\n if (ef._running) {\n return\n }\n // 计算属性只同步失效缓存,普通消费者仍由批处理队列合并。\n if (ef._computed) {\n runScheduledEffect(ef)\n return\n }\n if (batchDepth > 0 || isFlushingBatch) {\n batchedEffects.add(ef)\n return\n }\n runScheduledEffect(ef)\n}\n\nexport function trigger(target: object, key: PropertyKey) {\n const depsMap = targetMap.get(target)\n if (!depsMap) {\n return\n }\n const effects = depsMap.get(key)\n if (!effects) {\n return\n }\n const effectsToRun = new Set<ReactiveEffect>()\n effects.forEach((ef) => {\n if (ef !== activeEffect) {\n effectsToRun.add(ef)\n }\n })\n effectsToRun.forEach(scheduleEffect)\n}\n\nexport function trackEffects(dep: Dep) {\n if (!shouldTrack || !activeEffect) {\n return\n }\n if (!dep.has(activeEffect)) {\n dep.add(activeEffect)\n activeEffect.deps.push(dep)\n }\n}\n\nexport function triggerEffects(dep: Dep) {\n // 迭代时复制依赖集合,避免遍历过程中被重新加入导致死循环。\n const effectsToRun = new Set(dep)\n effectsToRun.forEach(scheduleEffect)\n}\n\n// 导出队列调度工具,供 watch/watchEffect 等高层 API 复用同一批处理逻辑\nexport { queueJob }\n"],"mappings":";;;;AAiBA,MAAM,4BAAY,IAAI,QAAuC;AAE7D,IAAI,eAAsC;AAC1C,MAAM,cAAgC,CAAC;AACvC,IAAI,cAAc;AAClB,IAAI;AAEJ,IAAI,aAAa;AACjB,IAAI,kBAAkB;AACtB,MAAM,iCAAiB,IAAI,IAAoB;AAC/C,MAAM,mCAAmB,IAAI,IAAgB;AAE7C,SAAS,mBAAmB,IAAoB;CAC9C,IAAI,CAAC,GAAG,QACN;CAEF,IAAI,GAAG,WAAW;EAChB,MAAM,gBAAgB;EACtB,oBAAqB,GAA4B;EACjD,IAAI;GACF,GAAG,UAAU;EACf,UACQ;GAC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EF,MAAM,+BAAe,IAAI,IAAoB;CAC7C,QAAQ,SAAS,OAAO;EACtB,IAAI,OAAO,cACT,aAAa,IAAI,EAAE;CAEvB,CAAC;CACD,aAAa,QAAQ,cAAc;AACrC;AAEA,SAAgB,aAAa,KAAU;CACrC,IAAI,CAAC,eAAe,CAAC,cACnB;CAEF,IAAI,CAAC,IAAI,IAAI,YAAY,GAAG;EAC1B,IAAI,IAAI,YAAY;EACpB,aAAa,KAAK,KAAK,GAAG;CAC5B;AACF;AAEA,SAAgB,eAAe,KAAU;CAGvC,IADyB,IAAI,GAClB,CAAC,CAAC,QAAQ,cAAc;AACrC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AsyncDerivation, AsyncDerivationContext, AsyncDerivationState, AsyncDerivationStatus, UseAsyncDerivationOptions, useAsyncDerivation } from "./asyncDerivation.mjs";
|
|
2
|
+
import { CustomRefFactory, CustomRefOptions, CustomRefSource, MaybeRef, MaybeRefOrGetter, Ref, ShallowRef, customRef, isRef, ref, toValue, unref } from "./ref.mjs";
|
|
3
|
+
import { ComputedGetter, ComputedRef, ComputedSetter, WritableComputedOptions, WritableComputedRef, computed } from "./computed.mjs";
|
|
4
|
+
import { EffectScope, batch, effect, effectScope, endBatch, getCurrentScope, onScopeDispose, startBatch, stop } from "./core.mjs";
|
|
5
|
+
import { MutationKind, MutationOp, MutationRecord, addMutationRecorder, removeMutationRecorder } from "./reactive/mutation.mjs";
|
|
6
|
+
import { PrelinkReactiveTreeOptions, prelinkReactiveTree, touchReactive } from "./reactive/patch.mjs";
|
|
7
|
+
import { isShallowReactive, shallowReactive } from "./reactive/shallow.mjs";
|
|
8
|
+
import { toRaw } from "./reactive/shared.mjs";
|
|
9
|
+
import { getReactiveVersion, isRaw, isReactive, markRaw, reactive } from "./reactive.mjs";
|
|
10
|
+
import { isProxy, isReadonly, readonly, shallowReadonly } from "./readonly.mjs";
|
|
11
|
+
import { isShallowRef, shallowRef, triggerRef } from "./shallowRef.mjs";
|
|
12
|
+
import { ToRefs, toRef, toRefs } from "./toRefs.mjs";
|
|
13
|
+
import { traverse } from "./traverse.mjs";
|
|
14
|
+
import { MapSources, MaybeUndefined, MultiWatchSources, OnCleanup, WatchCallback, WatchEffect, WatchEffectOptions, WatchMultiSources, WatchOptions, WatchScheduler, WatchSource, WatchSourceValue, WatchSources, WatchStopHandle, getDeepWatchStrategy, setDeepWatchStrategy } from "./watch/types.mjs";
|
|
15
|
+
import { watch, watchEffect, watchPostEffect, watchSyncEffect } from "./watch.mjs";
|
|
16
|
+
export { type AsyncDerivation, type AsyncDerivationContext, type AsyncDerivationState, type AsyncDerivationStatus, type ComputedGetter, type ComputedRef, type ComputedSetter, type CustomRefFactory, type CustomRefOptions, type CustomRefSource, type EffectScope, type MapSources, type MaybeRef, type MaybeRefOrGetter, type MaybeUndefined, type MultiWatchSources, type MutationKind, type MutationOp, type MutationRecord, type OnCleanup, type PrelinkReactiveTreeOptions, type Ref, type ShallowRef, type ToRefs, type UseAsyncDerivationOptions, type WatchCallback, type WatchEffect, type WatchEffectOptions, type WatchMultiSources, type WatchOptions, type WatchScheduler, type WatchSource, type WatchSourceValue, type WatchSources, type WatchStopHandle, type WritableComputedOptions, type WritableComputedRef, addMutationRecorder, batch, computed, customRef, effect, effectScope, endBatch, getCurrentScope, getDeepWatchStrategy, getReactiveVersion, isProxy, isRaw, isReactive, isReadonly, isRef, isShallowReactive, isShallowRef, markRaw, onScopeDispose, prelinkReactiveTree, reactive, readonly, ref, removeMutationRecorder, setDeepWatchStrategy, shallowReactive, shallowReadonly, shallowRef, startBatch, stop, toRaw, toRef, toRefs, toValue, touchReactive, traverse, triggerRef, unref, useAsyncDerivation, watch, watchEffect, watchPostEffect, watchSyncEffect };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/reactivity/reactive/mutation.d.ts
|
|
2
|
+
export type MutationOp = 'set' | 'delete';
|
|
3
|
+
export type MutationKind = 'property' | 'array';
|
|
4
|
+
export interface MutationRecord {
|
|
5
|
+
root: object;
|
|
6
|
+
kind: MutationKind;
|
|
7
|
+
op: MutationOp;
|
|
8
|
+
/**
|
|
9
|
+
* 点路径(例如 `a.b.c`);当路径不可靠时为 undefined。
|
|
10
|
+
*/
|
|
11
|
+
path?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 当路径不唯一时回退使用的顶层键列表。
|
|
14
|
+
*/
|
|
15
|
+
fallbackTopKeys?: string[];
|
|
16
|
+
}
|
|
17
|
+
type MutationRecorder = (record: MutationRecord) => void;
|
|
18
|
+
export declare function addMutationRecorder(recorder: MutationRecorder): void;
|
|
19
|
+
export declare function removeMutationRecorder(recorder: MutationRecorder): void;
|
|
20
|
+
//#endregion
|
|
21
|
+
//# sourceMappingURL=mutation.d.mts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/reactivity/reactive/patch.d.ts
|
|
2
|
+
export interface PrelinkReactiveTreeOptions {
|
|
3
|
+
shouldIncludeTopKey?: (key: string) => boolean;
|
|
4
|
+
maxDepth?: number;
|
|
5
|
+
maxKeys?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* 预链接响应式树结构,供运行时差量路径追踪使用。
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function prelinkReactiveTree(root: object, options?: PrelinkReactiveTreeOptions): void;
|
|
12
|
+
/**
|
|
13
|
+
* 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function touchReactive(target: object): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=patch.d.mts.map
|
|
@@ -11,9 +11,9 @@ function prelinkReactiveTree(root, options) {
|
|
|
11
11
|
const rootRaw = toRaw(root);
|
|
12
12
|
rawPathMap.set(rootRaw, "");
|
|
13
13
|
indexPatchNode(rootRaw, rootRaw);
|
|
14
|
-
const shouldIncludeTopKey = options
|
|
15
|
-
const maxDepth = typeof
|
|
16
|
-
const maxKeys = typeof
|
|
14
|
+
const shouldIncludeTopKey = options?.shouldIncludeTopKey;
|
|
15
|
+
const maxDepth = typeof options?.maxDepth === "number" ? Math.max(0, Math.floor(options.maxDepth)) : Number.POSITIVE_INFINITY;
|
|
16
|
+
const maxKeys = typeof options?.maxKeys === "number" ? Math.max(0, Math.floor(options.maxKeys)) : Number.POSITIVE_INFINITY;
|
|
17
17
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
18
18
|
const stack = [{
|
|
19
19
|
current: rootRaw,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.mjs","names":[],"sources":["../../../../src/reactivity/reactive/patch.ts"],"sourcesContent":["import { track } from '../core'\nimport {\n adoptReactiveRoot,\n indexPatchNode,\n rawMultiParentSet,\n rawParentMap,\n rawParentsMap,\n rawPathMap,\n rawRootMap,\n rawVersionMap,\n recordParentLink,\n rootPatchNodesMap,\n} from './patchState'\nimport { isObject, ReactiveFlags, toRaw, VERSION_KEY } from './shared'\n\nexport interface PrelinkReactiveTreeOptions {\n shouldIncludeTopKey?: (key: string) => boolean\n maxDepth?: number\n maxKeys?: number\n}\n\n/**\n * 预链接响应式树结构,供运行时差量路径追踪使用。\n * @internal\n */\nexport function prelinkReactiveTree(root: object, options?: PrelinkReactiveTreeOptions) {\n const rootRaw = toRaw(root as any) as object\n rawPathMap.set(rootRaw, '')\n indexPatchNode(rootRaw, rootRaw)\n\n const shouldIncludeTopKey = options?.shouldIncludeTopKey\n const maxDepth = typeof options?.maxDepth === 'number' ? Math.max(0, Math.floor(options!.maxDepth!)) : Number.POSITIVE_INFINITY\n const maxKeys = typeof options?.maxKeys === 'number' ? Math.max(0, Math.floor(options!.maxKeys!)) : Number.POSITIVE_INFINITY\n\n const visited = new WeakSet<object>()\n const stack: Array<{ current: object, path: string, depth: number }> = [{ current: rootRaw, path: '', depth: 0 }]\n let indexed = 0\n\n while (stack.length) {\n const node = stack.pop()!\n if (visited.has(node.current)) {\n continue\n }\n visited.add(node.current)\n rawPathMap.set(node.current, node.path)\n indexPatchNode(rootRaw, node.current)\n indexed += 1\n if (indexed >= maxKeys) {\n continue\n }\n\n if (node.depth >= maxDepth) {\n continue\n }\n if (Array.isArray(node.current)) {\n // 数组不预先展开子元素:大列表场景避免 O(n) 初始化开销。\n continue\n }\n\n const entries = Object.entries(node.current as any)\n for (const [key, value] of entries) {\n if (node.path === '' && shouldIncludeTopKey && !shouldIncludeTopKey(key)) {\n continue\n }\n if (!isObject(value)) {\n continue\n }\n if ((value as any)[ReactiveFlags.SKIP]) {\n continue\n }\n const childRaw = toRaw(value as any) as object\n adoptReactiveRoot(childRaw, node.current)\n recordParentLink(childRaw, node.current, key)\n if (!rawMultiParentSet.has(childRaw)) {\n const childPath = node.path ? `${node.path}.${key}` : key\n rawPathMap.set(childRaw, childPath)\n }\n indexPatchNode(rootRaw, childRaw)\n stack.push({ current: childRaw, path: node.path ? `${node.path}.${key}` : key, depth: node.depth + 1 })\n }\n }\n}\n\n/**\n * 清理预链接阶段建立的路径与父子索引。\n * @internal\n */\nexport function clearPatchIndices(root: object) {\n const rootRaw = toRaw(root as any) as object\n const nodes = rootPatchNodesMap.get(rootRaw)\n if (!nodes) {\n rawPathMap.delete(rootRaw)\n return\n }\n\n for (const node of nodes) {\n rawParentMap.delete(node)\n rawParentsMap.delete(node)\n rawPathMap.delete(node)\n rawMultiParentSet.delete(node)\n rawRootMap.delete(node)\n rawVersionMap.delete(node)\n }\n\n rootPatchNodesMap.delete(rootRaw)\n}\n\n/**\n * 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。\n * @internal\n */\nexport function touchReactive(target: object) {\n const raw = toRaw(target as any) as object\n track(raw, VERSION_KEY)\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,oBAAoB,MAAc,SAAsC;CACtF,MAAM,UAAU,MAAM,IAAW;CACjC,WAAW,IAAI,SAAS,EAAE;CAC1B,eAAe,SAAS,OAAO;CAE/B,MAAM,
|
|
1
|
+
{"version":3,"file":"patch.mjs","names":[],"sources":["../../../../src/reactivity/reactive/patch.ts"],"sourcesContent":["import { track } from '../core'\nimport {\n adoptReactiveRoot,\n indexPatchNode,\n rawMultiParentSet,\n rawParentMap,\n rawParentsMap,\n rawPathMap,\n rawRootMap,\n rawVersionMap,\n recordParentLink,\n rootPatchNodesMap,\n} from './patchState'\nimport { isObject, ReactiveFlags, toRaw, VERSION_KEY } from './shared'\n\nexport interface PrelinkReactiveTreeOptions {\n shouldIncludeTopKey?: (key: string) => boolean\n maxDepth?: number\n maxKeys?: number\n}\n\n/**\n * 预链接响应式树结构,供运行时差量路径追踪使用。\n * @internal\n */\nexport function prelinkReactiveTree(root: object, options?: PrelinkReactiveTreeOptions) {\n const rootRaw = toRaw(root as any) as object\n rawPathMap.set(rootRaw, '')\n indexPatchNode(rootRaw, rootRaw)\n\n const shouldIncludeTopKey = options?.shouldIncludeTopKey\n const maxDepth = typeof options?.maxDepth === 'number' ? Math.max(0, Math.floor(options!.maxDepth!)) : Number.POSITIVE_INFINITY\n const maxKeys = typeof options?.maxKeys === 'number' ? Math.max(0, Math.floor(options!.maxKeys!)) : Number.POSITIVE_INFINITY\n\n const visited = new WeakSet<object>()\n const stack: Array<{ current: object, path: string, depth: number }> = [{ current: rootRaw, path: '', depth: 0 }]\n let indexed = 0\n\n while (stack.length) {\n const node = stack.pop()!\n if (visited.has(node.current)) {\n continue\n }\n visited.add(node.current)\n rawPathMap.set(node.current, node.path)\n indexPatchNode(rootRaw, node.current)\n indexed += 1\n if (indexed >= maxKeys) {\n continue\n }\n\n if (node.depth >= maxDepth) {\n continue\n }\n if (Array.isArray(node.current)) {\n // 数组不预先展开子元素:大列表场景避免 O(n) 初始化开销。\n continue\n }\n\n const entries = Object.entries(node.current as any)\n for (const [key, value] of entries) {\n if (node.path === '' && shouldIncludeTopKey && !shouldIncludeTopKey(key)) {\n continue\n }\n if (!isObject(value)) {\n continue\n }\n if ((value as any)[ReactiveFlags.SKIP]) {\n continue\n }\n const childRaw = toRaw(value as any) as object\n adoptReactiveRoot(childRaw, node.current)\n recordParentLink(childRaw, node.current, key)\n if (!rawMultiParentSet.has(childRaw)) {\n const childPath = node.path ? `${node.path}.${key}` : key\n rawPathMap.set(childRaw, childPath)\n }\n indexPatchNode(rootRaw, childRaw)\n stack.push({ current: childRaw, path: node.path ? `${node.path}.${key}` : key, depth: node.depth + 1 })\n }\n }\n}\n\n/**\n * 清理预链接阶段建立的路径与父子索引。\n * @internal\n */\nexport function clearPatchIndices(root: object) {\n const rootRaw = toRaw(root as any) as object\n const nodes = rootPatchNodesMap.get(rootRaw)\n if (!nodes) {\n rawPathMap.delete(rootRaw)\n return\n }\n\n for (const node of nodes) {\n rawParentMap.delete(node)\n rawParentsMap.delete(node)\n rawPathMap.delete(node)\n rawMultiParentSet.delete(node)\n rawRootMap.delete(node)\n rawVersionMap.delete(node)\n }\n\n rootPatchNodesMap.delete(rootRaw)\n}\n\n/**\n * 让 effect 订阅整个对象的“版本号”,无需深度遍历即可对任何字段变化做出响应。\n * @internal\n */\nexport function touchReactive(target: object) {\n const raw = toRaw(target as any) as object\n track(raw, VERSION_KEY)\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,oBAAoB,MAAc,SAAsC;CACtF,MAAM,UAAU,MAAM,IAAW;CACjC,WAAW,IAAI,SAAS,EAAE;CAC1B,eAAe,SAAS,OAAO;CAE/B,MAAM,sBAAsB,SAAS;CACrC,MAAM,WAAW,OAAO,SAAS,aAAa,WAAW,KAAK,IAAI,GAAG,KAAK,MAAM,QAAS,QAAS,CAAC,IAAI,OAAO;CAC9G,MAAM,UAAU,OAAO,SAAS,YAAY,WAAW,KAAK,IAAI,GAAG,KAAK,MAAM,QAAS,OAAQ,CAAC,IAAI,OAAO;CAE3G,MAAM,0BAAU,IAAI,QAAgB;CACpC,MAAM,QAAiE,CAAC;EAAE,SAAS;EAAS,MAAM;EAAI,OAAO;CAAE,CAAC;CAChH,IAAI,U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W,OAAO,IAAI;EACtB,cAAc,OAAO,IAAI;CAC3B;CAEA,kBAAkB,OAAO,OAAO;AAClC;;;;;AAMA,SAAgB,cAAc,QAAgB;CAC5C,MAAM,MAAM,MAAM,MAAa;CAC/B,MAAM,KAAK,WAAW;AACxB"}
|
|
@@ -20,20 +20,17 @@ function indexPatchNode(root, node) {
|
|
|
20
20
|
getRootPatchNodes(root).add(node);
|
|
21
21
|
}
|
|
22
22
|
function bumpRawVersion(target) {
|
|
23
|
-
|
|
24
|
-
rawVersionMap.set(target, ((_rawVersionMap$get = rawVersionMap.get(target)) !== null && _rawVersionMap$get !== void 0 ? _rawVersionMap$get : 0) + 1);
|
|
23
|
+
rawVersionMap.set(target, (rawVersionMap.get(target) ?? 0) + 1);
|
|
25
24
|
}
|
|
26
25
|
function getRawVersion(target) {
|
|
27
|
-
|
|
28
|
-
return (_rawVersionMap$get2 = rawVersionMap.get(target)) !== null && _rawVersionMap$get2 !== void 0 ? _rawVersionMap$get2 : 0;
|
|
26
|
+
return rawVersionMap.get(target) ?? 0;
|
|
29
27
|
}
|
|
30
28
|
/**
|
|
31
29
|
* 将尚未归属父状态树的响应式节点接入父级根节点。
|
|
32
30
|
* @internal
|
|
33
31
|
*/
|
|
34
32
|
function adoptReactiveRoot(child, parent) {
|
|
35
|
-
|
|
36
|
-
const parentRoot = (_rawRootMap$get = rawRootMap.get(parent)) !== null && _rawRootMap$get !== void 0 ? _rawRootMap$get : parent;
|
|
33
|
+
const parentRoot = rawRootMap.get(parent) ?? parent;
|
|
37
34
|
const existingRoot = rawRootMap.get(child);
|
|
38
35
|
if (!existingRoot || existingRoot === child || existingRoot === parent) rawRootMap.set(child, parentRoot);
|
|
39
36
|
}
|
|
@@ -89,8 +86,7 @@ function recordParentLink(child, parent, key) {
|
|
|
89
86
|
return;
|
|
90
87
|
}
|
|
91
88
|
if (mutationRecorders.size) {
|
|
92
|
-
|
|
93
|
-
const root = (_rawRootMap$get2 = rawRootMap.get(parent)) !== null && _rawRootMap$get2 !== void 0 ? _rawRootMap$get2 : parent;
|
|
89
|
+
const root = rawRootMap.get(parent) ?? parent;
|
|
94
90
|
indexPatchNode(root, parent);
|
|
95
91
|
indexPatchNode(root, child);
|
|
96
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patchState.mjs","names":[],"sources":["../../../../src/reactivity/reactive/patchState.ts"],"sourcesContent":["import { mutationRecorders } from './mutation'\n\nexport const rawRootMap = new WeakMap<object, object>()\nexport const rawVersionMap = new WeakMap<object, number>()\nexport const rawParentMap = new WeakMap<object, { parent: object, key: PropertyKey }>()\nexport const rawParentsMap = new WeakMap<object, Map<object, Set<PropertyKey>>>()\nexport const rawMultiParentSet = new WeakSet<object>()\nexport const rawPathMap = new WeakMap<object, string>()\nexport const rootPatchNodesMap = new WeakMap<object, Set<object>>()\n\nfunction getRootPatchNodes(root: object) {\n let nodes = rootPatchNodesMap.get(root)\n if (!nodes) {\n nodes = new Set()\n rootPatchNodesMap.set(root, nodes)\n }\n return nodes\n}\n\nexport function indexPatchNode(root: object, node: object) {\n getRootPatchNodes(root).add(node)\n}\n\nexport function bumpRawVersion(target: object) {\n rawVersionMap.set(target, (rawVersionMap.get(target) ?? 0) + 1)\n}\n\nexport function getRawVersion(target: object) {\n return rawVersionMap.get(target) ?? 0\n}\n\n/**\n * 将尚未归属父状态树的响应式节点接入父级根节点。\n * @internal\n */\nexport function adoptReactiveRoot(child: object, parent: object) {\n const parentRoot = rawRootMap.get(parent) ?? parent\n const existingRoot = rawRootMap.get(child)\n if (!existingRoot || existingRoot === child || existingRoot === parent) {\n rawRootMap.set(child, parentRoot)\n }\n}\n\nexport function bumpAncestorVersions(target: object) {\n const visited = new Set<object>()\n const stack: object[] = [target]\n for (let i = 0; i < 2000 && stack.length; i++) {\n const current = stack.pop()!\n const parents = rawParentsMap.get(current)\n if (!parents) {\n continue\n }\n for (const parent of parents.keys()) {\n if (visited.has(parent)) {\n continue\n }\n visited.add(parent)\n bumpRawVersion(parent)\n stack.push(parent)\n }\n }\n}\n\nfunction refreshPathUniqueness(child: object) {\n const parents = rawParentsMap.get(child)\n if (!parents) {\n rawMultiParentSet.delete(child)\n rawParentMap.delete(child)\n return\n }\n\n let uniqueParent: object | undefined\n let uniqueKey: PropertyKey | undefined\n let total = 0\n for (const [parent, keys] of parents) {\n for (const k of keys) {\n total += 1\n if (total > 1) {\n break\n }\n uniqueParent = parent\n uniqueKey = k\n }\n if (total > 1) {\n break\n }\n }\n\n if (total === 1 && uniqueParent && uniqueKey) {\n rawMultiParentSet.delete(child)\n rawParentMap.set(child, { parent: uniqueParent, key: uniqueKey })\n return\n }\n\n rawMultiParentSet.add(child)\n rawParentMap.delete(child)\n}\n\nexport function recordParentLink(child: object, parent: object, key: PropertyKey) {\n if (typeof key !== 'string') {\n rawMultiParentSet.add(child)\n rawParentMap.delete(child)\n return\n }\n\n if (mutationRecorders.size) {\n const root = rawRootMap.get(parent) ?? parent\n indexPatchNode(root, parent)\n indexPatchNode(root, child)\n }\n\n let parents = rawParentsMap.get(child)\n if (!parents) {\n parents = new Map()\n rawParentsMap.set(child, parents)\n }\n\n let keys = parents.get(parent)\n if (!keys) {\n keys = new Set()\n parents.set(parent, keys)\n }\n\n keys.add(key)\n refreshPathUniqueness(child)\n}\n\nexport function removeParentLink(child: object, parent: object, key: PropertyKey) {\n const parents = rawParentsMap.get(child)\n if (!parents) {\n return\n }\n const keys = parents.get(parent)\n if (!keys) {\n return\n }\n keys.delete(key)\n if (!keys.size) {\n parents.delete(parent)\n }\n if (!parents.size) {\n rawParentsMap.delete(child)\n }\n refreshPathUniqueness(child)\n}\n\nexport function resolvePathToTarget(root: object, target: object): string[] | undefined {\n if (target === root) {\n return []\n }\n if (rawMultiParentSet.has(target)) {\n return undefined\n }\n const segments: string[] = []\n let current: object = target\n for (let i = 0; i < 2000; i++) {\n if (current === root) {\n return segments.reverse()\n }\n if (rawMultiParentSet.has(current)) {\n return undefined\n }\n const info = rawParentMap.get(current)\n if (!info) {\n return undefined\n }\n if (typeof info.key !== 'string') {\n return undefined\n }\n segments.push(info.key)\n current = info.parent\n }\n return undefined\n}\n"],"mappings":";;;AAEA,MAAa,6BAAa,IAAI,QAAwB;AACtD,MAAa,gCAAgB,IAAI,QAAwB;AACzD,MAAa,+BAAe,IAAI,QAAsD;AACtF,MAAa,gCAAgB,IAAI,QAA+C;AAChF,MAAa,oCAAoB,IAAI,QAAgB;AACrD,MAAa,6BAAa,IAAI,QAAwB;AACtD,MAAa,oCAAoB,IAAI,QAA6B;AAElE,SAAS,kBAAkB,MAAc;CACvC,IAAI,QAAQ,kBAAkB,IAAI,IAAI;CACtC,IAAI,CAAC,OAAO;EACV,wBAAQ,IAAI,IAAI;EAChB,kBAAkB,IAAI,MAAM,KAAK;CACnC;CACA,OAAO;AACT;AAEA,SAAgB,eAAe,MAAc,MAAc;CACzD,kBAAkB,IAAI,CAAC,CAAC,IAAI,IAAI;AAClC;AAEA,SAAgB,eAAe,QAAgB
|
|
1
|
+
{"version":3,"file":"patchState.mjs","names":[],"sources":["../../../../src/reactivity/reactive/patchState.ts"],"sourcesContent":["import { mutationRecorders } from './mutation'\n\nexport const rawRootMap = new WeakMap<object, object>()\nexport const rawVersionMap = new WeakMap<object, number>()\nexport const rawParentMap = new WeakMap<object, { parent: object, key: PropertyKey }>()\nexport const rawParentsMap = new WeakMap<object, Map<object, Set<PropertyKey>>>()\nexport const rawMultiParentSet = new WeakSet<object>()\nexport const rawPathMap = new WeakMap<object, string>()\nexport const rootPatchNodesMap = new WeakMap<object, Set<object>>()\n\nfunction getRootPatchNodes(root: object) {\n let nodes = rootPatchNodesMap.get(root)\n if (!nodes) {\n nodes = new Set()\n rootPatchNodesMap.set(root, nodes)\n }\n return nodes\n}\n\nexport function indexPatchNode(root: object, node: object) {\n getRootPatchNodes(root).add(node)\n}\n\nexport function bumpRawVersion(target: object) {\n rawVersionMap.set(target, (rawVersionMap.get(target) ?? 0) + 1)\n}\n\nexport function getRawVersion(target: object) {\n return rawVersionMap.get(target) ?? 0\n}\n\n/**\n * 将尚未归属父状态树的响应式节点接入父级根节点。\n * @internal\n */\nexport function adoptReactiveRoot(child: object, parent: object) {\n const parentRoot = rawRootMap.get(parent) ?? parent\n const existingRoot = rawRootMap.get(child)\n if (!existingRoot || existingRoot === child || existingRoot === parent) {\n rawRootMap.set(child, parentRoot)\n }\n}\n\nexport function bumpAncestorVersions(target: object) {\n const visited = new Set<object>()\n const stack: object[] = [target]\n for (let i = 0; i < 2000 && stack.length; i++) {\n const current = stack.pop()!\n const parents = rawParentsMap.get(current)\n if (!parents) {\n continue\n }\n for (const parent of parents.keys()) {\n if (visited.has(parent)) {\n continue\n }\n visited.add(parent)\n bumpRawVersion(parent)\n stack.push(parent)\n }\n }\n}\n\nfunction refreshPathUniqueness(child: object) {\n const parents = rawParentsMap.get(child)\n if (!parents) {\n rawMultiParentSet.delete(child)\n rawParentMap.delete(child)\n return\n }\n\n let uniqueParent: object | undefined\n let uniqueKey: PropertyKey | undefined\n let total = 0\n for (const [parent, keys] of parents) {\n for (const k of keys) {\n total += 1\n if (total > 1) {\n break\n }\n uniqueParent = parent\n uniqueKey = k\n }\n if (total > 1) {\n break\n }\n }\n\n if (total === 1 && uniqueParent && uniqueKey) {\n rawMultiParentSet.delete(child)\n rawParentMap.set(child, { parent: uniqueParent, key: uniqueKey })\n return\n }\n\n rawMultiParentSet.add(child)\n rawParentMap.delete(child)\n}\n\nexport function recordParentLink(child: object, parent: object, key: PropertyKey) {\n if (typeof key !== 'string') {\n rawMultiParentSet.add(child)\n rawParentMap.delete(child)\n return\n }\n\n if (mutationRecorders.size) {\n const root = rawRootMap.get(parent) ?? parent\n indexPatchNode(root, parent)\n indexPatchNode(root, child)\n }\n\n let parents = rawParentsMap.get(child)\n if (!parents) {\n parents = new Map()\n rawParentsMap.set(child, parents)\n }\n\n let keys = parents.get(parent)\n if (!keys) {\n keys = new Set()\n parents.set(parent, keys)\n }\n\n keys.add(key)\n refreshPathUniqueness(child)\n}\n\nexport function removeParentLink(child: object, parent: object, key: PropertyKey) {\n const parents = rawParentsMap.get(child)\n if (!parents) {\n return\n }\n const keys = parents.get(parent)\n if (!keys) {\n return\n }\n keys.delete(key)\n if (!keys.size) {\n parents.delete(parent)\n }\n if (!parents.size) {\n rawParentsMap.delete(child)\n }\n refreshPathUniqueness(child)\n}\n\nexport function resolvePathToTarget(root: object, target: object): string[] | undefined {\n if (target === root) {\n return []\n }\n if (rawMultiParentSet.has(target)) {\n return undefined\n }\n const segments: string[] = []\n let current: object = target\n for (let i = 0; i < 2000; i++) {\n if (current === root) {\n return segments.reverse()\n }\n if (rawMultiParentSet.has(current)) {\n return undefined\n }\n const info = rawParentMap.get(current)\n if (!info) {\n return undefined\n }\n if (typeof info.key !== 'string') {\n return undefined\n }\n segments.push(info.key)\n current = info.parent\n }\n return undefined\n}\n"],"mappings":";;;AAEA,MAAa,6BAAa,IAAI,QAAwB;AACtD,MAAa,gCAAgB,IAAI,QAAwB;AACzD,MAAa,+BAAe,IAAI,QAAsD;AACtF,MAAa,gCAAgB,IAAI,QAA+C;AAChF,MAAa,oCAAoB,IAAI,QAAgB;AACrD,MAAa,6BAAa,IAAI,QAAwB;AACtD,MAAa,oCAAoB,IAAI,QAA6B;AAElE,SAAS,kBAAkB,MAAc;CACvC,IAAI,QAAQ,kBAAkB,IAAI,IAAI;CACtC,IAAI,CAAC,OAAO;EACV,wBAAQ,IAAI,IAAI;EAChB,kBAAkB,IAAI,MAAM,KAAK;CACnC;CACA,OAAO;AACT;AAEA,SAAgB,eAAe,MAAc,MAAc;CACzD,kBAAkB,IAAI,CAAC,CAAC,IAAI,IAAI;AAClC;AAEA,SAAgB,eAAe,QAAgB;CAC7C,cAAc,IAAI,SAAS,cAAc,IAAI,MAAM,KAAK,KAAK,CAAC;AAChE;AAEA,SAAgB,cAAc,QAAgB;CAC5C,OAAO,cAAc,IAAI,MAAM,KAAK;AACtC;;;;;AAMA,SAAgB,kBAAkB,OAAe,QAAgB;CAC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,0 +1,22 @@
|
|
|
1
|
+
//#region src/reactivity/reactive/shallow.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 创建一个浅层响应式代理:仅跟踪第一层属性变更,不深度递归嵌套对象。
|
|
4
|
+
*
|
|
5
|
+
* @param target 待转换的对象
|
|
6
|
+
* @returns 浅层响应式代理
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const state = shallowReactive({ nested: { count: 0 } })
|
|
11
|
+
*
|
|
12
|
+
* state.nested.count++ // 不会触发 effect(嵌套对象未深度代理)
|
|
13
|
+
* state.nested = { count: 1 } // 会触发 effect(顶层属性变更)
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare function shallowReactive<T extends object>(target: T): T;
|
|
17
|
+
/**
|
|
18
|
+
* 判断一个值是否为 shallowReactive 创建的浅层响应式对象
|
|
19
|
+
*/
|
|
20
|
+
export declare function isShallowReactive(value: unknown): boolean;
|
|
21
|
+
//#endregion
|
|
22
|
+
//# sourceMappingURL=shallow.d.mts.map
|
|
@@ -31,8 +31,7 @@ function isArrayIndexKey(key) {
|
|
|
31
31
|
return Number.isInteger(n) && n >= 0 && String(n) === key;
|
|
32
32
|
}
|
|
33
33
|
function toRaw(observed) {
|
|
34
|
-
|
|
35
|
-
return (_ReactiveFlags$RAW = observed === null || observed === void 0 ? void 0 : observed["__r_raw"]) !== null && _ReactiveFlags$RAW !== void 0 ? _ReactiveFlags$RAW : observed;
|
|
34
|
+
return observed?.["__r_raw"] ?? observed;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
37
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.mjs","names":[],"sources":["../../../../src/reactivity/reactive/shared.ts"],"sourcesContent":["export enum ReactiveFlags {\n IS_REACTIVE = '__r_isReactive',\n IS_READONLY = '__r_isReadonly',\n RAW = '__r_raw',\n SKIP = '__r_skip', // 标记此对象无需转换为响应式(用于 markRaw)\n}\n\nexport enum TargetType {\n INVALID = 0,\n COMMON = 1,\n}\n\nexport function isObject(value: unknown): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function hasOwn(source: object, key: PropertyKey) {\n return Object.prototype.hasOwnProperty.call(source, key)\n}\n\nexport function toRawType(value: unknown) {\n return Object.prototype.toString.call(value).slice(8, -1)\n}\n\nfunction targetTypeMap(rawType: string) {\n switch (rawType) {\n case 'Object':\n case 'Array':\n return TargetType.COMMON\n case 'Map':\n case 'Set':\n case 'WeakMap':\n case 'WeakSet':\n // TODO: 后续如需支持集合响应式,需要引入专门的 collection handlers。\n return TargetType.INVALID\n default:\n return TargetType.INVALID\n }\n}\n\nexport function getTargetType(value: object) {\n return (value as any)[ReactiveFlags.SKIP]\n ? TargetType.INVALID\n : targetTypeMap(toRawType(value))\n}\n\n// 版本键(VERSION_KEY)表示“任意字段发生变化”,用于订阅整体版本避免深度遍历跟踪\nexport const VERSION_KEY: unique symbol = Symbol('wevu.version')\n\nexport function isArrayIndexKey(key: string) {\n if (!key) {\n return false\n }\n const code0 = key.charCodeAt(0)\n if (code0 < 48 || code0 > 57) {\n return false\n }\n const n = Number(key)\n return Number.isInteger(n) && n >= 0 && String(n) === key\n}\n\nexport function toRaw<T>(observed: T): T {\n return ((observed as any)?.[ReactiveFlags.RAW] ?? observed) as T\n}\n"],"mappings":";AAYA,SAAgB,SAAS,OAAiC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAgB,OAAO,QAAgB,KAAkB;CACvD,OAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,GAAG;AACzD;AAEA,SAAgB,UAAU,OAAgB;CACxC,OAAO,OAAO,UAAU,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,EAAE;AAC1D;AAEA,SAAS,cAAc,SAAiB;CACtC,QAAQ,SAAR;EACE,KAAK;EACL,KAAK,SACH;EACF,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WAEH;EACF,SACE;CACJ;AACF;AAEA,SAAgB,cAAc,OAAe;CAC3C,OAAQ,wBAEJ,cAAc,UAAU,KAAK,CAAC;AACpC;AAGA,MAAa,cAA6B,OAAO,cAAc;AAE/D,SAAgB,gBAAgB,KAAa;CAC3C,IAAI,CAAC,KACH,OAAO;CAET,MAAM,QAAQ,IAAI,WAAW,CAAC;CAC9B,IAAI,QAAQ,MAAM,QAAQ,IACxB,OAAO;CAET,MAAM,IAAI,OAAO,GAAG;CACpB,OAAO,OAAO,UAAU,CAAC,KAAK,KAAK,KAAK,OAAO,CAAC,MAAM;AACxD;AAEA,SAAgB,MAAS,UAAgB
|
|
1
|
+
{"version":3,"file":"shared.mjs","names":[],"sources":["../../../../src/reactivity/reactive/shared.ts"],"sourcesContent":["export enum ReactiveFlags {\n IS_REACTIVE = '__r_isReactive',\n IS_READONLY = '__r_isReadonly',\n RAW = '__r_raw',\n SKIP = '__r_skip', // 标记此对象无需转换为响应式(用于 markRaw)\n}\n\nexport enum TargetType {\n INVALID = 0,\n COMMON = 1,\n}\n\nexport function isObject(value: unknown): value is object {\n return typeof value === 'object' && value !== null\n}\n\nexport function hasOwn(source: object, key: PropertyKey) {\n return Object.prototype.hasOwnProperty.call(source, key)\n}\n\nexport function toRawType(value: unknown) {\n return Object.prototype.toString.call(value).slice(8, -1)\n}\n\nfunction targetTypeMap(rawType: string) {\n switch (rawType) {\n case 'Object':\n case 'Array':\n return TargetType.COMMON\n case 'Map':\n case 'Set':\n case 'WeakMap':\n case 'WeakSet':\n // TODO: 后续如需支持集合响应式,需要引入专门的 collection handlers。\n return TargetType.INVALID\n default:\n return TargetType.INVALID\n }\n}\n\nexport function getTargetType(value: object) {\n return (value as any)[ReactiveFlags.SKIP]\n ? TargetType.INVALID\n : targetTypeMap(toRawType(value))\n}\n\n// 版本键(VERSION_KEY)表示“任意字段发生变化”,用于订阅整体版本避免深度遍历跟踪\nexport const VERSION_KEY: unique symbol = Symbol('wevu.version')\n\nexport function isArrayIndexKey(key: string) {\n if (!key) {\n return false\n }\n const code0 = key.charCodeAt(0)\n if (code0 < 48 || code0 > 57) {\n return false\n }\n const n = Number(key)\n return Number.isInteger(n) && n >= 0 && String(n) === key\n}\n\nexport function toRaw<T>(observed: T): T {\n return ((observed as any)?.[ReactiveFlags.RAW] ?? observed) as T\n}\n"],"mappings":";AAYA,SAAgB,SAAS,OAAiC;CACxD,OAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAEA,SAAgB,OAAO,QAAgB,KAAkB;CACvD,OAAO,OAAO,UAAU,eAAe,KAAK,QAAQ,GAAG;AACzD;AAEA,SAAgB,UAAU,OAAgB;CACxC,OAAO,OAAO,UAAU,SAAS,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,EAAE;AAC1D;AAEA,SAAS,cAAc,SAAiB;CACtC,QAAQ,SAAR;EACE,KAAK;EACL,KAAK,SACH;EACF,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,WAEH;EACF,SACE;CACJ;AACF;AAEA,SAAgB,cAAc,OAAe;CAC3C,OAAQ,wBAEJ,cAAc,UAAU,KAAK,CAAC;AACpC;AAGA,MAAa,cAA6B,OAAO,cAAc;AAE/D,SAAgB,gBAAgB,KAAa;CAC3C,IAAI,CAAC,KACH,OAAO;CAET,MAAM,QAAQ,IAAI,WAAW,CAAC;CAC9B,IAAI,QAAQ,MAAM,QAAQ,IACxB,OAAO;CAET,MAAM,IAAI,OAAO,GAAG;CACpB,OAAO,OAAO,UAAU,CAAC,KAAK,KAAK,KAAK,OAAO,CAAC,MAAM;AACxD;AAEA,SAAgB,MAAS,UAAgB;CACvC,OAAS,yBAAyC;AACpD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { MutationKind, MutationOp, MutationRecord, addMutationRecorder, removeMutationRecorder } from "./reactive/mutation.mjs";
|
|
2
|
+
import { PrelinkReactiveTreeOptions, prelinkReactiveTree, touchReactive } from "./reactive/patch.mjs";
|
|
3
|
+
import { isShallowReactive, shallowReactive } from "./reactive/shallow.mjs";
|
|
4
|
+
import { toRaw } from "./reactive/shared.mjs";
|
|
5
|
+
//#region src/reactivity/reactive.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* 读取响应式版本号(框架内部调试能力)。
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare function getReactiveVersion(target: object): number;
|
|
11
|
+
export declare function reactive<T extends object>(target: T): T;
|
|
12
|
+
export declare function isReactive(value: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* 标记对象为“原始”状态,后续不会被转换为响应式,返回原对象本身。
|
|
15
|
+
*
|
|
16
|
+
* @param value 需要标记的对象
|
|
17
|
+
* @returns 带有跳过标记的原对象
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const foo = markRaw({
|
|
22
|
+
* nested: {}
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* const state = reactive({
|
|
26
|
+
* foo
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* state.foo // 不是响应式对象
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function markRaw<T extends object>(value: T): T;
|
|
33
|
+
/**
|
|
34
|
+
* 判断某个值是否被标记为原始(即不应转换为响应式)。
|
|
35
|
+
*
|
|
36
|
+
* @param value 待检测的值
|
|
37
|
+
* @returns 若含有跳过标记则返回 true
|
|
38
|
+
*/
|
|
39
|
+
export declare function isRaw(value: unknown): boolean;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { type MutationKind, type MutationOp, type MutationRecord, type PrelinkReactiveTreeOptions, addMutationRecorder, isShallowReactive, prelinkReactiveTree, removeMutationRecorder, shallowReactive, toRaw, touchReactive };
|
|
42
|
+
//# sourceMappingURL=reactive.d.mts.map
|
|
@@ -16,25 +16,22 @@ function getReactiveVersion(target) {
|
|
|
16
16
|
return getRawVersion(raw);
|
|
17
17
|
}
|
|
18
18
|
function emitMutation(target, key, op) {
|
|
19
|
-
var _rawRootMap$get;
|
|
20
19
|
if (!mutationRecorders.size) return;
|
|
21
20
|
if (typeof key !== "string") return;
|
|
22
21
|
if (key.startsWith("__r_")) return;
|
|
23
|
-
const root =
|
|
22
|
+
const root = rawRootMap.get(target) ?? target;
|
|
24
23
|
const kind = Array.isArray(target) && (key === "length" || isArrayIndexKey(key)) ? "array" : "property";
|
|
25
24
|
const baseSegments = resolvePathToTarget(root, target);
|
|
26
25
|
if (!baseSegments) {
|
|
27
26
|
const fallback = /* @__PURE__ */ new Set();
|
|
28
27
|
const parents = rawParentsMap.get(target);
|
|
29
28
|
if (parents) for (const [parent, keys] of parents) {
|
|
30
|
-
var _resolvePathToTarget;
|
|
31
29
|
const parentPath = rawPathMap.get(parent);
|
|
32
30
|
const topFromParentPath = parentPath ? parentPath.split(".", 1)[0] : void 0;
|
|
33
|
-
const topFromResolve = !topFromParentPath ?
|
|
31
|
+
const topFromResolve = !topFromParentPath ? resolvePathToTarget(root, parent)?.[0] : void 0;
|
|
34
32
|
for (const k of keys) {
|
|
35
|
-
var _ref;
|
|
36
33
|
if (typeof k !== "string") continue;
|
|
37
|
-
fallback.add(
|
|
34
|
+
fallback.add(topFromParentPath ?? topFromResolve ?? k);
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
37
|
else fallback.add(key);
|
|
@@ -74,9 +71,8 @@ const mutableHandlers = {
|
|
|
74
71
|
const res = Reflect.get(target, key, receiver);
|
|
75
72
|
track(target, key);
|
|
76
73
|
if (isObject(res)) {
|
|
77
|
-
var _ReactiveFlags$RAW;
|
|
78
74
|
if (res["__r_skip"]) return res;
|
|
79
|
-
const childRaw =
|
|
75
|
+
const childRaw = res?.["__r_raw"] ?? res;
|
|
80
76
|
adoptReactiveRoot(childRaw, target);
|
|
81
77
|
recordParentLink(childRaw, target, key);
|
|
82
78
|
const parentPath = rawPathMap.get(target);
|
|
@@ -132,8 +128,7 @@ const mutableHandlers = {
|
|
|
132
128
|
const oldValue = hadKey ? target[key] : void 0;
|
|
133
129
|
const result = Reflect.deleteProperty(target, key);
|
|
134
130
|
if (hadKey && result) {
|
|
135
|
-
|
|
136
|
-
const oldRaw = isObject(oldValue) ? (_ReactiveFlags$RAW2 = oldValue === null || oldValue === void 0 ? void 0 : oldValue["__r_raw"]) !== null && _ReactiveFlags$RAW2 !== void 0 ? _ReactiveFlags$RAW2 : oldValue : void 0;
|
|
131
|
+
const oldRaw = isObject(oldValue) ? oldValue?.["__r_raw"] ?? oldValue : void 0;
|
|
137
132
|
if (oldRaw) removeParentLink(oldRaw, target, key);
|
|
138
133
|
batch(() => {
|
|
139
134
|
trigger(target, key);
|