From 7624e9a52f6e8fe8b14f689d46801d895465dc5d Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 19:27:18 +0800 Subject: [PATCH 01/13] Create 0000-sfc-script-no-ref.md --- active-rfcs/0000-sfc-script-no-ref.md | 126 ++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 active-rfcs/0000-sfc-script-no-ref.md diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md new file mode 100644 index 00000000..2b4cdd27 --- /dev/null +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -0,0 +1,126 @@ +- Start Date: 2020-09-24 +- Target Major Version: 3.x +- Reference Issues: N/A +- Implementation PR: N/A + +# Summary + +TODO + +# Basic example + +```html + +``` + +# Motivation + +TODO + +# Detailed design + +TODO + +## Use with ` +``` + +
+Result + +```html + +``` +
+ +## Multi-line computed + +```html + +``` + +
+Result + +```html + +``` +
+ +## Don't transform + +```html + +``` + +
+Result + +```html + +``` +
+ +# Drawbacks + +TODO + +# Adoption strategy + +TODO From 5b18ce1246cef684bdd614360e3bd5abc62f3423 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 19:33:51 +0800 Subject: [PATCH 02/13] Remove setup attr in multi-line computed sample --- active-rfcs/0000-sfc-script-no-ref.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index 2b4cdd27..b2aa034c 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -65,7 +65,7 @@ export const baz = computed(() => foo.value + bar) ## Multi-line computed ```html - ``` +
+Result + +```html + ``` @@ -59,19 +81,19 @@ import { ref, computed } from 'vue' export let foo = ref(1) export let bar = 2 -export const baz = computed(() => foo.value + bar) +export let baz = computed(() => foo.value + bar) ```
## Multi-line computed -為了讓Language Service為`baz`獲取正確的類型,多行computed需要使用IIFE。 +為了讓Language Service為`// @computed`獲取正確的類型,多行computed需要定義為IIFE。 ```html ``` @@ -119,15 +141,55 @@ const baz = (foo) import { ref } from 'vue' let foo = ref(1) -const bar = foo.value -const baz = foo +let bar = foo.value +let baz = foo + +``` + + +對於屬性缺省的情況編譯器不會進行轉換,因此setup()可以使用屬性缺省或`()`兩種方式return ref物件。 + +```html + +``` + +
+Result + +```html + ```
# Drawbacks -TODO +編譯器實現可能很複雜 # Adoption strategy From 18e63878068ffbacf3bc0b8fbfa3420c77c48129 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 22:01:04 +0800 Subject: [PATCH 05/13] Make transform let/const correct --- active-rfcs/0000-sfc-script-no-ref.md | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index 27412379..7825ca65 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -18,7 +18,7 @@ export default { setup() { let count = 0 // @ref - let inc = () => count++ + const inc = () => count++ return { count, @@ -38,8 +38,8 @@ import { ref } from 'vue' export default { setup() { - let count = ref(0) - let inc = () => count.value++ + const count = ref(0) + const inc = () => count.value++ return { count, @@ -68,7 +68,7 @@ TODO ``` @@ -79,9 +79,9 @@ export let baz = foo + bar // @computed ``` @@ -93,9 +93,9 @@ export let baz = computed(() => foo.value + bar) ```html @@ -174,8 +174,8 @@ import { ref } from 'vue' export default { setup() { - let foo1 = ref(1) - let foo2 = ref(2) + const foo1 = ref(1) + const foo2 = ref(2) return { foo1, From f3015d309e65a22338c724dbdf5b3471f8851fa8 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 22:06:44 +0800 Subject: [PATCH 06/13] Add TypeScript sample --- active-rfcs/0000-sfc-script-no-ref.md | 91 +++++++++++++++++---------- 1 file changed, 58 insertions(+), 33 deletions(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index 7825ca65..adb5c158 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -86,39 +86,6 @@ export const baz = computed(() => foo.value + bar) ``` -## Multi-line computed - -為了讓Language Service為`// @computed`獲取正確的類型,多行computed需要定義為IIFE。 - -```html - -``` - -
-Result - -```html - -``` -
- ## Don't transform 某些情況下需要使用取得ref物件本身而非`.value`,例如在setup() return的時候。 @@ -187,6 +154,64 @@ export default { ``` +# TypeScript + +`no-ref`物件可以像一般變量一樣定義類型 + +```html + +``` + +
+Result + +```html + +``` +
+ + +## Multi-line computed + +為了讓Language Service為`// @computed`獲取正確的類型,多行computed需要定義為IIFE。 + +```html + +``` + +
+Result + +```html + +``` +
+ # Drawbacks 編譯器實現可能很複雜 From 9311f51fc84d48efacc657aec113c4c2e4c16664 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 22:10:32 +0800 Subject: [PATCH 07/13] Fixed TypeScript sample header level --- active-rfcs/0000-sfc-script-no-ref.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index adb5c158..0343b451 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -154,7 +154,7 @@ export default { ``` -# TypeScript +## TypeScript `no-ref`物件可以像一般變量一樣定義類型 From 10063bbd5c440f21100de7e8366340fb4a336d99 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 22:14:12 +0800 Subject: [PATCH 08/13] Update Multi-line computed sample --- active-rfcs/0000-sfc-script-no-ref.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index 0343b451..eeeedc34 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -185,10 +185,10 @@ const bar = computed(() => foo.value) ```html From 58ad9380fb5630918eb3500cd88db8925c162e15 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 23:03:42 +0800 Subject: [PATCH 09/13] Added Adoption strategy --- active-rfcs/0000-sfc-script-no-ref.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index eeeedc34..d9d36db7 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -218,4 +218,4 @@ console.log(baz.value); # Adoption strategy -TODO +這是可選及向後兼容的新功能 From 8463999717ab31da80e41f89f2c649eb690bc163 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 23:31:48 +0800 Subject: [PATCH 10/13] Added Motivation --- active-rfcs/0000-sfc-script-no-ref.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index d9d36db7..0814bead 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -52,7 +52,9 @@ export default { # Motivation -TODO +通常編寫代碼時,我們預期不需要`.value`來存取變量,`.value`的存取方式對用戶沒有額外好處。`.value`的特性也導致非ref變量與ref物件一起使用時,容易出現代碼看起來較混亂的情況。 + +`.value`是ref物件的統一特性,因此我們認為可以利用編譯器將這個特性抺除,同時可以保留響應功能。 # Detailed design From 072288d619a5fd6001e417fbb1012d10561ed6f3 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Thu, 24 Sep 2020 23:37:13 +0800 Subject: [PATCH 11/13] Fixed Basic example --- active-rfcs/0000-sfc-script-no-ref.md | 1 + 1 file changed, 1 insertion(+) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index 0814bead..823ffc3a 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -47,6 +47,7 @@ export default { } }, } + ``` From 956e74288552b699dafd83f0706430f86c11e0fb Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Fri, 25 Sep 2020 00:25:45 +0800 Subject: [PATCH 12/13] Add English version --- active-rfcs/0000-sfc-script-no-ref.md | 32 ++-- active-rfcs/0000-sfc-script-no-ref.zh.md | 224 +++++++++++++++++++++++ 2 files changed, 240 insertions(+), 16 deletions(-) create mode 100644 active-rfcs/0000-sfc-script-no-ref.zh.md diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index 823ffc3a..abc86a3b 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -5,11 +5,11 @@ # Summary -` +``` + +
+編譯結果 + +```html + +``` +
+ +# Motivation + +通常編寫代碼時,我們預期不需要`.value`來存取變量,`.value`的存取方式對用戶沒有額外好處。`.value`的特性也導致非ref變量與ref物件一起使用時,容易出現代碼看起來較混亂的情況。 + +`.value`是ref物件的統一特性,因此我們認為可以利用編譯器將這個特性抺除,同時可以保留響應功能。 + +# Detailed design + +將script標籤改更為` +``` + +
+編譯結果 + +```html + +``` +
+ +## Don't transform + +某些情況下需要使用取得ref物件本身而非`.value`,例如在setup() return的時候。 + +這種情況可以以小括號`()`包裏`no-ref`物件,編譯器會移除`no-ref`物件外的`()`,並抵削一次轉換操作。 + +```html + +``` + +
+編譯結果 + +```html + +``` +
+ +對於屬性缺省的情況編譯器不會進行轉換,因此setup()可以使用屬性缺省或`()`兩種方式return ref物件。 + +```html + +``` + +
+編譯結果 + +```html + +``` +
+ +## TypeScript + +`no-ref`物件可以像一般變量一樣定義類型。 + +```html + +``` + +
+編譯結果 + +```html + +``` +
+ + +## Multi-line computed + +為了讓Language Service為`// @computed`獲取正確的類型,多行computed需要定義為IIFE。 + +```html + +``` + +
+編譯結果 + +```html + +``` +
+ +# Drawbacks + +編譯器實現可能很複雜 + +# Adoption strategy + +這是可選及向後兼容的新功能 From 557b87c589dfae49ee93cacb2248462af32df24d Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Fri, 25 Sep 2020 15:57:52 +0800 Subject: [PATCH 13/13] Remove `()` feature --- active-rfcs/0000-sfc-script-no-ref.md | 50 +++++++++++++----------- active-rfcs/0000-sfc-script-no-ref.zh.md | 50 +++++++++++++----------- 2 files changed, 56 insertions(+), 44 deletions(-) diff --git a/active-rfcs/0000-sfc-script-no-ref.md b/active-rfcs/0000-sfc-script-no-ref.md index abc86a3b..86a4ddbf 100644 --- a/active-rfcs/0000-sfc-script-no-ref.md +++ b/active-rfcs/0000-sfc-script-no-ref.md @@ -91,15 +91,21 @@ export const baz = computed(() => foo.value + bar) ## Don't transform -In some cases, it is necessary to use the ref object itself instead of `.value`, such as when setting up () return. +> To reduce magic, the `()` feature has been removed -In this case, the `no-ref` object in the parentheses `()` package can be used. The compiler will remove the `()` outside the `no-ref` object and eliminate a conversion operation. +If you need to reference ref objects, you can still use the Composition API in the `no-ref` script. ```html - ``` @@ -107,28 +113,30 @@ let baz = (foo) Result ```html - ``` -In the case of attribute defaults, the compiler will not perform conversion, so setup() can use attribute defaults or `()` to return ref objects. +For attribute less case, the compiler will not perform conversion, so setup() can use the original method to return ref objects. ```html ``` @@ -194,7 +200,7 @@ let bar = 2 // @ref const baz = (() => { return foo + bar })() -console.log(baz); +console.log(baz) ``` @@ -210,7 +216,7 @@ const bar = ref(2) const baz = computed(() => { return foo.value + bar.value }) -console.log(baz.value); +console.log(baz.value) ``` diff --git a/active-rfcs/0000-sfc-script-no-ref.zh.md b/active-rfcs/0000-sfc-script-no-ref.zh.md index d41327dd..e3a21a9b 100644 --- a/active-rfcs/0000-sfc-script-no-ref.zh.md +++ b/active-rfcs/0000-sfc-script-no-ref.zh.md @@ -91,15 +91,21 @@ export const baz = computed(() => foo.value + bar) ## Don't transform -某些情況下需要使用取得ref物件本身而非`.value`,例如在setup() return的時候。 +> 為了減少魔法,已經移除抵銷轉換的`()`特性 -這種情況可以以小括號`()`包裏`no-ref`物件,編譯器會移除`no-ref`物件外的`()`,並抵削一次轉換操作。 +如果需要引用ref物件,仍然可以在`no-ref` script中使用Composition API。 ```html - ``` @@ -107,28 +113,30 @@ let baz = (foo) 編譯結果 ```html - ``` -對於屬性缺省的情況編譯器不會進行轉換,因此setup()可以使用屬性缺省或`()`兩種方式return ref物件。 +對於屬性缺省編譯器不會進行轉換,因此setup()可以使用原本的方式return ref物件。 ```html ``` @@ -194,7 +200,7 @@ let bar = 2 // @ref const baz = (() => { return foo + bar })() -console.log(baz); +console.log(baz) ``` @@ -210,7 +216,7 @@ const bar = ref(2) const baz = computed(() => { return foo.value + bar.value }) -console.log(baz.value); +console.log(baz.value) ```