从对象开始计算的Aurela [英] Aurelia's computedFrom with an object

查看:31
本文介绍了从对象开始计算的Aurela的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个state对象,它有一个属性session,该属性可以是objectnull

我不想对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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