Currently, I am utilizing an if-else statement in my Vuex action to set a default value for a payload property. Specifically, I check if the passed payload object contains a delay property; if it does not, I assign it a default value and handle appropriately.
Is there a more concise approach to achieving this task? I believe there must be a better way.
Below is the code snippet of my action:
showModal ( {commit}, modalPayload ) {
let delay;
if(modalPayload.delay == undefined) {
delay = 3000;
} else {
delay = modalPayload.delay;
}
commit('SHOW_MODAL', modalPayload);
setTimeout(function(){
commit('HIDE_MODAL');
}, delay);
},
Your suggestions are greatly appreciated. Thank you.