JS - Best Practices (Encapsulate conditionals)

 

Bad :

if (fsm.state === 'fetching' && isEmpty(listNode)) {
      // ...
}

Correct :

function shouldShowSpinner(fsm, listNode) {
      return fsm.state === 'fetching' && isEmpty(listNode);
}

if (shouldShowSpinner(fsmInstance, listNodeInstance)) {  
     // ...
}

 
 

js best practices