`

mobx 常用注解

阅读更多

mobx 常用注解

@computed

Decorator that can be used on ES6 or TypeScript derivable class properties to make them observable. The @computed can only be used on get functions for instance properties.

@computed 可以用在 ES6 或 TypeScript 属性上面,使属性可以被观测(observable).

而且@computed 仅仅使用在 get方法上

 

Use @computed if you have a value that can be derived in a pure manner from other observables.

如果有一个值是从被观测的变量(observables)中衍生出来的,那么就使用@computed

use @computed if you want to reactively produce a new value that can be used by other observers

如果你需要产生一个新变量值被其他观察者(observers)使用,那么就使用@computed

 

@computed can be parameterized. @computed({asStructure: true}) makes sure that the result of a derivation is compared structurally instead of referentially with its preview value. This makes sure that observers of the computation don't re-evaluate if new structures are returned that are structurally equal to the original ones. This is very useful when working with point, vector or color structures for example. It behaves the same as the asStructure modifier for observable values.

 

 

Property getters will be automatically turned into derived properties, just like @computed would do.

getter方法会自动加上@computed

Deprecated Argumentless functions will be automatically turned into derived properties, just like @computed would do.

无参方法会自动加上@computed.

注意@computed get 不要忘了return

参考:

https://mobxjs.github.io/mobx/refguide/object.html

https://mobxjs.github.io/mobx/refguide/computed-decorator.html

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics