Skip to content

Commit

Permalink
duck punch the router to fix a bug in emberjs
Browse files Browse the repository at this point in the history
  • Loading branch information
rauhryan committed Nov 14, 2016
1 parent 2fc4bd0 commit 5f38d9a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ember-app/app/initializers/punch-router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Ember from 'ember';

function addQueryParamsObservers(controller, propNames) {
propNames.forEach(function(prop) {
controller.addObserver(prop + '.[]', controller, controller._qpChanged);
});
}

let get = Ember.get;

export function initialize(container, application){
Ember.Route.reopen({
setup(context, transition) {
var controller;

var controllerName = this.controllerName || this.routeName;
var definedController = this.controllerFor(controllerName, true);

if (!definedController) {
controller = this.generateController(controllerName, context);
} else {
controller = definedController;
}


// Assign the route's controller so that it can more easily be
// referenced in action handlers. Side effects. Side effects everywhere.
if (!this.controller) {
var propNames = get(this, '_qp.propertyNames');
addQueryParamsObservers(controller, propNames);
this.controller = controller;
}

let queryParams = get(this, '_qp');

let states = queryParams.states;

controller._qpDelegate = states.allowOverrides;

return this._super(...arguments);
}
});
}

export default {
name: 'punch-router',
initialize: initialize
};

0 comments on commit 5f38d9a

Please sign in to comment.