-
Notifications
You must be signed in to change notification settings - Fork 4.7k
[Rough Draft] Composition-API: Introduction #67
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
Conversation
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.
Nice work! I've added a couple of wording suggestions, mainly to eliminate duplicates and filling words/phrases. You'll notice that in most cases I suggested a simpler and/or shorter expression (at least IMHO) :)
Co-Authored-By: Phan An <[email protected]>
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, @phanan for reading through it and providing suggestions! Loved all of them and already fixed the ones where it could be optimized.
|
||
 | ||
|
||
Please consider this colourful example on the side for second or two as it presents a larger component with its **logical concerns** grouped by colours. |
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.
It was supposed to provide some context to the image. Might skip that "colorful" part.
repositories, | ||
getUserRepositories // functions returned behave the same as methods |
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.
Yeah – leftover from Notion. Will have to convert in the editor! Good catch.
Great work @shentao! As I was doing a (p)review of the Notion doc, I don't have any additional comments 😅 |
Thanks @NataliaTepluhina! Let me know if there is any other way I could help out! |
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.
Very long PR, I will continue reviewing it.
|
||
Organizing logics with component's options (`data`, `computed`, `methods`, `watch`) works in most cases. However, when our components get bigger, the list of **logical concerns** also grows. This can lead to components that are hard to read and understand, especially for people who didn't write them in the first place. | ||
|
||
 |
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.
This image appears out of context to me. I feel it would be better if we reuse the above snippet covey the intension. And a better resolution would be great.
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.
Good call @znck! I just picked the image from the RFC page, since it explained the idea pretty nicely in a visual manner. I used the same thing a few times during talks and it was the part that proved to be very educative to the audience. What about using the second image where it shows the two files (pre and post composition API)?
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 doubt the image is good visual representation of logic fragmentation. I meant that we can use the above code snippet and highlight in a similar manner. Since readers have already read the code above, it would be easier for them to scan the coloured highlights.
|
||
 | ||
