Skip to content

Commit

Permalink
docs: Add example for composing decorators
Browse files Browse the repository at this point in the history
This is documentation for changes in
mobxjs#1652
  • Loading branch information
ramybenaroya committed Aug 15, 2018
1 parent ba941b8 commit ee6522e
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 ee6522e

Please sign in to comment.