Skip to content

Commit

Permalink
Reproduce bug
Browse files Browse the repository at this point in the history
Clicking button updates Ember Data model attribute `num`. The tracking
for the getter `title` works on first update, but subsequently fails
to update the template.

If instead of using `@attr` we use `@tracked`, clicking the button
any number of times will always update the template.
  • Loading branch information
wongpeiyi committed Aug 11, 2019
1 parent df6e68c commit 6d8b8f1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
11 changes: 11 additions & 0 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';

export default class ApplicationController extends Controller {

@action
changeTitle() {
this.model.num = Math.random();
}

}
18 changes: 18 additions & 0 deletions app/models/post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import DS from 'ember-data';
// import { tracked } from '@glimmer/tracking';

const { Model, attr } = DS;

export default class Post extends Model {

// This doesn't work after the first property change:
@attr() num;

// This works:
// @tracked num;

get title() {
return `Post ${this.num}`;
}

}
9 changes: 9 additions & 0 deletions app/routes/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Route from '@ember/routing/route';

export default class ApplicationRoute extends Route {

model() {
return this.store.createRecord('post');
}

}
6 changes: 2 additions & 4 deletions app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{{!-- The following component displays Ember's default welcome message. --}}
<WelcomePage />
{{!-- Feel free to remove this! --}}
<h1>Title: {{this.model.title}}</h1>

{{outlet}}
<button {{action "changeTitle"}}>Click me a few times</button>

0 comments on commit 6d8b8f1

Please sign in to comment.