0

So I have API fetch request to return back with a list of 1000 objects..=> I use saga yield put API to update the state in reducer. Now it is working well but I feel like there is a big room for speed optimization like lazy-loading.

Has anyone tried to update and pass the result to the Store in reducer as they come?

here is my pseudo code:

 export const API_REQUEST = () => {
    const API_ENDPOINT = `${API_URL}/api/2500/banners`
       return fetch(API_ENDPOINT, {
          method: "GET",
          dataType: "json",
       }).then(function(response) {
       if (response.status >= 200 && response.status < 300) {
          return response.json().then(function(results) {
          let banners = results.banners;
          return banners
  })
}

const banners = yield call(API_REQUEST)
yield put({
    type: "BANNERS_LOADED",
    banners
  })

and the above call updates the store reducer and subsequently updates the UI in browser. I am trying to implement lazy load..or something similar. if there is any suggestion, I would like to hear about it.

thanks!

slopeofhope
  • 686
  • 2
  • 6
  • 21
  • You could page your data sets and dispatch events once the user reaches the bottom (via scrolling for example). – Mario Tacke Oct 04 '16 at 20:45
  • Of course, you can add items as they come, either as singles or in batches. The details might depend on your API. Paginating you calls to the API and executing new calls as long as a response is available in one simple way to do it. You can also look into using the channels interface if you are working with server sent events, streams and so forth. – VanDanic Oct 05 '16 at 14:20
  • So as a dev that is how i would also explain to a dev but executing it is a different story. So based on the code i have put, how would you add items as they come or do u have something else in mind? – slopeofhope Oct 05 '16 at 14:25
  • Possible duplicate of [How is multitasking achieved in Redux Middleware?](http://stackoverflow.com/questions/41456031/how-is-multitasking-achieved-in-redux-middleware) – Paul Sweatte Jan 18 '17 at 21:31

0 Answers0