In my script, I need to retrieve a dictionary to convert encoded values into names:
$.ajax({
// retrieve dictionary
})
.done(function(dictionary){
// convert encoded values into names
})
.done(function(){
// run my application
});
However, sometimes the dictionary has already been loaded by another application, and in this case I don't need the ajax call:
if (dictionary) {
// convert encoded values into names
// run my application
}
else {
$.ajax({
// retrieve dictionary
})
.done(function(dictionary){
// convert encoded values into names
})
.done(function(){
// run my application
});
}
This if/else statement is rather heavy, is there a way to make it shorter:
// load dictionary if needed
// then run my application
Note: I used the $ sign for my pseudo-code, but I am not necessarily tied to jQuery.