0

I have the following array:

eligible_students: function() {
    self = this;
    this.store.find('user', App.CurrentUser.get('id')).then(function(user) {
            console.log(user);
            var students = user.get('students').then(function(students) {
                console.log(students);
                var results = user.get('students').map(function(item) {
                    return {student: item, queued: false};
                });
                console.log(results);
                self.set('eligible_students', results);
            });
        }
    );
    return [];
}.property('App.CurrentUser.id')

Everything works fine, but there's a stutter when this is rendered, since I'm adding the results after returning an empty array. Is there a way to do this that inherently takes advantage of Ember Promises? Or some other beautiful functionality?

I'm happy to provide more information on request :)

blaineh
  • 2,263
  • 3
  • 28
  • 46
  • What do you mean by stutter? Just the fact that it happens after the rest is rendered? – Kingpin2k Jan 02 '14 at 04:23
  • Yeah it's slow, but maybe that's to be expected? – blaineh Jan 02 '14 at 04:31
  • slow after the network response? the students response comes back and it takes a while to render the list of students? or the process of drilling down and getting the eligible students takes time? – Kingpin2k Jan 02 '14 at 04:48
  • Well the list renders as empty for a second, and then renders as full. I'm realizing the delay is probably inevitable, but I would still like a more elegant way to make this happen. – blaineh Jan 02 '14 at 15:46

1 Answers1

1

If you want to wait for the page to render until the users are loaded, then you should use the model hook in the router. You could use Ember.RSVP.hash (https://stackoverflow.com/a/20523510/1234490) to return multiple models if necessary. Then in the controller you could add a function eligibleStudens. I think it should be in the controller since it is along the lines of a completedTodos function for example.

This way you won't notice the stuttering. Lemme know if it works:)

Community
  • 1
  • 1
Thomas Brus
  • 931
  • 5
  • 11