Last active
January 23, 2020 14:47
-
-
Save balinterdi/caa8253ecf4e038e1681f46010efb544 to your computer and use it in GitHub Desktop.
Refresh a route's @model – this one re-renders the template with the new song
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
import Route from '@ember/routing/route'; | |
let songs = [ | |
{ name: 'Black Dog', band: 'Led Zeppelin', rating: 3 }, | |
{ name: 'Yellow Ledbetter', band: 'Pearl Jam', rating: 4 }, | |
{ name: "Baba O'Riley", band: 'The Who', rating: 4 }, | |
]; | |
let count = 0; | |
export default class ApplicationRoute extends Route { | |
model() { | |
if (count === 0) { | |
count++; | |
setTimeout(() => { this.refresh() }, 3000); | |
return songs; | |
} else { | |
return [...songs, { name: 'Brother', band: 'Alice in Chains', rating: 5 }]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment