In my Item
model, I have async methods such as delete
, rename
, etc. Whenever one of these methods is being executed, I display a spinner on the views to indicate loading. Since there are multiple async methods in the Item
model, I find myself repetitively including code like this in my controller:
function delete() {
isRequesting = true;
item.delete().then(function() {
isRequesting = false;
}
}
function rename() {
isRequesting = true;
item.rename().then(function() {
isRequesting = false;
}
}
These instances of isRequesting=
clutter up my code and can also be easily forgotten. On the other hand, I have a singleton called fileNavigator
with many async methods, for which I use events to manage requesting status:
fileNavigator.on(FileNavigatorEvents.REQUESTING, function (event, requesting) {
isRequesting = requesting;
});
This approach eliminates the need to manually handle isRequesting
when working with the async methods of fileNavigator
. My question is if there is a similar pattern that could be applied to non-singleton instances of Item
?