Skip to content

Commit

Permalink
Better example
Browse files Browse the repository at this point in the history
  • Loading branch information
nvie committed Mar 18, 2019
1 parent f9a4ae2 commit d108ba9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,13 @@ a common field (like a `type` field) that lets you distinguish members.
The following two decoders are effectively equivalent:

```javascript
const d1: Decoder<Foo | Bar> = dispatch('type', { foo, bar });
const d2: Decoder<Foo | Bar> = either(foo, bar);
type Rect = {| __type: 'rect', x: number, y: number, width: number, height: number |};
type Circle = {| __type: 'circle', cx: number, cy: number, r: number |};
// ^^^^^^
// Field that defines which decoder to pick
// vvvvvv
const shape1: Decoder<Rect | Circle> = dispatch('__type', { rect, circle });
const shape2: Decoder<Rect | Circle> = either(rect, circle);
```

But using `dispatch()` will typically be more runtime-efficient than using
Expand Down

0 comments on commit d108ba9

Please sign in to comment.