EmberSherpa / ama

Ask me anything Ember!
22 stars 0 forks source link

How would you recommend to implement infinite scrolling the Ember-way? #3

Closed mattmazzola closed 8 years ago

mattmazzola commented 8 years ago

Some background: I have an app built that loads the first page and I'm not sure how to add infinite scrolling to it. Given the data-down actions-up principles combined with the idea that the route should handle actions related to updating the model, and the controller should handle actions from the user etc. It seems like the route should be maintaining the state of the count and offset parameters used to issue the store.findQuery command and the controller should know when user needs more data and invoke the actions in the route which should update the model with the next page of data. That being said, I'm just guessing and would be interested to see how other people do this.

An alternative I could think of is to disregard using the model hook completely, and put all of the loading/updating logic into the controller.

Another option I had considered is that i could still split the logic between the route and controller, but I keep the route dumb and let it overwrite the model. Instead of rendering the model directly, I add another array in the controller which it knows to keep appending to whenever the model changes.

Anyways, I'm not sure if the above made sense, but infinite scrolling seems like a trendy UX thing these days and if there is a conventional way to do this in Ember it seems like a good thing to know!

Hope to hear your opinions!

taras commented 8 years ago

Given the data-down actions-up principles combined with the idea that the route should handle actions related to updating the model, and the controller should handle actions from the user etc. It seems like the route should be maintaining the state of the count and offset parameters used to issue the store.findQuery command and the controller should know when user needs more data and invoke the actions in the route which should update the model with the next page of data. That being said, I'm just guessing and would be interested to see how other people do this.

This seems like the best option to me.

There is a very good infinity scroll addon available by @hhff. ember-infinity provides a {{infinity-loader}} component which shows the loading icon and triggers the model to load data and Route mixin that handles complexity related to asynchronously loading the data.

There is room to make this addon more data-down actions-up with Ember 2.0 concepts. One of the limitations that the current code has is that it's limited to 1 infinite scroll per page(I could be wrong about this). It also hides a lot of the logic related to querying data in the mixin and the component. I would like this functionality to be more exposed. Ember 1.13 introduced stateful helpers, which we could use to handle the asynchronous loading complexity and expose the loading state of the active query. This might make it possible for us to eliminate the need for Route Mixin and make the {{infinite-loader}} component much simpler.

With all of that said, I think ember-infiity is an excellent addon for doing Infinite Scroll today. Give it a shot :)

hhff commented 8 years ago

:+1: if there's anything missing, hit us with a PR!

taras commented 8 years ago

@hhff I think it's too early to do this refactoring. I would like to see what routable components are going to look like and possibly wait for ListView to be finished(which should happen soon). When those 2 things are complete, doing Infinite Scroll in Ember will be very different than it is today.

hhff commented 8 years ago

oh sorry i didnt read the whole thread! was just saying hi :smile:

taras commented 8 years ago

hi @hhff :)

hhff commented 8 years ago

but yes! big plans for ember infinity when routeable components lands! we're also working to expose some its internals for easier customization.

one dude wanted to do infinite scroll in both directions - we were chatting about list view for that. fun stuff!

taras commented 8 years ago

@mattmazzola do you have any further question about this?

mattmazzola commented 8 years ago

Oh sorry. No, no further questions. You can close it if needed. I wasn't sure what the protocol was for these AMA style issues.