File tree
Expand file treeCollapse file tree1 file changed
+21
-0
lines changed Expand file treeCollapse file tree1 file changed
+21
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -598,6 +598,27 @@ var totalOutput = programmerOutput
|
598 | 598 | ```
|
599 | 599 | **[⬆ back to top](#table-of-contents)**
|
600 | 600 |
|
| 601 | +### Encapsulate conditionals |
| 602 | + |
| 603 | +**Bad:** |
| 604 | +```javascript |
| 605 | +if (fsm.state === 'fetching' && isEmpty(listNode)) { |
| 606 | +/// ... |
| 607 | +} |
| 608 | +``` |
| 609 | + |
| 610 | +**Good**: |
| 611 | +```javascript |
| 612 | +function shouldShowSpinner() { |
| 613 | +return fsm.state === 'fetching' && isEmpty(listNode); |
| 614 | +} |
| 615 | + |
| 616 | +if (shouldShowSpinner()) { |
| 617 | +// ... |
| 618 | +} |
| 619 | +``` |
| 620 | +**[⬆ back to top](#table-of-contents)** |
| 621 | + |
601 | 622 | ### Avoid negative conditionals
|
602 | 623 |
|
603 | 624 | **Bad:**
|
|
You can’t perform that action at this time.
0 commit comments