[OPEN-ILS-DEV] prototype staff client, feedback/5
steven
schan at vcn.bc.ca
Tue Feb 11 15:30:52 EST 2014
Continuing to give feedback to the prototype staff client.
Feedback/5 is a short note about the use of promises in the code base. I
see the following code pattern several times, for example in
staff/services/auth.js and staff/cat/bucket/record/app.js:
async1(a1)
.then( function (x1) {
return async2(a2).then( function (x2) {
return sync(a3);
});
});
where async1() and async2() are asynchronous function calls that return
promises. They are called in sequence, and the final synchronous
function sync() is called only after async2() is finished. The then
method is used but it is not chained, which results in extra code
indentation that could be avoided, as follows:
async1(a1)
.then( function (x1) {
return async2(a2);
})
.then( function (x2) {
return sync(a3);
});
I suggest the 2nd code pattern be used where ever possible, because it
makes the code easier to understand.
--
More information about the Open-ils-dev
mailing list