Is there a better way of doing it?


#1

I have this code:

new Ember.RSVP.Promise((resolve) => {
	let promise = myList.pushObject(book);
	resolve(promise);
}).then(() => {
	this.send('scrollToBottom', '#myList');
});

Is there a better way of doing it?


#2

yes:

myList.pushObject(book);
Ember.run.schedule('afterRender', this, 'send', 'scrollToBottom', '#myList');

The promise code is not doing anything except happening to be async. It may or may not pause long enough to allow rendering. Instead, use the runloop to do stuff at the right time.


#3

RSVP Promise resolves in the same run loop. So it’s not really async anyway.


#4

@lightblade is this an aswer to me?