msgraph-sdk-javascript icon indicating copy to clipboard operation
msgraph-sdk-javascript copied to clipboard

PageIterator: matain the state of previous calls

Open plamber opened this issue 1 year ago • 4 comments

Feature Request

Maintain the state of all previous calls in the PageIterator.

Is your feature request related to a problem? Please describe

We are using the PageIterator to create an "Infinite Scroll" capability on our SPA application. Unfortunately, when iterating, we have to maintain the state of previous calls in a separate array.

Describe the solution you'd like

Expose an array of objects with all the results returned by the PageIterator.

Describe alternatives you've considered

We created a wrapper around the PageIterator to save the previous state of all results in an array.

plamber avatar Oct 02 '22 09:10 plamber

@plamber Thank you for initiating this request!

This will be an essential improvement to the PageIterator.

nikithauc avatar Oct 03 '22 22:10 nikithauc

I'm curious here. Why do you keep all those items once "processed"?

sebastienlevert avatar Oct 04 '22 00:10 sebastienlevert

Hi @sebastienlevert, This is required if you want to create an infinite scroll effect.

For example, you show a list of the first 10 items of a Graph query to a user. The user scrolls down the page and before we are reaching the end of the 10 items we will trigger another query that returns the next 10 items. In REACT, if you want to re-render the page with 20 items, you need to keep the state of the 20 items to have this infinite scroll logic. You do not want to re-execute a query just because the user scrolls up the page.

Hope this clears the use case.

Cheers

plamber avatar Oct 04 '22 03:10 plamber

Oh makes sense. You don't append 10 new results, you re-render, but with the 20 results. It's an interesting use case!

sebastienlevert avatar Oct 05 '22 13:10 sebastienlevert