@@ -59,6 +59,28 @@ function getTargetType(value: Target) {
5959// only unwrap nested ref
6060type UnwrapNestedRefs < T > = T extends Ref ? T : UnwrapRef < T >
6161
62+ /**
63+ * Creates a reactive copy of the original object.
64+ *
65+ * The reactive conversion is "deep"—it affects all nested properties. In the
66+ * ES2015 Proxy based implementation, the returned proxy is **not** equal to the
67+ * original object. It is recommended to work exclusively with the reactive
68+ * proxy and avoid relying on the original object.
69+ *
70+ * A reactive object also automatically unwraps refs contained in it, so you
71+ * don't need to use `.value` when accessing and mutating their value:
72+ *
73+ * ```js
74+ * const count = ref(0)
75+ * const obj = reactive({
76+ * count
77+ * })
78+ *
79+ * obj.count++
80+ * obj.count // -> 1
81+ * count.value // -> 1
82+ * ```
83+ */
6284export function reactive < T extends object > ( target : T ) : UnwrapNestedRefs < T >
6385export function reactive ( target : object ) {
6486 // if trying to observe a readonly proxy, return the readonly version.
@@ -73,9 +95,11 @@ export function reactive(target: object) {
7395 )
7496}
7597
76- // Return a reactive-copy of the original object, where only the root level
77- // properties are reactive, and does NOT unwrap refs nor recursively convert
78- // returned properties.
98+ /**
99+ * Return a shallowly-reactive copy of the original object, where only the root
100+ * level properties are reactive. It also does not auto-unwrap refs (even at the
101+ * root level).
102+ */
79103export function shallowReactive < T extends object > ( target : T ) : T {
80104 return createReactiveObject (
81105 target ,
@@ -107,6 +131,10 @@ export type DeepReadonly<T> = T extends Builtin
107131 ? { readonly [ K in keyof T ] : DeepReadonly < T [ K ] > }
108132 : Readonly < T >
109133
134+ /**
135+ * Creates a readonly copy of the original object. Note the returned copy is not
136+ * made reactive, but `readonly` can be called on an already reactive object.
137+ */
110138export function readonly < T extends object > (
111139 target : T
112140) : DeepReadonly < UnwrapNestedRefs < T > > {
@@ -118,10 +146,12 @@ export function readonly<T extends object>(
118146 )
119147}
120148
121- // Return a reactive-copy of the original object, where only the root level
122- // properties are readonly, and does NOT unwrap refs nor recursively convert
123- // returned properties.
124- // This is used for creating the props proxy object for stateful components.
149+ /**
150+ * Returns a reactive-copy of the original object, where only the root level
151+ * properties are readonly, and does NOT unwrap refs nor recursively convert
152+ * returned properties.
153+ * This is used for creating the props proxy object for stateful components.
154+ */
125155export function shallowReadonly < T extends object > (
126156 target : T
127157) : Readonly < { [ K in keyof T ] : UnwrapNestedRefs < T [ K ] > } > {
0 commit comments