Skip to content

Commit

Permalink
Fix query param stickiness between models in ember-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Raja Alauddin Raja Abdullah committed Jan 5, 2017
1 parent 7dbf597 commit 7672ec9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Controller, RSVP } from 'ember-runtime';
import { Component } from 'ember-glimmer';
import { Engine } from 'ember-application';
import { Route } from 'ember-routing';
import { jQuery } from 'ember-views';

moduleFor('Application test: engine rendering', class extends ApplicationTest {
setupAppAndRoutableEngine(hooks = []) {
Expand All @@ -20,6 +21,7 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
this.route('comments');
this.route('likes');
});
this.route('category', {path: 'category/:id'});
});
this.registerRoute('application', Route.extend({
model() {
Expand All @@ -34,6 +36,9 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
queryParams: ['lang'],
lang: ''
}));
this.register('controller:category', Controller.extend({
queryParams: ['type'],
}));
this.register('template:application', compile('Engine{{lang}}{{outlet}}'));
this.register('route:application', Route.extend({
model() {
Expand Down Expand Up @@ -572,4 +577,18 @@ moduleFor('Application test: engine rendering', class extends ApplicationTest {
});
});
}

['@test query params don\'t have stickiness by default between model'](assert) {
assert.expect(1);

this.setupAppAndRoutableEngine();
this.additionalEngineRegistrations(function() {
this.register('template:category', compile('{{#link-to "blog.category" 1337}}Category 1337{{/link-to}}'))
});

return this.visit('/blog/category/1?type=news').then(() => {
let href = this.element.querySelector('a').href;
assert.equal(href.match(/type=news/), null);
});
}
});
4 changes: 2 additions & 2 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
let aQp = queryParams.map[prop];

aQp.values = params;
let cacheKey = calculateCacheKey(aQp.controllerName, aQp.parts, aQp.values);
let cacheKey = calculateCacheKey(aQp.route.fullRouteName, aQp.parts, aQp.values);

if (cache) {
let value = cache.lookup(cacheKey, prop, aQp.undecoratedDefaultValue);
Expand Down Expand Up @@ -1363,7 +1363,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
_qpChanged(prop, value, qp) {
if (!qp) { return; }

let cacheKey = calculateCacheKey(qp.controllerName, qp.parts, qp.values);
let cacheKey = calculateCacheKey(qp.route.fullRouteName, qp.parts, qp.values);

// Update model-dep cache
let cache = this._bucketCache;
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/system/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ const EmberRouter = EmberObject.extend(Evented, {
delete queryParams[presentProp];
}
} else {
let cacheKey = calculateCacheKey(qp.controllerName, qp.parts, state.params);
let cacheKey = calculateCacheKey(qp.route.fullRouteName, qp.parts, state.params);
queryParams[qp.scopedPropertyName] = appCache.lookup(cacheKey, qp.prop, qp.defaultValue);
}
}
Expand Down

0 comments on commit 7672ec9

Please sign in to comment.