]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(reactivity-transform/types): restructure macro types + export types for all...
authorEvan You <yyx990803@gmail.com>
Sat, 11 Dec 2021 10:15:44 +0000 (18:15 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 11 Dec 2021 10:15:44 +0000 (18:15 +0800)
packages/reactivity/src/index.ts
packages/reactivity/src/ref.ts
packages/runtime-core/src/index.ts
packages/vue/macros-global.d.ts [new file with mode: 0644]
packages/vue/macros.d.ts [new file with mode: 0644]
packages/vue/package.json
packages/vue/ref-macros.d.ts

index c61999bd6f39a82efa28772313bf6a97e753053c..676f8598fb3f96b63ea6639be93fd66392b4f669 100644 (file)
@@ -14,7 +14,8 @@ export {
   UnwrapRef,
   ShallowRef,
   ShallowUnwrapRef,
-  RefUnwrapBailTypes
+  RefUnwrapBailTypes,
+  CustomRefFactory
 } from './ref'
 export {
   reactive,
index 66c3dd439828563ace870f5e02721d16c797042c..55059485d6cb6fe80b9070c2d57857a6d04c1740 100644 (file)
@@ -151,7 +151,7 @@ export function proxyRefs<T extends object>(
     : new Proxy(objectWithRefs, shallowUnwrapHandlers)
 }
 
-type CustomRefFactory<T> = (
+export type CustomRefFactory<T> = (
   track: () => void,
   trigger: () => void
 ) => {
index ff0aeb90df4c26777bf338ab1e2107013f66da4c..63aac5ac90fd67fa9d832fbd2ca75c7c84864208 100644 (file)
@@ -151,18 +151,28 @@ export {
   Ref,
   ToRef,
   ToRefs,
-  ReactiveEffectOptions,
-  DebuggerEvent,
-  DebuggerOptions,
-  TrackOpTypes,
-  TriggerOpTypes,
-  ComputedRef,
-  WritableComputedRef,
   UnwrapRef,
+  ShallowRef,
   ShallowUnwrapRef,
-  WritableComputedOptions,
+  RefUnwrapBailTypes,
+  CustomRefFactory,
+  ReactiveFlags,
   DeepReadonly,
-  ShallowReactive
+  ShallowReactive,
+  UnwrapNestedRefs,
+  ComputedRef,
+  WritableComputedRef,
+  WritableComputedOptions,
+  ComputedGetter,
+  ComputedSetter,
+  ReactiveEffectRunner,
+  ReactiveEffectOptions,
+  EffectScheduler,
+  DebuggerOptions,
+  DebuggerEvent,
+  DebuggerEventExtraInfo,
+  TrackOpTypes,
+  TriggerOpTypes
 } from '@vue/reactivity'
 export {
   WatchEffect,
diff --git a/packages/vue/macros-global.d.ts b/packages/vue/macros-global.d.ts
new file mode 100644 (file)
index 0000000..9b6f5a5
--- /dev/null
@@ -0,0 +1,19 @@
+import {
+  $ as _$,
+  $$ as _$$,
+  $ref as _$ref,
+  $shallowRef as _$shallowRef,
+  $computed as _$computed,
+  $customRef as _$customRef,
+  $toRef as _$toRef
+} from './macros'
+
+declare global {
+  const $: typeof _$
+  const $$: typeof _$$
+  const $ref: typeof _$ref
+  const $shallowRef: typeof _$shallowRef
+  const $computed: typeof _$computed
+  const $customRef: typeof _$customRef
+  const $toRef: typeof _$toRef
+}
diff --git a/packages/vue/macros.d.ts b/packages/vue/macros.d.ts
new file mode 100644 (file)
index 0000000..a0a9f54
--- /dev/null
@@ -0,0 +1,106 @@
+import {
+  Ref,
+  UnwrapRef,
+  ComputedRef,
+  WritableComputedOptions,
+  DebuggerOptions,
+  WritableComputedRef,
+  CustomRefFactory
+} from '@vue/runtime-dom'
+
+export declare const RefType: unique symbol
+
+export declare const enum RefTypes {
+  Ref = 1,
+  ComputedRef = 2,
+  WritableComputedRef = 3
+}
+
+type RefValue<T> = T extends null | undefined
+  ? T
+  : T & { [RefType]?: RefTypes.Ref }
+
+type ComputedRefValue<T> = T extends null | undefined
+  ? T
+  : T & { [RefType]?: RefTypes.ComputedRef }
+
+type WritableComputedRefValue<T> = T extends null | undefined
+  ? T
+  : T & { [RefType]?: RefTypes.WritableComputedRef }
+
+type NormalObject<T extends object> = T & { [RefType]?: never }
+
+/**
+ * Vue ref transform macro for binding refs as reactive variables.
+ */
+export declare function $<T>(arg: ComputedRef<T>): ComputedRefValue<T>
+export declare function $<T>(
+  arg: WritableComputedRef<T>
+): WritableComputedRefValue<T>
+export declare function $<T>(arg: Ref<T>): RefValue<T>
+export declare function $<T extends object>(arg?: T): DestructureRefs<T>
+
+type DestructureRefs<T extends object> = {
+  [K in keyof T]: T[K] extends ComputedRef<infer V>
+    ? ComputedRefValue<V>
+    : T[K] extends WritableComputedRef<infer V>
+    ? WritableComputedRefValue<V>
+    : T[K] extends Ref<infer V>
+    ? RefValue<V>
+    : T[K]
+}
+
+/**
+ * Vue ref transform macro for accessing underlying refs of reactive varaibles.
+ */
+export declare function $$<T extends object>(arg: NormalObject<T>): ToRawRefs<T>
+export declare function $$<T>(value: RefValue<T>): Ref<T>
+export declare function $$<T>(value: ComputedRefValue<T>): ComputedRef<T>
+export declare function $$<T>(
+  value: WritableComputedRefValue<T>
+): WritableComputedRef<T>
+
+type ToRawRefs<T extends object> = {
+  [K in keyof T]: T[K] extends RefValue<infer V>
+    ? Ref<V>
+    : T[K] extends ComputedRefValue<infer V>
+    ? ComputedRef<V>
+    : T[K] extends WritableComputedRefValue<infer V>
+    ? WritableComputedRef<V>
+    : T[K] extends object
+    ? T[K] extends
+        | Function
+        | Map<any, any>
+        | Set<any>
+        | WeakMap<any, any>
+        | WeakSet<any>
+      ? T[K]
+      : ToRawRefs<T[K]>
+    : T[K]
+}
+
+export declare function $ref<T>(arg?: T | Ref<T>): RefValue<UnwrapRef<T>>
+
+export declare function $shallowRef<T>(arg?: T): RefValue<T>
+
+export declare function $toRef<T extends object, K extends keyof T>(
+  object: T,
+  key: K
+): RefValue<T[K]>
+
+export declare function $toRef<T extends object, K extends keyof T>(
+  object: T,
+  key: K,
+  defaultValue: T[K]
+): RefValue<Exclude<T[K], undefined>>
+
+export declare function $customRef<T>(factory: CustomRefFactory<T>): RefValue<T>
+
+export declare function $computed<T>(
+  getter: () => T,
+  debuggerOptions?: DebuggerOptions
+): ComputedRefValue<T>
+export declare function $computed<T>(
+  options: WritableComputedOptions<T>,
+  debuggerOptions?: DebuggerOptions
+): WritableComputedRefValue<T>
index 8152b511571e7c3bc0a8350a6de65bf7a7990051..a6a3606a9093a6c3876af056130e6af9091f2f33 100644 (file)
@@ -34,6 +34,8 @@
     },
     "./dist/*": "./dist/*",
     "./package.json": "./package.json",
+    "./macros": "./macros.d.ts",
+    "./macros-global": "./macros-global.d.ts",
     "./ref-macros": "./ref-macros.d.ts"
   },
   "buildOptions": {
index c38b4bad7193d24469a90e65f9a0b7be3ec0937a..6afce7f70a3035c8cdb6951174772e3b6571e93a 100644 (file)
@@ -1,98 +1,2 @@
-import {
-  Ref,
-  UnwrapRef,
-  ComputedRef,
-  WritableComputedOptions,
-  DebuggerOptions,
-  WritableComputedRef
-} from '@vue/runtime-dom'
-
-declare const RefType: unique symbol
-
-declare const enum RefTypes {
-  Ref = 1,
-  ComputedRef = 2,
-  WritableComputedRef = 3
-}
-
-type RefValue<T> = T extends null | undefined
-  ? T
-  : T & { [RefType]?: RefTypes.Ref }
-
-type ComputedRefValue<T> = T extends null | undefined
-  ? T
-  : T & { [RefType]?: RefTypes.ComputedRef }
-
-type WritableComputedRefValue<T> = T extends null | undefined
-  ? T
-  : T & { [RefType]?: RefTypes.WritableComputedRef }
-
-type NormalObject<T extends object> = T & { [RefType]?: never }
-
-/**
- * Vue ref transform macro for binding refs as reactive variables.
- */
-declare function _$<T>(arg: ComputedRef<T>): ComputedRefValue<T>
-declare function _$<T>(arg: WritableComputedRef<T>): WritableComputedRefValue<T>
-declare function _$<T>(arg: Ref<T>): RefValue<T>
-declare function _$<T extends object>(arg?: T): DestructureRefs<T>
-
-type DestructureRefs<T extends object> = {
-  [K in keyof T]: T[K] extends ComputedRef<infer V>
-    ? ComputedRefValue<V>
-    : T[K] extends WritableComputedRef<infer V>
-    ? WritableComputedRefValue<V>
-    : T[K] extends Ref<infer V>
-    ? RefValue<V>
-    : T[K]
-}
-
-/**
- * Vue ref transform macro for accessing underlying refs of reactive varaibles.
- */
-declare function _$$<T extends object>(arg: NormalObject<T>): ToRawRefs<T>
-declare function _$$<T>(value: RefValue<T>): Ref<T>
-declare function _$$<T>(value: ComputedRefValue<T>): ComputedRef<T>
-declare function _$$<T>(
-  value: WritableComputedRefValue<T>
-): WritableComputedRef<T>
-
-type ToRawRefs<T extends object> = {
-  [K in keyof T]: T[K] extends RefValue<infer V>
-    ? Ref<V>
-    : T[K] extends ComputedRefValue<infer V>
-    ? ComputedRef<V>
-    : T[K] extends WritableComputedRefValue<infer V>
-    ? WritableComputedRef<V>
-    : T[K] extends object
-    ? T[K] extends
-        | Function
-        | Map<any, any>
-        | Set<any>
-        | WeakMap<any, any>
-        | WeakSet<any>
-      ? T[K]
-      : ToRawRefs<T[K]>
-    : T[K]
-}
-
-declare function _$ref<T>(arg?: T | Ref<T>): RefValue<UnwrapRef<T>>
-
-declare function _$shallowRef<T>(arg?: T): RefValue<T>
-
-declare function _$computed<T>(
-  getter: () => T,
-  debuggerOptions?: DebuggerOptions
-): ComputedRefValue<T>
-declare function _$computed<T>(
-  options: WritableComputedOptions<T>,
-  debuggerOptions?: DebuggerOptions
-): WritableComputedRefValue<T>
-
-declare global {
-  const $: typeof _$
-  const $$: typeof _$$
-  const $ref: typeof _$ref
-  const $shallowRef: typeof _$shallowRef
-  const $computed: typeof _$computed
-}
+// TODO deprecated file - to be removed when out of experimental
+import './macros-global'