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

(cherry picked from commit 8f1db44)
  • Loading branch information
rauhryan authored and chancancode committed Nov 27, 2016
1 parent 05cfca5 commit 968385f
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 @@ -1228,6 +1228,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 @@ -1249,8 +1252,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 968385f

Please sign in to comment.