-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Allow extensions to use route resolvers #2275
Conversation
5f5cced
to
bdd45cb
Compare
My suggestion would actually be that we add validation for Then we can add a second property, like I see there's an interface for While it might be helpful to provide an extendable base resolver, we need to also make sure devs can register resolvers that don't extend that base resolver, since there would otherwise be no way to have only |
@clarkwinkelmann Those are TS typings, we can't use them to check in JS. They most likely don't translate to anything in JS. |
Yes, I know. I was just saying we should use the typings since that code is TS already. The part about checking the parameters will have to use basic javascript and not interfaces. |
I would be alright with that. The only question is, how do we want to handle providing routeName to a custom resolver? I'd say we should expect a setRouteName method on all custom resolvers then? |
We don't necessarily need to pass the routeName to the resolver. The resolver could also hard-code its routeName in the case of custom resolvers. I'd say we add a check in the Something else we could do is check whether the |
bdd45cb
to
6a29f8e
Compare
@clarkwinkelmann how's this? |
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'm not sure that resolverClass
feature is really needed, but otherwise looking good.
Functionnaly I guess it's the same but why use onmatch
and not return m(this.component, [...])
in render()
like previously?
By doing that, we'd be effectively killing off the ability to use/modify onmatch. It's a useful feature, and I'm planning to use it in #2249 to show error pages when relevant (passing the error details in through the payload). |
8c63ff2
to
161cd57
Compare
Could the PR description get a few more details on the actual use-case here? What is the intention here? It's a bit difficult sifting through so much discussion about temporary, now-obsolete changes in the huge Mithril branch. |
ae61b3c
to
db56065
Compare
Done, and rebased |
9136f3f
to
db56065
Compare
db56065
to
8432bc9
Compare
I still find it hard to see actual concrete use-cases, to be honest. The only concrete ones seems to be the "frontend error handling" one (#2249), and I've raised my concerns about that in the relevant issue and PR. That said, I would first recommend to spend time on actual abstractions for pages / routes, to get hold of the hacks that were introduced around routing in the upgrade to Mithril 2 and then revisit this if there are actual extension needs - we might not need the resolvers in core anymore, or have better extension points to offer at that time. |
Resolvers are a mithril 2 feature, and even if we can't come up with use cases now, I'm not sure why we shouldn't try to support the feature itself, especially when it's not difficult to do so |
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 this is good (???)
@franzliedke Could you go a bit more into detail about your vision for page/route abstraction? We need to decide whether we want to include this in b14 Some ideas I've had include:
This would be a more pleasant API for dealing with this stuff, |
I don't think this is an urgent matter, I'd recommend keeping this for the next release cycle. It would be nice to have at least one (community?) extension making use of this feature to validate its implementation. |
8432bc9
to
2abe9f1
Compare
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 code looks clean and organized, and nothing else is added apart from the resolver for Discussion so 👍
Not tested locally.
… resolverClass which should accept the component and route key in its constructor.
…t to another on the same discussion triggers a scroll instead of rerendering
35a14ff
to
596a1d5
Compare
Depends on #2378.
See #2266.
Mithril Route Resolvers are new features in Mithril 2 that allow some logic to be inserted before a route is handled. Essentially, a quick layer before the component: https://mithril.js.org/route.html#routeresolver. Essentially, its 2 methods allow for hacking in:
Currently, Route Resolvers are used to pass in the Flarum route name as an attr to the component handling the route. We will also be using them to process 403 and 404 errors in the frontend (instead of having dedicated blade pages).
The current implementation of mapRoutes automatically wraps all components in a route resolver. This is nice, but it doesn't allow extensions to use custom route resolvers in their routes. As such, this PR provides the following options for mapRoute:
resolver
key can be used to provide an INSTANCE of a route resolver. This instance should define which component should be used, and hardcode the route name to be passed into it. This instance will be used without any modifications by Flarum.resolverClass
key ANDcomponent
key can be used to provide a CLASS that will be used to instantiate a route resolver, to be used instead of Flarum's default one, as well as the component to use. It's constructor should take 2 arguments:(component, routeName)
. We recommend extending theflarum/utils/DefaultResolver
class.component
key can be used alone to provide a component. This will result in the default behavior.We also use a custom route resolver for DiscussionPage so that routing from one post to another in the same discussion results in a scroll, not a full page rerender.