-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
duck punch the router to fix a bug in emberjs
Relates to - emberjs/ember.js#13981 - emberjs/ember.js#13771
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
|