从对象开始计算的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;
        }
    )
}

相关文章