从对象开始计算的Aurela
本教程将介绍从对象开始计算的Aurela的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。
问题描述
我有一个state
对象,它有一个属性session
,该属性可以是object
或null
。
我不想对isSessionActive()
getter进行脏检查,所以我想使用computedFrom()
。但是,computerFrom()
似乎不会在此对象更改时触发,除非它以前是undefined
。
我的状态存储上是否可以在没有专用isSessionActive
布尔属性的情况下执行此操作?
@autoinject
export class Home {
firstName: string = "user";
private state: State;
constructor(private store: Store) {
store.state.subscribe(
response => this.state = response
)
}
@computedFrom('state.activeSession')
get isSessionActive() {
return this.state.activeSession !== null;
}
}
推荐答案
我只是执行了以下操作:
isSessionActive: boolean = false;
constructor(private store: Store) {
store.state.subscribe(
response => {
this.state = response;
this.isSessionActive = response.activeSession !== null;
}
)
}
好了关于从对象开始计算的Aurela的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。