diff --git a/active-rfcs/0000-sfc-script-refs.md b/active-rfcs/0000-sfc-script-refs.md new file mode 100644 index 00000000..2375c589 --- /dev/null +++ b/active-rfcs/0000-sfc-script-refs.md @@ -0,0 +1,196 @@ +- 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, 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. + +So i think we can use the compiler to add `.value` `ref()` while we don't need to write them. + +# Detailed design + +Change the script tag to ` +``` + +Result: + +```html + +``` + +## Don't transform + +If you need to define original ref, you can still use Composition API in ` +``` + +Setup()'s return statement can write as before,references in there will not be transformed. + +```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 + +這是可選及向後兼容的新功能