Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4831

Run loop with setter in init after promise resolves

$
0
0

@Scott_Newcomer wrote:

This component handles a bunch of different shapes of arrays. plain array, promise, promise proxy, plain array with promises in it (which can be filtered). Some details hidden, but in init, it tries to render the collection (if plain array) as fast as possible (fastboot) and when the browser takes over then create gallery in didInsertElement (since using document.querySelector).

init() {
  // Because we may need to access a promisified object in the template, we need
  // to resolve before handing off
  this.get('promisifiedItems')
   .then(resolvedItems => this.set('resolvedItems', filterRejected(resolvedItems)))
   .catch(() => this.set('hasErrored', true))
   .finally(() => this.set('isDoneLoading', true));
},
 
didInsertElement() {
  // next only works, scheduleOnce is too early
  scheduleOnce('afterRender', this, () => {
    this.get('promisifiedItems').then(() => {
	  createGallery(); //  grabs each painted item and attaches css transformations
    });
  });
}

In a simple test I have, resolvedItems is set before didInsertElement but I can’t use scheduleOnce because resolvedItems has yet to paint. Want it to happen on a tight as schedule as possible so wanted to ask - is this expected (Ember 3.7) and is there some rules about the run loop, setters and painting to glean from this?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4831

Trending Articles