From ee6522e53dae60f0b8b2b8e1f850725562327012 Mon Sep 17 00:00:00 2001 From: Ramy Ben Aroya Date: Wed, 15 Aug 2018 15:13:24 +0300 Subject: [PATCH] docs: Add example for composing decorators This is documentation for changes in https://github.com/mobxjs/mobx/pull/1652 --- docs/refguide/api.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/docs/refguide/api.md b/docs/refguide/api.md index 324f83167..8641880b4 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