Skip to content

Commit 5cab469

Browse files
committed
exact matched to vue-next
1 parent a06a1b8 commit 5cab469

File tree

3 files changed

+189
-1101
lines changed

3 files changed

+189
-1101
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"cross-env": "^7.0.2",
4343
"husky": "^4.2.5",
4444
"jest": "^26.0.1",
45+
"jest-cli": "^26.0.1",
4546
"lint-staged": "^10.2.7",
4647
"prettier": "^2.0.5",
4748
"rollup": "^2.12.0",

src/reactivity/ref.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Data } from '../component';
22
import { RefKey } from '../symbols';
33
import { proxy, isPlainObject, warn } from '../utils';
4-
import { HasDefined } from '../types/basic';
54
import { reactive, isReactive, shallowReactive } from './reactive';
65
import { ComputedRef } from '../apis/computed';
76

@@ -79,26 +78,10 @@ export function createRef<T>(options: RefOption<T>) {
7978
return Object.seal(new RefImpl<T>(options));
8079
}
8180

82-
type RefValue<T> = T extends Ref<infer V> ? V : UnwrapRef<T>;
83-
84-
export function ref<T extends object>(value: T): T extends Ref ? T : Ref<UnwrapRef<T>>;
85-
export function ref<T>(value: T): Ref<UnwrapRef<T>>;
86-
// without init value, explicit typed: a = ref<{ a: number }>()
87-
// typeof a will be Ref<{ a: number } | undefined>
81+
export function ref<T extends object>(raw: T): T extends Ref ? T : Ref<UnwrapRef<T>>;
82+
export function ref<T>(raw: T): Ref<UnwrapRef<T>>;
8883
export function ref<T = any>(): Ref<T | undefined>;
89-
// with null as init value: a = ref<{ a: number }>(null);
90-
// typeof a will be Ref<{ a: number } | null>
91-
export function ref<T = null>(raw: null): Ref<T | null>;
92-
// with init value: a = ref({ a: ref(0) })
93-
// typeof a will be Ref<{ a: number }>
94-
export function ref<S, T = unknown, R = HasDefined<S> extends true ? S : RefValue<T>>(
95-
raw: T
96-
): Ref<R>;
97-
// implementation
98-
export function ref(raw?: any): any {
99-
// if (isRef(raw)) {
100-
// return {} as any;
101-
// }
84+
export function ref(raw?: unknown) {
10285
if (isRef(raw)) {
10386
return raw;
10487
}

0 commit comments

Comments
 (0)