mercredi 6 avril 2016

Fetch from DB asynchronously in Ember.js

I have an application that starts from a login route, checks credentials against a backend, fetches user information asynchronously from either the backend or offline storage and then transitions to another route where that user information is used to format a date. The problem lays when I refresh the page once logged in. The settings are lost and falls back to default formatting.

Code for fetching the user information is inside a service and returns a promise.

fetchUserInfo: ->
  new Ember.RSVP.Promise (resolve) =>
    settings = @get('store').find 'settings'
    @set 'settings', settings
    resolve(settings)

My question is, when I refresh the webpage where should I place this fetching code again, is it good practice to just put it in init in the controller?




Aucun commentaire:

Enregistrer un commentaire