This commit is contained in:
Rico Sta. Cruz 2016-12-12 14:24:49 +11:00
parent 006fac7c97
commit a30e5affaf
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 18 additions and 0 deletions

18
mobx.md
View File

@ -11,6 +11,7 @@ import {observable, computed} from 'mobx'
class Page {
@observable title = ''
@observable published = false
@observable author = null
@computed get authorName () {
return this.author || 'Anonymous'
@ -71,6 +72,23 @@ class Foo {
}
```
### expr()
```js
// A temporary computed value. Its result is cached.
render () {
const isPublished = expr(() => page.published === true)
if (isPublished) { ... }
}
```
## [Modifiers](http://mobxjs.github.io/mobx/refguide/modifiers.html)
- `asMap(obj)` - JS map (dynamic keys)
- `asReference(fn)` - don't observe me
- `asStructure(obj)` - JS object (observe as deepEqual)
- `asFlat(array)` - JS array (observe its children)
## React
```js