-
Notifications
You must be signed in to change notification settings - Fork 546
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
SFC Improvements #182
Closed
Closed
SFC Improvements #182
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
96c72ff
sfc improvements
yyx990803 390e0a2
improve component sugar example
yyx990803 22bfdc8
fix example consistency
yyx990803 d805c9b
fix example
yyx990803 2d94fbf
fix typo
yyx990803 391a10c
make it clear let bindings are not part of the RFC
yyx990803 923348c
use export default for options
yyx990803 b1c7267
update `<script setup>` details + require setup signature via attribu…
yyx990803 3a2b0e7
update `<style vars>` proposal
yyx990803 3e0e5c8
update TS section regarding setup argument usage
yyx990803 45365a9
edit(sfc): add details on exposing components, transform API and bind…
yyx990803 6adbdbd
remove component sugar rfc
yyx990803 c0de170
update transform API example
yyx990803 e19fcb9
typo (#207)
MBearo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@yyx990803 I looked up the
BindingMetadata
typedef in compiler-core. Following types are defined:'data' | 'props' | 'setup' | 'options'
I think an additional value
A: 'import'
, forexport { A } from './a'
could lead to interesting optimizations.The compiler would then be free to reference the import directly, without reactivity and bypassing the setup state for references to
A
.That's particularly interesting for local components (or directives).
This RFC also looks for a syntax to import local components. With the ability to recognize imports (constants) and reference them directly, it doesn't need one!
If the template does
<MyButton />
and the script setup contains anexport { MyButton } from './my-button'
identified as such, the compiler could produce the equivalent ofh(MyButton, ...)
.Without this knowledge, the local component would suffer two drawbacks:
MyButton
on the setup object.MyButton
is a variable that could change, so the component is dynamic and precludes the static optimizations.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.
The reason we are not doing this is that the template and script parts of an SFC are typically executed as separate modules to
1. allow each having its own loader pipelines (webpack specific)
2. allow template to be individually hot-reloaded (thus preserving component state).
Regarding the drawbacks:
Component access only goes through the setup object, which is not a full reactive object (it's a proxy that only checks for ref unwrapping, so the cost is fairly cheap).
<MyButton/>
directly compiles toh($setup.MyButton)
, so there is no dynamic assumptions here.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 think I'm missing a piece here.
Setup properties can mutate, right? Do you know/assume
$setup.MyButton
is a constant rather than a reactive value that will change?If you assume
MyButton
can mutate, then isn't the code equivalent to<component :is="MyButton">
, which precludes some optimizations compared to a static<MyButton>
?https://vue-next-template-explorer.netlify.app/#%7B%22src%22%3A%22%3Ccomponent%20%3Ais%3D%5C%22xy%5C%22%20%2F%3E%5Cr%5Cn%3Cmy-xy%20%2F%3E%22%2C%22options%22%3A%7B%22mode%22%3A%22module%22%2C%22prefixIdentifiers%22%3Afalse%2C%22optimizeImports%22%3Afalse%2C%22hoistStatic%22%3Afalse%2C%22cacheHandlers%22%3Afalse%2C%22scopeId%22%3Anull%2C%22ssrCssVars%22%3A%22%7B%20color%20%7D%22%2C%22bindingMetadata%22%3A%7B%22TestComponent%22%3A%22setup%22%2C%22foo%22%3A%22setup%22%2C%22bar%22%3A%22props%22%7D%2C%22optimizeBindings%22%3Afalse%7D%7D
Or does the syntax
<MyButton>
imply that it must be static, even though it comes fromsetup
?In this case, what happens if that assumption is violated by user, do you emit a warning in DEV?