Skip to content

Commit 5d969e8

Browse files
committed
Add null case
1 parent 7926caa commit 5d969e8

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
3. [Basics](#basics)
77
4. [Readability](#readability)
88
5. [Side Effects](#side-effects)
9-
6. [User Input](#user-input)
9+
6. [Limits](#limits)
1010
7. [Security](#security)
1111
8. [Performance](#performance)
1212
9. [Testing](#testing)
@@ -318,11 +318,57 @@ assert(date1 === '1/6/2017');
318318
> George Bernard Shaw
319319
320320
### Null cases should be handled
321+
If you have a list component for example, all is well and good if you display a
322+
nice beautiful table that shows all its data. Your users love it and you get a
323+
promotion! But what happens when no data comes back? What do you show in the
324+
null case? Your code should be resilient to every case that can occur. If
325+
there's something bad that can happen in your code, eventually it will happen.
326+
327+
```javascript
328+
class InventoryList {
329+
constructor(data) {
330+
this.data = data;
331+
}
332+
333+
render() {
334+
return (
335+
<table>
336+
<tbody>
337+
<tr>
338+
<th>
339+
ID
340+
</th>
341+
<th>
342+
Product
343+
</th>
344+
</tr>
345+
// We should should something for the null case here if there's
346+
// nothing in the data inventory
347+
{Object.keys(this.data.inventory).map(itemId => (
348+
<tr key={i}>
349+
<td>
350+
{itemId}
351+
</td>
352+
353+
<td>
354+
{this.state.inventory[itemId].product}
355+
</td>
356+
</tr>
357+
))}
358+
</tbody>
359+
</table>
360+
);
361+
}
362+
}
363+
```
321364

322365
### Singular cases should be handled
366+
```javascript
367+
```
323368

324369
### Large cases should be handled
325370

371+
326372
### Commit messages should be clear and accurately describe new code
327373
We've all written commit messages like "Changed some crap", "damn it",
328374
"ugg one more to fix this stupid bug". These are funny and satisfying, but not
@@ -332,7 +378,7 @@ commit. Write commit messages that describe the code accurately, and include
332378
a ticket number from your issue tracking system if you have one. That will make
333379
searching through your commit log much easier.
334380

335-
### The code should what it's supposed to
381+
### The code should do what it's supposed to do
336382
This seems obvious, but most reviewers don't have the time or take the time to
337383
manually test every user-facing change. It's important to make sure the business
338384
logic of every change is as per design. It's easy to forget that when you're

0 commit comments

Comments
 (0)