I didn't write but rather I'm reviewing the following Lightning JS function:
InitializeComponent : function (component) {
var recId = component.get("v.recordId");
var action = component.get("c.Init");
action.setParams({ "recordId" : recId });
action.setCallback(this, function(response) {
var resp = response.getReturnValue();
if (component.isValid()) {
// Success Code }
},"SUCCESS");
action.setCallback(this, function(response) {
// Error Code
},"ERROR");
$A.enqueueAction(action);
}
I've never seen and am trying to understand the way successes and failures of server side actions are being handled in this code.
It's less intuitive to me (but maybe more efficient?) than the developer guide's way here:
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
// do something with return value
} else if (state === "INCOMPLETE") {
// do something
} else if (state === "ERROR") {
// do something with error
}
});
I don't understand how setting up two call backs, making the SUCCESS action state an additional parameter in one and ERROR in the other, handles what to do in each of those conditons.