Skip to content

Commit

Permalink
Docs: decorate - compose decorators for a single prop (#1686)
Browse files Browse the repository at this point in the history
* docs: Add example for composing decorators

This is documentation for changes in
#1652

* Update api.md

* use single quotes

* Update api.md
  • Loading branch information
Ramy Ben Aroya authored and mweststrate committed Aug 17, 2018
1 parent 6e8f14f commit 8543751
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/refguide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,25 @@ decorate(TodoList, {
})
```

For applying multiple decorators on a single property, you can pass an array of decorators. The decorators application order is from right to left.
```javascript
import { decorate, observable } from 'mobx'
import { serializable, primitive } from 'serializr'
import persist from 'mobx-persist'

class Todo {
id = Math.random();
title = '';
finished = false;
}

decorate(Todo, {
title: [serializable(primitive), persist('object'), observable],
finished: [serializable(primitive), observable]
})
```
Note: Not all decorators can be composed together, and this functionality is just best-effort. Some decorators affect the instance directly and can 'hide' the effect of other decorators that only change the prototype.


## Computed values

Expand Down

0 comments on commit 8543751

Please sign in to comment.