Skip to content

Commit

Permalink
make sure to call super in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
bttf committed Aug 11, 2016
1 parent b083915 commit cd8f098
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 2 additions & 1 deletion addon/mixins/reset-scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default Ember.Mixin.create({
/**
* Scroll to top when route is entered.
*/
activate() {
activate(...args) {
this._super(...args);
Ember.$(window).scrollTop(0);
},
});
29 changes: 21 additions & 8 deletions addon/mixins/scroll-operator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ export default Ember.Mixin.create({
* Attach on-scroll handler to window/document. Handler will call _scrollTop
* on scroll.
*/
activate() {
activate(...args) {
this._super(...args);
this._attachEvents();
},

/**
* Detach on-scroll handlers on route exit.
*/
deactivate() {
deactivate(...args) {
this._super(...args);
this._detachEvents();
},

Expand All @@ -23,10 +25,15 @@ export default Ember.Mixin.create({
* position or not based on transition. Also detachEvents to ignore any
* scrolling that may happen between now and setupController.
*/
beforeModel(transition) {
beforeModel(...args) {
const { transition } = args;

this._super(...args);

if (!this._didTransitionViaBackOrForward(transition) && this.controller) {
this.controller.set('currentPosition', 0);
}

this._detachEvents();
},

Expand All @@ -35,11 +42,17 @@ export default Ember.Mixin.create({
* happens after model hooks have been fully executed. Also re-attachEvents
* now to resume watching scroll position.
*/
setupController(controller) {
Ember.run.schedule('afterRender', null, () => {
Ember.$(window).scrollTop(controller.getWithDefault('currentPosition', 0));
this._attachEvents();
});
setupController(...args) {
const { controller } = args;

this._super(...args);

if (controller) {
Ember.run.schedule('afterRender', null, () => {
Ember.$(window).scrollTop(controller.getWithDefault('currentPosition', 0));
this._attachEvents();
});
}
},

_attachEvents() {
Expand Down

0 comments on commit cd8f098

Please sign in to comment.