Skip to content

Commit

Permalink
[BUGFIX beta] sets the controller _qpDelegate
Browse files Browse the repository at this point in the history
before mapping all the queryParams.

In certain scenarios, if query params are shared
through a service, bound query params will
fire the _qpDelegate while transitioning to a new
controller if the property has been modified from
it's default value.

Loosely related to
  - #11592

  Based on a previous PR
    - #13981
  • Loading branch information
rauhryan committed Nov 9, 2016
1 parent cd137d7 commit 8f1db44
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,9 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
let queryParams = get(this, '_qp');

let states = queryParams.states;

controller._qpDelegate = states.allowOverrides;

if (transition) {
// Update the model dep values used to calculate cache keys.
stashParamNames(this.router, transition.state.handlerInfos);
Expand All @@ -1337,8 +1340,6 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
});
}

controller._qpDelegate = states.allowOverrides;

if (transition) {
let qpValues = getQueryParamsFor(this, transition.state);
controller.setProperties(qpValues);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
Controller,
Service
} from 'ember-runtime';
import Ember from 'ember';
import { run } from 'ember-metal';
import { jQuery } from 'ember-views';
import { QueryParamTestCase, moduleFor } from 'internal-test-helpers';

moduleFor('Query Params - shared service state', class extends QueryParamTestCase {

boot() {
this.setupApplication();
return this.visitApplication();
}

setupApplication() {
this.router.map(function() {
this.route('home', { path: '/' });
this.route('dashboard');
});

this.application.register('service:filters', Service.extend({
shared: true
}));

this.registerController('home', Controller.extend({
filters: Ember.inject.service()
}));

this.registerController('dashboard', Controller.extend({
filters: Ember.inject.service(),
queryParams: [
{ 'filters.shared': 'shared' }
]
}));

this.registerTemplate('application', `{{link-to 'Home' 'home' }} <div> {{outlet}} </div>`);
this.registerTemplate('home', `{{link-to 'Dashboard' 'dashboard' }}{{input type="checkbox" id='filters-checkbox' checked=(mut filters.shared) }}`);
this.registerTemplate('dashboard', `{{link-to 'Home' 'home' }}`);
}
visitApplication() {
return this.visit('/');
}

['@test can modify shared state before transition'](assert) {
assert.expect(1);

return this.boot().then(() => {
this.$input = jQuery('#filters-checkbox');

// click the checkbox once to set filters.shared to false
run(this.$input, 'click');

return this.visit('/dashboard').then(() => {
assert.ok(true, 'expecting navigating to dashboard to succeed');
});
});
}

['@test can modify shared state back to the default value before transition'](assert) {
assert.expect(1);

return this.boot().then(() => {
this.$input = jQuery('#filters-checkbox');

// click the checkbox twice to set filters.shared to false and back to true
run(this.$input, 'click');
run(this.$input, 'click');

return this.visit('/dashboard').then(() => {
assert.ok(true, 'expecting navigating to dashboard to succeed');
});
});
}
});

0 comments on commit 8f1db44

Please sign in to comment.