-
Notifications
You must be signed in to change notification settings - Fork 248
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 inline defined middleware #10956
Conversation
8c97731
to
1b5530f
Compare
…m one page to another
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 couldn't migrate this file to the router config because it relies on the store already having schemas.
The initialization sequence (even modified slightly) will not have schemas loaded before route resolution when re/loading a page.
@@ -3,13 +3,13 @@ import { NAME as SETTINGS } from '@shell/config/product/settings'; | |||
import { MANAGEMENT } from '@shell/config/types'; | |||
|
|||
export default { | |||
middleware({ redirect, route, store } ) { | |||
const hasSettings = !!store.getters[`management/schemaFor`](MANAGEMENT.SETTING); | |||
beforeCreate() { |
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'll preface this comment by saying that I'm fine with the approach represented here, I'm more interested in exploring an alternative to see if it makes sense for this use case.
Have we considered utilizing in-component guards1 instead of the beforeCreate()
hook? I think that the guard would better communicate what we are doing within this component, but it comes with the tradeoff that we might not have access to this
when we want it..
Footnotes
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 haven't considered that. Do you know of a way to access the store from the guard?
It's actually a pretty reasonable idea which may apply better in that it executes before the component is created just like middleware.
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 did find vuejs/vue-router#1103 (comment)
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, it looks like we would have to do something like this instead
beforeRouteEnter (to, from, next) {
next(vm => {
const hasSettings = !!vm.$store.getters[`management/schemaFor`](MANAGEMENT.SETTING);
...
})
}
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'll keep looking into this. It's interesting and not as straight forward as I would've thought. If we access the vm it looks like the component will already be created so not a big advantage.
There's another suggestion I found which mentions just importing our store and accessing it directly. With responses that would resemble our current predicament in regards to how we can access our store in the app.
Any thoughts on the idea of making the store global?
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 gave the global store a shot and it's a no go. The schemas aren't present when re/loaded.
I'm fine with leaving it as is or using the next(vm => {}). Do you think one is better than the other?
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 we can leave this as is. It sounds like we won't get much of a benefit and the syntax will end up being less direct with the in-component guard.
Thanks for entertaining the idea 🙂
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.
LGTM
Nice cleanup 👍 |
Summary
Remove inline defined middleware. Replace it primarily with router configuration.
Areas or cases that should be tested
We already have adequate automated testing for this.
Checklist