August 03, 2017

Better encapsulate conditionals

Bad:

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

Good:

functionshouldShowSpinner(fsm, listNode) {
  returnfsm.state==='fetching'&&isEmpty(listNode);
}

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