I have that function which gets data from API (getFollowedArtistsAdapter) until it's not the last page of results. I want to make it all as one Promise. But when I look at this function it seems to be illegible and unnecessarily convoluted.
const getArtists = () => {
  let afterGet = null;
  let items = [];
  return new Promise(function promiseCallback(resolve, reject) {
    const afterParam = afterGet ? {limit: 50, after: afterGet} : {limit: 50};
    getFollowedArtistsAdapter(afterParam)
      .then((data) => {
        items = items.concat(data.artists.items);
        if(data.artists.next){
          afterGet = data.artists.items[data.artists.items.length - 1].id;
          promiseCallback(resolve, reject);
        } else {
          return updateStoreArtists(items).then(() => resolve());
        }
      });
  });
}
Any ideas how to split it?
 
    