]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(reactivity-transform): rename @vue/ref-transform to @vue/reactivity-transform
authorEvan You <yyx990803@gmail.com>
Sat, 11 Dec 2021 16:04:38 +0000 (00:04 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 11 Dec 2021 16:04:38 +0000 (00:04 +0800)
14 files changed:
.eslintrc.js
packages/compiler-sfc/__tests__/compileScriptRefTransform.spec.ts
packages/compiler-sfc/package.json
packages/compiler-sfc/src/compileScript.ts
packages/compiler-sfc/src/index.ts
packages/reactivity-transform/README.md [moved from packages/ref-transform/README.md with 62% similarity]
packages/reactivity-transform/__tests__/__snapshots__/refTransform.spec.ts.snap [moved from packages/ref-transform/__tests__/__snapshots__/refTransform.spec.ts.snap with 100% similarity]
packages/reactivity-transform/__tests__/refTransform.spec.ts [moved from packages/ref-transform/__tests__/refTransform.spec.ts with 100% similarity]
packages/reactivity-transform/api-extractor.json [moved from packages/ref-transform/api-extractor.json with 100% similarity]
packages/reactivity-transform/package.json [moved from packages/ref-transform/package.json with 72% similarity]
packages/reactivity-transform/src/babelPlugin.ts [moved from packages/ref-transform/src/babelPlugin.ts with 100% similarity]
packages/reactivity-transform/src/index.ts [moved from packages/ref-transform/src/index.ts with 100% similarity]
packages/reactivity-transform/src/refTransform.ts [moved from packages/ref-transform/src/refTransform.ts with 100% similarity]
test-dts/reactivityMacros.test-d.ts [moved from test-dts/refTransformMacros.test-d.ts with 100% similarity]

index ea44a000114986215f9a5888dc7aed685f523146..4c667f90216ebcebb96e020be9495a88fe7c65c9 100644 (file)
@@ -50,7 +50,7 @@ module.exports = {
     // Packages targeting Node
     {
       files: [
-        'packages/{compiler-sfc,compiler-ssr,server-renderer,ref-transform}/**'
+        'packages/{compiler-sfc,compiler-ssr,server-renderer,reactivity-transform}/**'
       ],
       rules: {
         'no-restricted-globals': ['error', ...DOMGlobals],
index d2f52589003e72adb4d118025258e4a9ec98a4b3..f6897b8038d8795a249c054d55dbf0f5bcb9c0f8 100644 (file)
@@ -2,7 +2,7 @@ import { BindingTypes } from '@vue/compiler-core'
 import { compileSFCScript as compile, assertCode } from './utils'
 
 // this file only tests integration with SFC - main test case for the ref
-// transform can be found in <root>/packages/ref-transform/__tests__
+// transform can be found in <root>/packages/reactivity-transform/__tests__
 describe('sfc ref transform', () => {
   function compileWithRefTransform(src: string) {
     return compile(src, { refTransform: true })
index 7cf10ddf2a9d11a041996ce01a325e6e2ebbe5ba..344fe77930991f7aa23f4da6f1beca85b2bdb3e4 100644 (file)
@@ -36,7 +36,7 @@
     "@vue/compiler-core": "3.2.24",
     "@vue/compiler-dom": "3.2.24",
     "@vue/compiler-ssr": "3.2.24",
-    "@vue/ref-transform": "3.2.24",
+    "@vue/reactivity-transform": "3.2.24",
     "@vue/shared": "3.2.24",
     "estree-walker": "^2.0.2",
     "magic-string": "^0.25.7",
index 1823d28cba6a05ee83a519b004a48a599b230810..9aa108118fdcdab676278f0d1e59d1a74c7db766 100644 (file)
@@ -51,7 +51,7 @@ import { createCache } from './cache'
 import {
   shouldTransform as shouldTransformRef,
   transformAST as transformRefAST
-} from '@vue/ref-transform'
+} from '@vue/reactivity-transform'
 
 // Special compiler macros
 const DEFINE_PROPS = 'defineProps'
index 1c4bb14ee6f33fdfcf447bd452d9d1486d979be2..245aa461901598b7f26982be38a3de33fadd8a56 100644 (file)
@@ -8,7 +8,7 @@ export {
   shouldTransform as shouldTransformRef,
   transform as transformRef,
   transformAST as transformRefAST
-} from '@vue/ref-transform'
+} from '@vue/reactivity-transform'
 
 // Utilities
 export { parse as babelParse } from '@babel/parser'
similarity index 62%
rename from packages/ref-transform/README.md
rename to packages/reactivity-transform/README.md
index 33948af37aa392a8e609aebfd03c64fa591a5356..92277a8b288d44066b646640f9ba2fcd09673017 100644 (file)
@@ -1,4 +1,4 @@
-# @vue/ref-transform
+# @vue/reactivity-transform
 
 > ⚠️ This is experimental and currently only provided for testing and feedback. It may break during patches or even be removed. Use at your own risk!
 >
@@ -6,32 +6,50 @@
 
 ## Basic Rules
 
-- `$()` to turn refs into reactive variables
-- `$$()` to access the original refs from reactive variables
+- Ref-creating APIs have `$`-prefixed versions that create reactive variables instead. They also do not need to be explicitly imported. These include:
+  - `ref`
+  - `computed`
+  - `shallowRef`
+  - `customRef`
+  - `toRef`
+- `$()` can be used to destructure an object into reactive variables, or turn existing refs into reactive variables
+- `$$()` to "escape" the transform, which allows access to underlying refs
 
 ```js
-import { ref, watch } from 'vue'
+import { watchEffect } from 'vue'
 
 // bind ref as a variable
-let count = $(ref(0))
+let count = $ref(0)
 
-// no need for .value
-console.log(count)
-
-// get the actual ref
-watch($$(count), c => console.log(`count changed to ${c}`))
+watchEffect(() => {
+  // no need for .value
+  console.log(count)
+})
 
 // assignments are reactive
 count++
+
+// get the actual ref
+console.log($$(count)) // { value: 1 }
+```
+
+Macros can be optionally imported to make it more explicit:
+
+```js
+// not necessary, but also works
+import { $, $ref } from 'vue/macros'
+
+let count = $ref(0)
+const { x, y } = $(useMouse())
 ```
 
-### Shorthands
+### Global Types
 
-A few commonly used APIs have shorthands (which also removes the need to import them):
+To enable types for the macros globally, include the following in a `.d.ts` file:
 
-- `$(ref(0))` -> `$ref(0)`
-- `$(computed(() => 123))` -> `$computed(() => 123)`
-- `$(shallowRef({}))` -> `$shallowRef({})`
+```ts
+/// <reference types="vue/macros-global" />
+```
 
 ## API
 
@@ -42,7 +60,7 @@ This package is the lower-level transform that can be used standalone. Higher-le
 Can be used to do a cheap check to determine whether full transform should be performed.
 
 ```js
-import { shouldTransform } from '@vue/ref-transform'
+import { shouldTransform } from '@vue/reactivity-transform'
 
 shouldTransform(`let a = ref(0)`) // false
 shouldTransform(`let a = $ref(0)`) // true
@@ -51,7 +69,7 @@ shouldTransform(`let a = $ref(0)`) // true
 ### `transform`
 
 ```js
-import { transform } from '@vue/ref-transform'
+import { transform } from '@vue/reactivity-transform'
 
 const src = `let a = $ref(0); a++`
 const {
@@ -86,7 +104,7 @@ interface RefTransformOptions {
 Transform with an existing Babel AST + MagicString instance. This is used internally by `@vue/compiler-sfc` to avoid double parse/transform cost.
 
 ```js
-import { transformAST } from '@vue/ref-transform'
+import { transformAST } from '@vue/reactivity-transform'
 import { parse } from '@babel/parser'
 import MagicString from 'magic-string'
 
similarity index 72%
rename from packages/ref-transform/package.json
rename to packages/reactivity-transform/package.json
index 50c832c583d701b666e695b429b40b066fa28f25..48c7179f57eb0be4c6d579c9eb605c7a9ce46d13 100644 (file)
@@ -1,8 +1,8 @@
 {
-  "name": "@vue/ref-transform",
+  "name": "@vue/reactivity-transform",
   "version": "3.2.24",
-  "description": "@vue/ref-transform",
-  "main": "dist/ref-transform.cjs.js",
+  "description": "@vue/reactivity-transform",
+  "main": "dist/reactivity-transform.cjs.js",
   "files": [
     "dist"
   ],
     ],
     "prod": false
   },
-  "types": "dist/ref-transform.d.ts",
+  "types": "dist/reactivity-transform.d.ts",
   "repository": {
     "type": "git",
     "url": "git+https://github.com/vuejs/vue-next.git",
-    "directory": "packages/ref-transform"
+    "directory": "packages/reactivity-transform"
   },
   "keywords": [
     "vue"
@@ -26,7 +26,7 @@
   "bugs": {
     "url": "https://github.com/vuejs/vue-next/issues"
   },
-  "homepage": "https://github.com/vuejs/vue-next/tree/dev/packages/ref-transform#readme",
+  "homepage": "https://github.com/vuejs/vue-next/tree/dev/packages/reactivity-transform#readme",
   "dependencies": {
     "@babel/parser": "^7.15.0",
     "@vue/compiler-core": "3.2.24",