javascript – Aurelia的computedFrom与一个对象

前端之家收集整理的这篇文章主要介绍了javascript – Aurelia的computedFrom与一个对象前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个具有属性会话的状态对象,该属性可以是对象或null.

我不想对isSessionActive()getter进行脏检查,所以我想使用computedFrom().但是,当此对象更改时,computerFrom()似乎不会触发,除非之前未定义.

如果我的州商店没有专门的isSessionActive布尔属性,我可以这样做吗?

  1. @autoinject
  2. export class Home {
  3. firstName: string = "user";
  4. private state: State;
  5. constructor(private store: Store) {
  6. store.state.subscribe(
  7. response => this.state = response
  8. )
  9. }
  10. @computedFrom('state.activeSession')
  11. get isSessionActive() {
  12. return this.state.activeSession !== null;
  13. }
  14. }
最佳答案
我最后只是做了以下事情:

  1. isSessionActive: boolean = false;
  2. constructor(private store: Store) {
  3. store.state.subscribe(
  4. response => {
  5. this.state = response;
  6. this.isSessionActive = response.activeSession !== null;
  7. }
  8. )
  9. }

猜你在找的JavaScript相关文章