With events being fired and also handled in a helper, I have multiple copies of simple constants and so there is some risk of silent failure due to typos.
Given the helper functions are defined as properties of an object, it appears possible to define constants in the same way and reference them via the helper instance:
({
ADD_ACTION : 'ADD',
EDIT_ACTION : 'EDIT',
onRowAction : function(component, event, helper) {
var action = event.getParam('action');
switch(action.name) {
case this.ADD_ACTION:
...
case this.EDIT_ACTION:
...
}
},
})
But is there a better way to share constants between helper methods in a single Lightning Component?
PS
itzmukeshy7's use of objects to group the constants is a nice refinement:
({
actions: {
ADD: 'ADD',
EDIT: 'EDIT'
},
onRowAction : function(component, event, helper) {
var action = event.getParam('action');
switch(action.name) {
case this.actions.ADD:
...
case this.actions.EDIT:
...
}
},
})