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

Proof of concept for terminal forwarding #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

asakusuma
Copy link

This PR adds an option that allows declaring a route to be an invalid terminal state, while also declaring what route should actually be visited if someone tries to visit as the terminal route.

TODO:

  1. Figure out perf implications
  2. Decide on exact API for the current "terminal" option in the dsl
  3. Support API for applying the terminal option to the parent instead of the index?

@@ -15,6 +15,16 @@ export function initialize(application) {
}
});

Ember.Router.reopen({
willTransition(a,b,intent) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces here.

@nathanhammond
Copy link
Owner

Writing some documentation:


The use-case for specifying a terminal route is _not_ to prevent us from having to create a route whose content is simply:

beforeModel() {
  this.replaceWith('non-terminal.sibling');
}

The goal is instead to make sure that redirects of this nature which are not dynamic can easily be identified and accounted for in other tools such as ember-prefetch.

@nathanhammond
Copy link
Owner

Looking at ember-prefetch we need some way to make sure that this has settled by the time we trigger willTransition. Flow as it stands:

  1. Overridden willTransition inside of your PR.
  2. Ember.Router.willTransition, which triggers the willTransition event.
  3. ember-prefetch's willTransition event handler.

Which means that we can't prevent things like ember-prefetch from running to completion on the original transition object. We need some way to capture this before the willTransition is fired/occurs, so that the "first" transition is to the correct location. (This scenario is almost universally going to be triggered by directly visiting some URL as there shouldn't be any links to non-terminal routes.)

let terminal = intent.targetName.substr(13);
this.replaceWith(terminal);
}
this._super.apply(this, arguments);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to get away with manually passing forward the new transition from line 22 into _super as long as we're 100% certain that this is the first reopen.

/cc @nickiaconis

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.

2 participants