feat(sfc): support $shallowRef ref sugar

This commit is contained in:
Evan You
2021-08-11 10:19:58 -04:00
parent e42d7794cb
commit 00b76d3dc1
7 changed files with 46 additions and 20 deletions

View File

@@ -3,6 +3,10 @@ import { Ref, UnwrapRef, ShallowUnwrapRef, ComputedRef } from '@vue/reactivity'
export function $ref<T>(arg: T | Ref<T>): UnwrapRef<T>
export function $ref() {}
export function $shallowRef<T>(arg: T): T {
return arg
}
declare const ComputedRefMarker: unique symbol
type ComputedRefValue<T> = T & { [ComputedRefMarker]?: any }

View File

@@ -354,4 +354,10 @@ export const compatUtils = (
// Ref sugar macros ------------------------------------------------------------
// for dts generation only
export { $ref, $computed, $raw, $fromRefs } from './helpers/refSugar'
export {
$ref,
$shallowRef,
$computed,
$raw,
$fromRefs
} from './helpers/refSugar'

View File

@@ -6,6 +6,7 @@ type _defineExpose = typeof defineExpose
type _withDefaults = typeof withDefaults
type _ref = typeof $ref
type _shallowRef = typeof $shallowRef
type _computed = typeof $computed
type _fromRefs = typeof $fromRefs
type _raw = typeof $raw
@@ -17,6 +18,7 @@ declare global {
const withDefaults: _withDefaults
const $ref: _ref
const $shallowRef: _shallowRef
const $computed: _computed
const $fromRefs: _fromRefs
const $raw: _raw