-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
40 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |