Skip to content

Commit

Permalink
Doc review changes
Browse files Browse the repository at this point in the history
- Fix typos
- Update example to actually work
  • Loading branch information
Stenerson committed May 17, 2017
1 parent 2859a7b commit 505c5dd
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,37 +216,37 @@ const normalizedData = normalize(data, tweet);
}
```

#### `idAttribute` Usage

When passing the `idAttribute` a function, it should return the IDs value.

For Example:

```js
const myData = {
patrons: [
{ id: 1, guest_id: null, name: "Esther" },
{ id: 1, guest_id: 22, name: "Tom" },
]
};
const data = [
{ id: '1', guest_id: null, name: 'Esther' },
{ id: '1', guest_id: '22', name: 'Tom' },
];

const patronsSchema = new schema.Entity('patrons', undefined, {
// idAttribute *functions* must return the ids **value** (not key)
idAttribute: value => value.guest_id ? `${value.id}-${value.guest_id}` : value.id,
});

normalize(myData, [patronsSchema]);
normalize(data, [patronsSchema]);
```

#### Output

```js
{
entities: {
patrons: {
1: { ... },
1-22: { ... },
}
},
result: [1, 1-22]
entities: {
patrons: {
'1': { id: '1', guest_id: null, name: 'Esther' },
'1-22': { id: '1', guest_id: '22', name: 'Tom' },
}
},
result: ['1', '1-22']
}
```

Expand Down

0 comments on commit 505c5dd

Please sign in to comment.