glimmerjs / glimmer-application

[MOVED] This package is now part of the Glimmer.js monorepo
https://github.com/glimmerjs/glimmer.js
30 stars 13 forks source link

Tracked property on a service doesn't invalidate tag #87

Closed mixonic closed 7 years ago

mixonic commented 7 years ago

A reproduction appropriate for http://glimmer-playground.netlify.com/.

<div>
  <h1>Welcome to Glimmer!</h1>
  <p>You have clicked the button {{count}} times.</p>
  <button onclick={{action increment}}>Click</button>
  <br>
  Service#isMax: {{service.isMax}}
  <br>
  Component#isMax {{isMax}}
</div>
import Component, { tracked } from '@glimmer/component';

class Service {
  @tracked
  isMax = false;
}

export default class extends Component {

  constructor(options) {
    super(options);
    this.service = new Service();
  }

  @tracked count = 1;

  increment() {
    this.count++;
    if (this.count > 2) {
      this.service.isMax = true;
    }
  }

  @tracked('service.isMax')
  get isMax() {
    return this.service.isMax;
  }
}

Expected: Both {{service.isMax}} and {{isMax}} will toggle to true after passing a count of 2.

Action: Only isMax toggles to true.

mixonic commented 7 years ago

Replaced by https://github.com/glimmerjs/glimmer-component/issues/65