Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listening to scroll change #69

Closed
danielspaniel opened this issue Oct 14, 2015 · 3 comments
Closed

listening to scroll change #69

danielspaniel opened this issue Oct 14, 2015 · 3 comments

Comments

@danielspaniel
Copy link

I am trying to listen to the scrolling as the collection scrolls, and first thought of passing in
my own scroll-change action to handle this, but that means the collection is actually delegating to
my scroll change action instead of doing its own scrolly things.

In the ember-collections component there is the action:

  actions: {
    scrollChange(scrollLeft, scrollTop) {
      if (this._scrollChange) {
          this.sendAction('scroll-change', scrollLeft, scrollTop);
      } else {
        if (scrollLeft !== this._scrollLeft ||
            scrollTop !== this._scrollTop) {
          set(this, '_scrollLeft', scrollLeft);
          set(this, '_scrollTop', scrollTop);
          needsRevalidate(this);
        }
      }
    },

which means that if I pass in an action handler to listen for the scroll events ( custom action ) I am essentially overriding the components behavior.

I am only interested in listening to scroll change events in a collection, so I am curious if there is a way to do that in a more elegant way, or a way that works, since my way not working? I know I can attach a 'scroll' listener to the collection's div and use jquery to listen that way, but its not as fun.

Seems like I should be able to pass in my action handler and not override the original. I don't mind submitting a PR for this if needed.

@alexander-alvarez
Copy link

If you extend the component, you should be able to call _super within your action handler to also call the original action.

actions: {
    scrollChange(scrollLeft, scrollTop) {
      // your code
     ...
      this._super(scrollLeft, scrollTop)
    }
}

@danielspaniel
Copy link
Author

your right @alexander-alvarez, I could just do that .. I guess I was trying to fish about to see if the intent really was to have the passed in scroll-change listener override the built in one.
Not sure why that was done that way in other words.

@lukemelia
Copy link
Collaborator

@danielspaniel The idea was that the default behavior of scrolling should be that it works normally, BUT if you want to handle the scrollChange action in a true data down, actions up manner than we don't want to get in your way of updating the scrollLeft and scrollTop as you see fit.

Maybe too confusing? Definitely needs docs if it's going to stay like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants