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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值