Repository navigation
Refactor "Specifying a route's model" to be agnostic of data library choice - #708
Conversation
acorncom
left a comment
There was a problem hiding this comment.
@jenweber this is a GREAT start. There are a few items I think it's worth us cleaning up, but after we do that, I'm firmly in favor of merging this and not letting it sit for debate for too long. We can always improve it in future PRs
|
Extracting ember-data out into an independent topic would be a huge positive change for the beginning of the learning experience. I hope we can continue moving in this direction, and ultimately land at a place where the first time readers experiment with Ember, it's in the simplest context possible, involving only the most important entities and concepts. |
lisaychuang
left a comment
There was a problem hiding this comment.
Initial review as requested by @jenweber :)
Thank you for your hard work updating this guide! It's past midnight so I'll look through the rest tomorrow!
lisaychuang
left a comment
There was a problem hiding this comment.
Added more comments with questions, typos noted etc.
I find the section on Reusing Route Context highly confusing. Since this section was not edited by @jenweber , I'll suggest reviewing the section to determine if it should be removed or updated.
Thank you!
| Sometimes you need to fetch a model, but your route doesn't have the parameters, because it's | ||
| a child route and the route directly above or a few levels above has the parameters that your route | ||
| needs. | ||
| You might run into this if you have a URL like `/photos/4/comments/18`, and when you're in the comments route, you need a photo ID. |
There was a problem hiding this comment.
when you're in the comments route, you need a photo :id
In this example, you are using the convention of mode_id instead of just plain :id ( i.e. album_id), this might be confusing for readers as the previous examples above are using :id?
Since the code example uses song and album, change the URL example to match that instead (e.g. /albums/4/asongs/18)
The section below was not edited so I can't add comments inline:
Firstly, talking to @mike-north he said that trying to get query params from the parents' route is an advanced concept, and an uncommon thing to do. If we want to include the most important 20% of content that people need 80% of the time, this section does not pass the 80/20 rule. This looks like an an edge case and have "code smell".
Specific comments on why this section is confusing:
- Line 305 - 306:
This is guaranteed to work because the parent route is loaded. But if you tried to do
paramsForon a sibling route, you wouldn't have the results you expected.
Q1: Why do we have a guarantee with the parent route? Simply stating a guarantee is in one place but not the other doesn't help me form a mental model.
Q2: Why is using this method with a sibling route undesirable?
- Line 308
This is a great way to use the parent context to load something that you want.
Q: What does the generic term "something that you want" mean?
In the example ofsongloading something fromalbum, are we referring to data on thealbume.g. album name?
- Line 309 - 311
Using
paramsForwill also give you the query params defined on that route's controller.
This method could also be used to look up the current route's parameters from an action
or another method on the route, and in that case we have a shortcut:this.paramsFor(this.routeName).
😩I have no idea what this paragraph means.
- Line 313
In our case, the parent route had already loaded its songs, so we would be writing unnecessary fetching logic.
There has been no explanation on the parent route and how it loads data so far, so how did we arrive at this conclusion that songs are already loaded?
- Line 329
In the case above, the parent route looked something like this
Q1: Again, I'm still confused about what this example is
Q2: Why do we need to useRSVP.hashin the parent route?
I think either this entire section needs to be eliminated, or it need to be reviewed and updated to a sensible order:
- Start explaining from the "child route" (e.g.
song) and move upwards (e.g. `album) - Start explaining from the parent route and move downwards to child route
There was a problem hiding this comment.
I agree on a lot of these points. I didn't touch this section because it was super messy :P I would like to break this out into a new Issue/PR
|
@mike-north @lisaychuang @zachgarwood and @acorncom, thanks so much for the reviews! This is such an important part of understanding Ember, and I'm thankful we all invested the time to make it better :) @acorncom will you do one more read through? I think I have addressed all the comments, except about how reusing a route's context is super confusing. I agree and would like to address it in a separate PR. |
|
Also please squash & merge this when it's ready, or our git history will be ruined forever, haha |
|
Wow something bad happened with the GitHub diff... locally |
mansona
left a comment
There was a problem hiding this comment.
Some things (like links) that really should be changed, one or two minor suggestions that can be ignored and a few discussion points 👍
|
|
||
| If you decide to pass the entire model, be sure to cover this behavior in your acceptance tests. | ||
|
|
||
| If a route you are trying to link to has multiple dynamic segments, like `/photos/4/comments/18`, be sure to specify all the necessary information for each segment: |
There was a problem hiding this comment.
so this isn't 100% true 🤔 and to be honest I don't know how you would teach the alternative because it's quite a weird behaviour.
So first of all this is true if you're anywhere in the app not under the photos route. But if you're on /photos/4 you can link to
and it will keep you within the first dynamic segment and use 18 for the second 🙈 kinda strange but c'est la vie 🤷♂
There was a problem hiding this comment.
In the interest of teaching the happy path in the Guides, I think we should keep it as-is.
| needs. | ||
| You might run into this if you have a URL like `/photos/4/comments/18`, and when you're in the comments route, you need a photo ID. | ||
|
|
||
| In this scenario, you can use the `paramsFor` method to get the parameters of a parent route. |
There was a problem hiding this comment.
I feel like we should use album_id and comment_id in this example to make it more realistic 🤔 also aren't you saying that we're in the comments route? shouldn't the file name for this be app/routes/photo/comment.js or something?
There was a problem hiding this comment.
and to that point... if the code examples are talking about albums and songs shouldn't our in-prose example also be using the same model types?
There was a problem hiding this comment.
I agree, however I would like to address this in a future PR. This discrepancy is present in the current guides: https://guides.emberjs.com/release/routing/specifying-a-routes-model/
Small wording fixes suggested by acorncom Co-Authored-By: jenweber <[email protected]>
Co-Authored-By: acorncom <[email protected]>
Co-Authored-By: jenweber <[email protected]>
Co-Authored-By: jenweber <[email protected]>
Co-Authored-By: jenweber <[email protected]>
mansona
left a comment
There was a problem hiding this comment.
I have reviewed this extensively and double checked all the links and I'm happy that we can now merge it 👍 there are a few things that could still be improved (as ever) but at this stage, your work is a significant improvement on the previous page that we need to get this merged ASAP.
Instead of suggesting my changes I pushed one commit with the last fixes. If you are happy with those changes then push that merge button 🎉 ![]()
significant reviews since this last review 👍
|
🎉 congratulations @jenweber |
|
Thanks everyone for the reviews! Merged. |
See #20 for the motivation. In short, in order to make Ember Data guides a standalone resource and learning concept, we need to refactor how we teach data fetching in other parts of the app. I've made this article longer, and I don't take that lightly, but based on my experience teaching others, we can't skimp on this. Understanding models is one of the greatest new learner pain points, so more examples and simpler language are critical.
If there are controversial refactors, I can break this into multiple PRs, but I think it's best evaluated as a whole.
This PR is a broad refactor of https://guides.emberjs.com/release/routing/specifying-a-routes-model/
Here's how I recommend reviewing:
new Promiseexample makes any sense. I am skeptical.Changes
Here's a summary of the things I changed and the things I didn't.
Rationale for the biggest changes
The biggest changes are:
ember-ajaxexample is provided based on discussion in Quest - Improvements to teaching Ember Data #20.:idinstead of:photos_idparams. It's not something magical.Learning topics that are covered
In the old version, the following learning topics were covered. This refactor fulfills the scope of the old version as follows:
router.js