From 854375104e9b594c1c9dd1d5e6a570a16dcc4fee Mon Sep 17 00:00:00 2001 From: Ramy Ben Aroya Date: Fri, 17 Aug 2018 17:18:55 +0300 Subject: [PATCH] Docs: decorate - compose decorators for a single prop (#1686) * docs: Add example for composing decorators This is documentation for changes in https://github.com/mobxjs/mobx/pull/1652 * Update api.md * use single quotes * Update api.md --- docs/refguide/api.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/refguide/api.md b/docs/refguide/api.md index 324f83167..2eff8254b 100644 --- a/docs/refguide/api.md +++ b/docs/refguide/api.md @@ -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