Skip to content

Script refs #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Repair en
  • Loading branch information
cereschen committed Sep 27, 2020
commit ab8e0c0d0151dc3834267b971fb8eca61bf2f92f
9 changes: 5 additions & 4 deletions active-rfcs/0000-sfc-script-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 `<script refs>`.
If you need to define original ref, you can still use Composition API in `<script refs>`.

```html
<script lang="ts" refs>
Expand All @@ -99,7 +100,7 @@ function baz(val: Ref<number>) { ... }
</script>
```

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
<script refs>
Expand Down