From fd5e95222930e86fb88d3f29121e43eaa7dadd71 Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Sun, 27 Sep 2020 19:42:18 +0800 Subject: [PATCH 1/2] Create 0000-sfc-script-refs.md --- active-rfcs/0000-sfc-script-refs.md | 195 ++++++++++++++++++++++++ active-rfcs/0000-sfc-script-refs.zh.md | 196 +++++++++++++++++++++++++ 2 files changed, 391 insertions(+) create mode 100644 active-rfcs/0000-sfc-script-refs.md create mode 100644 active-rfcs/0000-sfc-script-refs.zh.md diff --git a/active-rfcs/0000-sfc-script-refs.md b/active-rfcs/0000-sfc-script-refs.md new file mode 100644 index 00000000..10619aa4 --- /dev/null +++ b/active-rfcs/0000-sfc-script-refs.md @@ -0,0 +1,195 @@ +- Start Date: 2020-09-27 +- Target Major Version: 3.x +- Reference Issues: N/A +- Implementation PR: N/A + +# Summary + +` +``` + +Result: + +```html + +``` + +# Motivation + +Usually when writing code, we expect that `.value` is not needed to access variables, and the access method of `.value` has no additional benefit to users. The characteristics of `.value` also cause the code to look messy when non-ref variables are used with ref objects. + +`.value` is a unified feature of ref objects, so we think we can use the compiler to remove this feature while retaining the response function. + +# Detailed design + +Change the script tag to ` +``` + +Result: + +```html + +``` + +## Don't transform + +If you need to reference ref objects, you can still use Composition API in ` +``` + +For attributes, the compiler will not perform conversion by default, so setup() can use the original method to return ref objects. + +```html + +``` + +Result: + +```html + +``` + +## TypeScript + +The type of `refs` objects can be defined like general variables. + +```html + +``` + +Result: + +```html + +``` + +## Multi-line computed + +In order for Language Service to obtain the correct type, multi-line computed needs to be defined as IIFE. + +```html + +``` + +Result: + +```html + +``` + +# Drawbacks + +- Compiler implementation can be complicated +- Language Service requires additional support + +# Adoption strategy + +This is an optional and backward compatible new feature diff --git a/active-rfcs/0000-sfc-script-refs.zh.md b/active-rfcs/0000-sfc-script-refs.zh.md new file mode 100644 index 00000000..997c8135 --- /dev/null +++ b/active-rfcs/0000-sfc-script-refs.zh.md @@ -0,0 +1,196 @@ +- Start Date: 2020-09-27 +- Target Major Version: 3.x +- Reference Issues: N/A +- Implementation PR: N/A + +# Summary + +` +``` + +編譯結果: + +```html + +``` + +# Motivation + +通常編寫代碼時,我們預期不需要`.value`來存取變量,`.value`的存取方式對用戶沒有額外好處。`.value`的特性也導致非ref變量與ref物件一起使用時,容易出現代碼看起來較混亂的情況。 + +`.value`是ref物件的統一特性,因此我們認為可以利用編譯器將這個特性抺除,同時可以保留響應功能。 + +# Detailed design + +將script標籤改更為` +``` + +編譯結果: + +```html + +``` + +## Don't transform + +如果需要引用ref物件,仍然可以在` +``` + +對於屬性缺省編譯器不會進行轉換,因此setup()可以使用原本的方式return ref物件。 + +```html + +``` + +編譯結果: + +```html + +``` + +## TypeScript + +`refs`物件可以像一般變量一樣定義類型。 + +```html + +``` + +編譯結果: + +```html + +``` + +## Multi-line computed + +為了讓Language Service獲取正確的類型,多行computed需要定義為IIFE。 + +```html + +``` + +編譯結果: + +```html + +``` + +# Drawbacks + +編譯器實現可能很複雜 + +Language Service需要額外支持 + +# Adoption strategy + +這是可選及向後兼容的新功能 From ab8e0c0d0151dc3834267b971fb8eca61bf2f92f Mon Sep 17 00:00:00 2001 From: cereschen <491191796@qq.com> Date: Sun, 27 Sep 2020 22:43:13 +0800 Subject: [PATCH 2/2] Repair en --- active-rfcs/0000-sfc-script-refs.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/active-rfcs/0000-sfc-script-refs.md b/active-rfcs/0000-sfc-script-refs.md index 10619aa4..2375c589 100644 --- a/active-rfcs/0000-sfc-script-refs.md +++ b/active-rfcs/0000-sfc-script-refs.md @@ -47,9 +47,10 @@ export default { # Motivation -Usually when writing code, we expect that `.value` is not needed to access variables, and the access method of `.value` has no additional benefit to users. The characteristics of `.value` also cause the code to look messy when non-ref variables are used with ref objects. +Usually when writing code, somebody don't want to write `.value`, and we don't need to access properties other than `value` most time. +Although it's quite right to write `. value`, it's not elegant. -`.value` is a unified feature of ref objects, so we think we can use the compiler to remove this feature while retaining the response function. +So i think we can use the compiler to add `.value` `ref()` while we don't need to write them. # Detailed design @@ -83,7 +84,7 @@ export const baz = computed(() => foo.value + bar) ## Don't transform -If you need to reference ref objects, you can still use Composition API in ` ``` -For attributes, the compiler will not perform conversion by default, so setup() can use the original method to return ref objects. +Setup()'s return statement can write as before,references in there will not be transformed. ```html