Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

askvortsov1
Copy link
Member

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 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.
@askvortsov1 askvortsov1 added this to the 0.1.0-beta.15 milestone Oct 5, 2020
Copy link
Member

@clarkwinkelmann clarkwinkelmann left a 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() {
Copy link
Member

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 ?

Copy link
Member Author

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();
Copy link
Contributor

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();
Copy link
Contributor

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()) {
Copy link
Contributor

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();

    ....

}

@askvortsov1
Copy link
Member Author

Obsolete with #2378

@askvortsov1 askvortsov1 closed this Oct 9, 2020
@askvortsov1 askvortsov1 removed this from the 0.1.0-beta.15 milestone Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants