-
Notifications
You must be signed in to change notification settings - Fork 545
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
Remove data object declaration #111
Conversation
I've always found that weird too, but there's surely an explanation for that design decision. However, the object syntax is slightly more readable than the function syntax. Maybe you could add that as a drawback? Simplicity is a big thing in Vue, especially in comparison to React. I would prefer the object syntax behavior to match the function syntax behavior rather than the other way around. |
Those are not interchangeable and do different things, that's why it's not in the drawback section. Even though I agree that it's more readable at the same time it's more confusing for beginners to distinguish between them without knowing how components actually instantiate. It would be sad to encounter an example with an object declaration, paste that into your code and get an unexpected result. |
hmm.. I am confused, because it always worked that way. There is appropriate warning in dev mode if you try to define data using plain object instead of function. |
Good point. I missed that it works only on a root component instance. Will update RFC accordingly. Thanks. |
I like this. The impact of this change is also minimized due to the root mounting API change in v3 (where you always use a root component). ^ @CyberAP I think the above should be mentioned in the RFC. |
This RFC is now in final comments stage. An RFC in final comments stage means that: The core team has reviewed the feedback and reached consensus about the general direction of the RFC and believe that this RFC is a worthwhile addition to the framework. |
I like this.. shared state is still easy to achieve and can appear more intentional now. const shared = {
foo: 1,
bar: 2
};
export default {
data() {
return {
localFoo: 'foo',
shared: shared
}
}
}; |
You might want to add that if you don't need the export default {
data: () => ({
look: 'ma',
no: 'extra',
indentation: 'required'
})
} |
If this RFC is accepted into the Vue, it will be necessary to further describe in the documentation how the data() {
const state = reactive({
count: 0,
double: computed(() => state.count * 2)
})
function increment() {
state.count++
}
return {
state,
increment
}
} |
Not that I don't agree that some explanation could be added to the docs, but I think that "If this RFC is accepted into the Vue" is not necessary - now you can also have
Actually can't it? I guess it would work too, didn't check though |
I'm honestly not sure what the actual difference is comparing |
Technical differences:
Conceptual differences:
|
…ect-declaration.md
@CyberAP Please update link to rendered RFC. |
updated link to the rendered RFC |
Thanks, updated now. |
* feat: migrate Style Guide (closes #24) * fix tag * remove "data() must be a function because vuejs/rfcs#111
* feat: migrate Style Guide (closes #24) * fix tag * remove "data() must be a function because vuejs/rfcs#111
Rendered