Proper way to handle reloading of data?


#1

it seems like there is no consistent way to reload data and is done on a situation by situation basis,

a few of the strategies I had to employ so far to get my reload on pages working properly

I have to refresh the route after a modal form submits and saves and subsequently closes to update the table on the index page with the new record without having to refresh the page to see it.

var route = this.container.lookup("route:posts.index");
route.refresh();

I have a few of my form submits transition to a route after a proper save and in that route I have an afterModel hook that I use to reload the data

afterModel: function(model, transition) {
model.reload();
model.constructor.eachRelationship(function (key, relationship) {
	if (relationship.kind === 'hasMany') {
		model.get(key).reload();
 	}
});
return model;
}

I have a different type of confirmation modal related to deleting of a record and I have to call reload twice directly on the parent model of my page to reflect the accurate new data related elsewhere on the page caused by the deletion, for some odd reason .reload() once doesn’t work properly but twice fixes the problem

 model.reload();
 model.reload();

these are just 3 examples where I had to debug in and find a working solution to handle a reload properly, had to do a few more other ones also

what solutions have other people come up with that work in a more unified way? I have found that a simple .reload() doesn’t fix your problems most of the time, a full page refresh always fixes your problems (not practical) and you have to find some odd solutions to fix the problems


#2

I used in my app the following situation: Put a pooling to verify and invalidate unload() my data if it was modified.

Before save() model, update it. If it was modified just update e don’t save at all.