-
-
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
Abstract away onNewRoute and routeHasChanged #2359
Conversation
This provides a cleaner interface for dealing with pages that handle multiple routes. We also move `modal` and `drawer` close calls to ensure those happen on route change with the same component.
This avoid issues with SettingsPage
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.
Seeing this isn't needed for beta 14, I'll do a full review of this later on.
this.currentPath = m.route.get(); | ||
} | ||
|
||
routeHasChanged() { |
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.
Do we want this to be public API, or could we just do the test in onbeforeupdate
?
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 public API is good: subclasses with more complex use cases (like DiscussionPage) could use it to do more of those checks, and also possibly handle some side effects if the route hasn't changed but we still want to do something (like scrolling to a post).
/** | ||
* A class name to apply to the body while the route is active. | ||
* | ||
* @type {String} | ||
*/ | ||
this.bodyClass = ''; | ||
|
||
this.currentPath = m.route.get(); |
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 line can be probably removed I think, since it's called in onNewRoute
already.
@@ -12,15 +12,18 @@ export default class Page extends Component { | |||
|
|||
this.onNewRoute(); |
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'd move that to the end of the function. This way everything in oninit
would run before onNewRoute
.
// Otherwise, load in a new discussion. The `else` branch will | ||
// be followed when `onNewRoute` is called from `oninit`. | ||
const idParam = m.route.param('id'); | ||
if (this.discussion && idParam && idParam.split('-')[0] === this.discussion.id()) { |
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'd split this out in this PR already, since the diff is very hard to read. Something like this:
isSameRoute() {
const idParam = m.route.param('id');
return this.discussion && idParam && idParam.split('-')[0] === this.discussion.id();
}
onSameRoute() {
const near = m.route.param('near') || '1';
if (near !== String(this.near)) {
this.stream.goToNumber(near);
}
this.near = near;
}
and:
onNewRoute() {
if (this.isSameRoute()) return this.onSameRoute();
super.onNewRoute();
....
}
Obsolete with #2378 |
This provides a cleaner interface for dealing with pages that handle multiple routes. We also move
modal
anddrawer
close calls to ensure those happen on route change with the same component.