Our app calls for us to handle scroll events in a view. We had a look through the Ember source and it doesn’t appear that scroll events are part of the automatic Ember event delegation. We had to manually hook it up in our view via:
$(window).scroll(function...);
We then started to run into some issues when testing as we have disabled auto-run. We ended up working around this by wrapping the scroll handler with a run loop. This seems to work fine but would like some input from the community as to whether this is a reasonable approach and the reasoning behind scroll events not being automatically delegated.
I think we decided not to watch scroll by default because 1) they are specific to any view and 2) they can fire a whole lot. Your approach is correct, both binding to the window and wrapping in Ember.run. Make sure you do the binding in didInsertElement and tear it down in willRemoveElement.
// ... My class
scroll: function() {
// You can pass this directly but i've extracted it here for clarity
var view = this;
Ember.run(view, function() {
// Scroll work
})
},
// ... The rest of the class