3 category: JavaScript libraries
11 import {observable, computed} from 'mobx'
14 @observable title = ''
15 @observable published = false
16 @observable author = null
18 @computed get authorName () {
19 return this.author || 'Anonymous'
30 // do ajax/async here if you like
38 const person = observable({
39 name: 'Ella Fitzgerald'
44 const temp = observable(23)
55 import {autorun, autorunAsync, when} from 'mobx'
61 // Runs it, finds out what it accessed, then observe those
63 console.log(page.title)
73 () => !this.isVisible,
74 () => this.doSomething())
82 // A temporary computed value. Its result is cached.
84 const isPublished = expr(() => page.published === true)
85 if (isPublished) { ... }
89 ## [Modifiers](http://mobxjs.github.io/mobx/refguide/modifiers.html)
91 - `asMap(obj)` - JS map (dynamic keys)
92 - `asReference(fn)` - don't observe me
93 - `asStructure(obj)` - JS object (observe as deepEqual)
94 - `asFlat(array)` - JS array (observe its children)
101 import { observer } from 'mobx-react'
104 class PageView extends React.Component {
106 return <div>{this.props.page.title}</div>
110 <PageView page={page} />
113 ### Functional components
116 import { observer } from 'mobx-react'
118 const PageView = observer(({page}) => {
119 <div>{page.title}</div>
122 <PageView page={page} />
127 - <https://github.com/mobxjs/mobx>