-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
ui: Outlet Loading #8779
Merged
Merged
ui: Outlet Loading #8779
Conversation
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
kaxcode
approved these changes
Sep 30, 2020
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 was a lot, but it's a full implementation so it's understandable. There seem to be some merge conflicts. Once those are fixed .
johncowen
force-pushed
the
ui/chore/loading-outlets
branch
from
October 1, 2020 08:08
3db7afe
to
03b4532
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The Route loading logic in the UI has historically been spread out amongst various pieces of the application, in the AppView component (sometimes), the Application route and the Feedback service.
The sprawly nature of this along with the fact that you could easily forget to set certain properties when creating new routes meant it was more than straightforwards for loading to 'just work' especially in sub-routes and sub-sub-routes etc. We took a look at using model hooks and loading.hbs templates, but both options had their downsides, and both required extra things to be done in order for loading to 'just work' whether adding hooks or files.
We realized that if each
{{outlet}}
was wrapped in a<Outlet data-outlet="dc">{{outlet}}</Outlet>
component,dc
being the name/identifier of the currentRoute
/template
(theRoute.routeName
), then we could automatically figure out which outlet in the Route hierarchy was to be loaded by traversing up the tree of outlets and comparing the clicked route name with the name of the outlet.For example:
In our case we add a
data-state="loading"
attribute to the outlet when we find the match. Once the router has finished transitioning, we set the state of the loading outlet back to idle.Using this attribute we can do all of out route loading visuals via CSS by hiding and showing the unloaded and subsequently loaded outlet, which massively reduces the spread of code used to control loading state in the application. Future work could involve a more subtle transition between loading pages, if that was something we wanted to do.
The one downside is that the only way to 'name' the outlets correctly is to have access to the
Route.routeName
property, something that is only available from within the Route. We tried various methods of retrieving this and passing it through to the template, and eventually settled on using a base Route class, which all of our Routes now inherit from. The approach means:Additionally here we took advantage of the work to re-work how we target individual pages via CSS.
Previously we used the AppView component to set classNames on the root of the document (in every single template), say for example on the kv edit page we would add
class="template-kv template-edit"
. We've replaced this by automatically adding the name on the current route as a data attribute on the root of the document using theapplication
outlet. For examplehtml data-route="dc.kv.edit"
, which again we can use to target individual pages via CSS without having to remember to do anything in our templates. Additionally, using selectors such ashtml[data-route$='.edit']
etc. lets you can target all edit pages.