@ samselikoff
GET wikipedia.org/napolean -->
GET wikipedia.org/France -->
Route request, fetch data
<-- HTML/CSS
"Can we make that form AJAX?"
"Let's add infinite scrolling"
"Dynamic dropdowns"
"Why don't we prefetch that data"
GET github.com -->
Route request, fetch data
<-- HTML/CSS
<-- JS
AJAX/non-AJAX request -->
<-- JSON/HTML
GET gmail.com -->
Fetch JS app, initial data
<-- HTML/CSS
<-- JS app, templates
AJAX request -->
<-- JSON
JS now controls
Router.map(function() {
this.route('inbox');
this.resource('message', {path: '/:message_id'});
this.resource('contacts');
});
export default Ember.Route.extend({
model: function() {
return Ember.getJSON('/contacts');
}
});
<h1>{{title}}</h1>
{{#each contact in contacts}}
<div class='contact-card'>
<h2>{{contact.name}}</h2>
<h3>{{contact.email}}</h3>
</div>
{{/each}}
// controllers/contact.js
export default Ember.ObjectController.extend({
fullName: function() {
return this.get('firstName') + ' ' + this.get('lastName');
}.property('firstName', 'lastname')
});
// templates/contacts.hbs
{{#each contact in contacts}}
<p>{{contact.fullName}}</p>
{{/each}}
// views/profile-card.js
export default Ember.View.extend({
didInsertElement: function() {
this.$().somePlugin();
}
});
// templates/contacts.hbs
{{#each contact in contacts}}
{{view 'profile-card'}}
{{/each}}
<div class="sidebar">
<label >Select a date</label>
{{date-picker selectedDate=currentMonth mode='month'}}
</div>
// templates/index.hbs
<div>
<a id='delete-contact' {{action 'deleteContact' this}}>Delete</a>
</div>
// a-view.js, a-component.js, a-controller.js, a-route.js
actions: {
deleteContact: function(contact) {
contact.delete();
}
}
// models/contact.js
export default DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
age: DS.attr('number'),
addresses: DS.hasMany('address')
});
// some-route.js
model: function() {
return this.store.find('contact');
}
ember-cli