Yes, you can access static variables, but there's no point for your
specific use case. @AuraEnabled is used to expose custom classes and
methods to Lightning. Static variables will be reset between each
transaction, just as they are in Visualforce.
public class Payload {
@AuraEnabled public Integer counter;
}
@AuraEnabled public static Payload someMethod(Payload state) {
if(...) {
state.counter++;
} else {
state.counter--;
}
return state;
}
doSomething: function(component, event, helper) {
var action = component.get("c.someMethod");
action.setParams({ state: component.get("v.state"); });
action.setCallback(function(result) {
// Not included, but remember to check isValid/result status
component.set("v.state", result.getReturnValue());
});
$A.enqueueAction(action);
}
No comments:
Post a Comment