I have a service called local-storage that has an init method that sets a local property to the content that is in local storage using a local storage adapter.
init: function() {
this.getUser();
},
getUser: function() {
let id = this.get('session.userId');
if (!isEmpty(id)) {
this.get('store').findRecord('user', id).then((user)=>{
this.set('user',user);
this.notifyPropertyChange('user');
});
}
},
The findRecord here is looking up local storage not making a network call.
In my index route I'm attempting to use a value on that property to load a model from the network, but when the model is attempting to get the data over the network it fires before the local-storage service has set the user. If I console log in the init method and at the beginning of the model hook I can see the index route is calling it's model hook before the service has set the user to what the local storage adapter has returned.
This was working before and I'm not sure what has happened but I really need this service to be completely set before I attempt to load data as most of the data is going to be dependent on that use property being set in the service.
Aucun commentaire:
Enregistrer un commentaire