|
||
Please consider this colourful example on the side for second or two as it presents a larger component with its **logical concerns** grouped by colours. |
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.
Yes, please.
suggestion: "logical concerns grouped by colours" should be the key focus of the paragraph and less dramatic text would be better to match overall writing style.
|
||
Now that we know the **why** we can get to the **how**. To start working with the Compsition API we first need a place where we can actually use it. In a Vue component, we call this place the `setup`. | ||
|
||
### Introducing `setup` |
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.
suggestion: The heading feels more like from an article. Can we reword it (without Introduction maybe)?
One thing I forgot to mention: Let’s all use American English (IIRC this is
mentioned somewhere in our writing guide) for our docs, so “color” instead
of “colour” ;)
…On Wed, 15 Apr 2020 at 07:57, Rahul Kadyan ***@***.***> wrote:
***@***.**** commented on this pull request.
Very long PR, I will continue reviewing it.
------------------------------
In src/guide/composition-api-introduction.md
<#67 (comment)>:
> @@ -0,0 +1,540 @@
+# Composition API: Introduction
+
+## Why Composition API?
+
+::: tip Note
+Reaching this far in the documentation, we are assuming that you are already familiar with both the basics of writing Vue code as well as the basics of creating components. If you’re not, you might want to first read through [Vue Introduction](introduction.md) and [Components Basics](component-basics.md) first before reading further.
+:::
+
+Creating Vue components is a powerful technique that allows us to extract repeatable parts of the interface coupled with its functionality into reusable pieces of code. This alone can get our application pretty far in terms of maintainability and flexibility. However, our collective experience has proved that this alone might not be enough, especially when your application is getting really big – think several hundreds of components. When dealing with such large applications, sharing and reusing code becomes especially important.
*nitpick:* I understand what you're trying to covey here but I feel the
phrase "a powerful technique" is unnecessary as you're highlighting the
powers of the technique in the following segment.
⬇️ Suggested change
-Creating Vue components is a powerful technique that allows us to extract repeatable parts of the interface coupled with its functionality into reusable pieces of code. This alone can get our application pretty far in terms of maintainability and flexibility. However, our collective experience has proved that this alone might not be enough, especially when your application is getting really big – think several hundreds of components. When dealing with such large applications, sharing and reusing code becomes especially important.
+Creating Vue components allows us to extract repeatable parts of the interface coupled with its functionality into reusable pieces of code. This alone can get our application pretty far in terms of maintainability and flexibility. However, our collective experience has proved that this alone might not be enough, especially when your application is getting really big – think several hundreds of components. When dealing with such large applications, sharing and reusing code becomes especially important.
------------------------------
In src/guide/composition-api-introduction.md
<#67 (comment)>:
> + },
+ mounted () {
+ this.getUserRepositories() // 1
+ }
+}
+```
+
+This component has several responsibilities:
+
+1. Getting repositories from a presumedly external API for that user name and refreshing it whenever the user changes
+2. Searching for repositories using a `searchQuery` string
+3. Filtering repositories using a `filters` object
+
+Organizing logics with component's options (`data`, `computed`, `methods`, `watch`) works in most cases. However, when our components get bigger, the list of **logical concerns** also grows. This can lead to components that are hard to read and understand, especially for people who didn't write them in the first place.
+
+
This image appears out of context to me. I feel it would be better if we
reuse the above snippet covey the intension. And a better resolution would
be great.
------------------------------
In src/guide/composition-api-introduction.md
<#67 (comment)>:
> + this.getUserRepositories() // 1
+ }
+}
+```
+
+As you can see, this component has several responsibilities:
+
+1. Getting repositories from a presumedly external API for that user name and refreshing it whenever the user changes
+2. Filtering repositories based on a `searchQuery` text
+3. Filtering repositories based on a `filters` object
+
+The above way of building components, enforces code that is organized by option types within the component itself (data, computed, methods, watch), which is OK in most cases. However, usually when our components grow the list of **logical concerns** is also growing. This can lead to components that are hard to read and understand, especially to someone that hasn’t originally written it.
+
+
+
+Please consider this colourful example on the side for second or two as it presents a larger component with its **logical concerns** grouped by colours.
Yes, please.
*suggestion:* "logical concerns grouped by colours" should be the key
focus of the paragraph and less dramatic text would be better to match
overall writing style.
------------------------------
In src/guide/composition-api-introduction.md
<#67 (comment)>:
> +
+Organizing logics with component's options (`data`, `computed`, `methods`, `watch`) works in most cases. However, when our components get bigger, the list of **logical concerns** also grows. This can lead to components that are hard to read and understand, especially for people who didn't write them in the first place.
+
+
+
+Please consider this colourful example on the side for second or two as it presents a larger component with its **logical concerns** grouped by colours.
+
+Such fragmentation is what makes it difficult to understand and maintain a complex component. The separation of options obscures the underlying logical concerns. In addition, when working on a single logical concern, we have to constantly "jump" around option blocks for the relevant code.
+
+It would be much nicer if we could collocate code related to the same logical concern. And this is exactly what the Composition API enables us to do.
+
+## Basics of Composition API
+
+Now that we know the **why** we can get to the **how**. To start working with the Compsition API we first need a place where we can actually use it. In a Vue component, we call this place the `setup`.
+
+### Introducing `setup`
*suggestion:* The heading feels more like from an article. Can we reword
it (without Introduction maybe)?
------------------------------
In src/guide/composition-api-introduction.md
<#67 (comment)>:
> +setup (props) {
+ let repositories = []
+ const getUserRepositories = async () => {
+ repositories = await fetchUserRepositories(props.user)
+ }
+
+ return {
+ repositories,
+ getUserRepositories // functions returned behave the same as methods
+ }
+}
+```
+
+This is our starting point, except it's not working yet because our `repositories` variable is not reactive. This means from a user's perspective, the repository list would remain empty. Let's fix that!
+
+### Introducing `ref`
*suggestion:* Same as above, dramatic heading.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#67 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB5O3USJYJWUHTVTOOJRY3DRMVED3ANCNFSM4MH2B56A>
.
|
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.
Again, solid work @shentao! I'm using some free time before work to add a couple more super minor suggestions (some might even be the result of my last review!). My general idea is to keep the documentation as short and straightforward as it could be by:
- Merging/removing sentences/phrases that convey the same/similar message.
- Reducing the usage of filler and/or assuming phrases such as "As you know" or "You might have noticed." While these phrases add a friendly touch to the document, overusing them might lengthen (and dilute) the doc, cause a dramatic feel, and is prone to struggle invalidation.
|
||
Now we need to react to the changes made to the `user` prop. For that we will use the standalone `watch` function. | ||
|
||
### Introducing standalone `watch` |
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 headings should have the same case (currently it's Title Case e.g., Ready for More?).
@shentao You can use grammarly.com to catch issues like "color" instead of "colour" and there's a vscode extension too (shameless plug). |
Co-Authored-By: Phan An <[email protected]> Co-Authored-By: Rahul Kadyan <[email protected]>
As we have no further comments, I'm merging this PR 🎉 |
commit 5509287 Author: Natalia Tepluhina <[email protected]> Date: Mon May 4 06:57:13 2020 +0300 Options API Reference (#73) * feat: started with Global Config API * feat: finished global config * feat: added component global api * feat: added directives API * feat: added mixin API * feat: add mount API * feat: added unmount and use * Update src/api/global-api.md Co-Authored-By: Jinjiang <[email protected]> * Update src/api/global-config.md Co-Authored-By: Jinjiang <[email protected]> * fixL changed global -> application * fix: fixed types for config * fix: fixed types for API * feat: added a note about native HTML tags * feat: added options data chapter * feat: finished options data * feat: added options-DOM * Added emits to data * feat: added lifecycle hooks * feat: added renderTracked and renderTriggered * feat: added options assets * feat: added options composition * feat: added misc to options * fix: TODO cleanup * fix: changed data description Co-authored-by: Jinjiang <[email protected]> commit b31cbfc Author: Damian Dulisz <[email protected]> Date: Sun May 3 16:18:35 2020 +0200 [Rough Draft] Composition-API: Introduction (#67) * Add Composition-API: Introduction draft * Fix image links * Add styling for Tips and Warnings. Fix missing `js` syntax flag * Apply suggestions from An Phan Co-Authored-By: Phan An <[email protected]> * Apply suggestions from code review Co-Authored-By: Phan An <[email protected]> Co-Authored-By: Rahul Kadyan <[email protected]> * Convert tabs to spaces Co-authored-by: Phan An <[email protected]> Co-authored-by: Rahul Kadyan <[email protected]> commit 19c7285 Author: NataliaTepluhina <[email protected]> Date: Sun May 3 17:18:17 2020 +0300 fix: fixed slots inconsistence
* feat: started with Global Config API * feat: finished global config * feat: added component global api * feat: added directives API * feat: added mixin API * feat: add mount API * feat: added unmount and use * Update src/api/global-api.md Co-Authored-By: Jinjiang <[email protected]> * Update src/api/global-config.md Co-Authored-By: Jinjiang <[email protected]> * fixL changed global -> application * fix: fixed types for config * fix: fixed types for API * feat: added a note about native HTML tags * feat: added options data chapter * feat: finished options data * feat: added options-DOM * Added emits to data * feat: added lifecycle hooks * feat: added renderTracked and renderTriggered * feat: added options assets * feat: added options composition * feat: added misc to options * fix: TODO cleanup * fix: changed data description * Added instance properties * Squashed commit of the following: commit 5509287 Author: Natalia Tepluhina <[email protected]> Date: Mon May 4 06:57:13 2020 +0300 Options API Reference (#73) * feat: started with Global Config API * feat: finished global config * feat: added component global api * feat: added directives API * feat: added mixin API * feat: add mount API * feat: added unmount and use * Update src/api/global-api.md Co-Authored-By: Jinjiang <[email protected]> * Update src/api/global-config.md Co-Authored-By: Jinjiang <[email protected]> * fixL changed global -> application * fix: fixed types for config * fix: fixed types for API * feat: added a note about native HTML tags * feat: added options data chapter * feat: finished options data * feat: added options-DOM * Added emits to data * feat: added lifecycle hooks * feat: added renderTracked and renderTriggered * feat: added options assets * feat: added options composition * feat: added misc to options * fix: TODO cleanup * fix: changed data description Co-authored-by: Jinjiang <[email protected]> commit b31cbfc Author: Damian Dulisz <[email protected]> Date: Sun May 3 16:18:35 2020 +0200 [Rough Draft] Composition-API: Introduction (#67) * Add Composition-API: Introduction draft * Fix image links * Add styling for Tips and Warnings. Fix missing `js` syntax flag * Apply suggestions from An Phan Co-Authored-By: Phan An <[email protected]> * Apply suggestions from code review Co-Authored-By: Phan An <[email protected]> Co-Authored-By: Rahul Kadyan <[email protected]> * Convert tabs to spaces Co-authored-by: Phan An <[email protected]> Co-authored-by: Rahul Kadyan <[email protected]> commit 19c7285 Author: NataliaTepluhina <[email protected]> Date: Sun May 3 17:18:17 2020 +0300 fix: fixed slots inconsistence * Revert "Squashed commit of the following:" This reverts commit b62c049. Co-authored-by: Jinjiang <[email protected]>
…uejs#67) * docs(event-handling): review src/guide/essentials/event-handling.md * Apply suggestions from code review Co-authored-by: Godpu <[email protected]>
This PR is a draft of the Composition API: Introduction Tutorial.
Here's what the PR includes:
setup
optionref
(`reactive is omitted in the introduction tutorial)setup
watch
(watchEffect
is omitted in the introduction tutorial)computed
What's left to do:
reactive
andwatchEffect
is a good idea. I believe it is and here’s my reasoning:reactive
– I don’t think we need to show two ways of doing the same thing at this stage, where I think the most important part is to show how the Option API can translate to Composition API. Also introducingreactive
at this point could confuse the reader and is by no means justified by the code itself.watchEffect
doesn’t really have a counterpart in the options API (unless we consider how the render function is working 😅). Thus explaining it here would unnecessarily make the text longer and could sidetrack the reader by showing something that again is not necessary from the tutorial perspective.Open to feedback! I think it might still be a bit too long...
Edit: Path to preview is
/guide/composition-api-introduction.html
.