In the code bellow, the third parameter is a promise, that when resolved (or rejected) will execute a callback function.
There we receive a "Maximum call stack size exceeded" when Locker service is active.
var dataService = {
request : $A.getCallback(function(actionName, params, defer) {
var componentActionName = 'c.' + actionName;
var action = component.get(componentActionName);
action.setParams(params);
action.setCallback(this, function(a) {
try {
var state = a.getState();
if (state === 'SUCCESS') {
defer.resolve(a.getReturnValue());
}
else if (state === 'ERROR') {
var errors = a.getError();
if (errors) {
defer.reject(errors[0].message);
} else {
defer.reject('Lightning server side unknown error');
}
}
} catch (ex) {
console.log('### Exception: ');
console.log(ex);
}
});
$A.enqueueAction(action);
})
Any idea what might be going on?
$A.getCallback
in an object which is not recommended in the developer guide: "Don't save a reference to a function wrapped in $A.getCallback(). If you use the reference later to send actions, the saved transaction state will cause the actions to be aborted." I don't know if that could be part of the problem or not.