Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: implement script setup suger for components
- Loading branch information
Showing
28 changed files
with
709 additions
and
1,238 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
{ | ||
"baseUrl": "https://mutoe.github.io/vue3-realworld-example-app", | ||
"experimentalNetworkStubbing": true, | ||
"chromeWebSecurity": false | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
<template> | ||
<router-link | ||
:to="to" | ||
v-bind="attrs" | ||
> | ||
<router-link :to="props" v-bind="attrs"> | ||
<slot /> | ||
</router-link> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType } from 'vue' | ||
import type { RouteParams } from 'vue-router' | ||
<script lang="ts" setup> | ||
import type { AppRouteNames } from '../router' | ||
import type { RouteParams } from 'vue-router' | ||
import { defineProps, useContext } from 'vue' | ||
export default defineComponent({ | ||
name: 'AppLink', | ||
props: { | ||
name: { type: String as PropType<AppRouteNames>, required: true }, | ||
params: { type: Object as PropType<RouteParams>, default: () => ({}) }, | ||
}, | ||
setup (props, { attrs }) { | ||
return { | ||
to: props, | ||
attrs, | ||
} | ||
}, | ||
}) | ||
const props = defineProps<{ | ||
name: AppRouteNames | ||
params?: RouteParams | ||
}>() | ||
const { attrs } = useContext() | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mutoe
I think, it would be better to implement the setup sugar (and maybe event with ref sugar) in a separate branch or repository. And leave pure Composition API in a main branch as a main way "how to write" code in .vue files
What do you think?
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@levchak0910 Yeah, what you said makes sense. Are you worried that this feature will be removed?
When we use Composition API, we will never go back to Options API, and there is no verbose boilerplate code.
So I think what we can do is to tag our previous commit.
Also, until this feature is stable, I will continue to update it to let newcomers use this pleasant feature faster :)
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using the Testing library for testing, this can be considered a new branch, It's a good idea.
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I suppose this will never happen )
This suggestion appeared because script sugar force us to write code in significantly another way. There are many changes (709+ and 1,238-) on this small code base comparatively with pure Composition API. Therefore I think to have 2 versions of codebase written with pure Composition API and suggared would be better
And to be honest, I personally don't really like the script sugar (and even more the ref sugar) and don't perceive this as an improvement
Writing tests does not affect how we write application code, so here I think it is pretty ok to have this in main branch
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My main point of view that vue gives us 2 (almost) different way, how to write code and we should show this 2 ways in 2 different branches or repos
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you are right. Let me create a branch for this sugar.
If this becomes the mainstream one day in the future(I hope π ), I think it can be shown as the main branch.
c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @mutoe!
<script setup>
is officially stable since Vue 3.2, so I think it is safe to merge<script setup>
to main now.c0c983d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your reminder. I will consider merging it to main or making main branch as default branch.