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

Decouple controller lookup from URL generation. #14980

Merged
merged 1 commit into from
Mar 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
this.fullRouteName = getEngineRouteName(getOwner(this), name);
},

/**
Populates the QP meta information in the BucketCache.

@private
@method _populateQPMeta
*/
_populateQPMeta() {
this._bucketCache.stash('route-meta', this.fullRouteName, this.get('_qp'));
},

/**
@private

Expand Down
1 change: 0 additions & 1 deletion packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ const EmberRouter = EmberObject.extend(Evented, {
}

handler._setRouteName(routeName);
handler._populateQPMeta();

Copy link
Contributor

Choose a reason for hiding this comment

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

So you've removed this to enable lazy evaluating of qp meta, but where is this lazy evaluation happening? How is this backwards compatible?

Copy link
Member Author

Choose a reason for hiding this comment

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

@scalvert - Great question, general reasons below:

  • if you look at _populateQPMeta()'s definition, all it does is eagerly this.get('_qp') and save it off into the bucket cache, however nothing ever looks it up!!!
  • Things like Ember.Router#_prepareQueryParams (used by {{link-to, transitionTo, etc) are calling route._getQPMeta() which does return route.get('_qp') (I'm guessing that at some point it was returning from the bucket cache, but it does not do this any longer). This still works (regardless of _populateQPMeta() being called first).

if (engineInfo && !hasDefaultSerialize(handler)) {
throw new Error('Defining a custom serialize method on an Engine route is not supported.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { get } from 'ember-metal';
import { RSVP } from 'ember-runtime';
import { Route } from 'ember-routing';

Expand All @@ -11,21 +12,37 @@ moduleFor('Query Params - async get handler', class extends QueryParamTestCase {
return {
location: 'test',

init() {
this._super(...arguments);
this._seenHandlers = Object.create(null);
this._handlerPromises = Object.create(null);
},

_getQPMeta(handlerInfo) {
return this._bucketCache.lookup('route-meta', handlerInfo.name);
let handler = this._seenHandlers[handlerInfo.name];
if (handler) {
return get(handler, '_qp');
}
},

_getHandlerFunction() {
let getHandler = this._super(...arguments);
let cache = {};
let handlerPromises = this._handlerPromises;
let seenHandlers = this._seenHandlers;

return (routeName) => {
fetchedHandlers.push(routeName);

// Cache the returns so we don't have more than one Promise for a
// given handler.
return cache[routeName] || (cache[routeName] = new RSVP.Promise((resolve) => {
setTimeout(() => resolve(getHandler(routeName)), 10);
return handlerPromises[routeName] || (handlerPromises[routeName] = new RSVP.Promise((resolve) => {
setTimeout(() => {
let handler = getHandler(routeName);

seenHandlers[routeName] = handler;

resolve(handler);
}, 10);
}));
};
}
Expand Down