Skip to content

Instantly share code, notes, and snippets.

@balinterdi
Last active January 23, 2020 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balinterdi/caa8253ecf4e038e1681f46010efb544 to your computer and use it in GitHub Desktop.
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
<div class="h-screen w-full bg-blue-800 text-gray-100">
<div class="w-full xl:w-1/3 mx-auto">
<div class="h-12 flex items-center mb-4 border-b-2">
<h1 class="font-bold text-2xl">Rock & Roll <span class="font-normal">with Ember.js</span></h1>
</div>
<div class="w-full">
<div class="">
<ul>
{{#each @model as |song|}}
<li>
{{song.name}} by {{song.band}}
<span class="float-right">{{song.rating}}</span>
</li>
{{/each}}
</ul>
</div>
</div>
</div>
</div>
{{outlet}}
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