MVC Workflow
User
Notifies
Model action
View
Updates
Controller Updates
• Tracks the app’s state
Router • Affects the application’s view hierarchy
• Mediates between the MVC components
Serialize
URL Usable app state
Deserialize
7
Ember.Object
• Enhanced JavaScript object model
• Computed Properties (synthetizes
properties)
• Observers (reacts to changes)
• Bindings (syncs objects)
Always access properties
using get and set
10
Ember.Object
var App = Ember.Application.create();
App.Person = Em.Object.extend({
firstName: null,
lastName: null,
fullName: function(){
return this.get('firstName') + " " + this.get('lastName');
}.property('firstName', 'lastName')
}); Computed Property
var john = App.Person.create({
firstName: "John",
lastName: "Doe"
});
john.get("fullName"); // John Doe
What about computed property for arrays, hãn?
femalesCount: function() {
http://jsfiddle.net/cBWsr/2/ var people = this.get('people');
return people.filterProperty('isFemale', true).
get('length');
}.property('people.@each.isFemale')
11
Ember.Object
var App = Ember.Application.create();
App.Person = Em.Object.extend({
login: null,
firstName: null,
changedFirstName: function(){
this.set('login', this.get('firstName').toLowerCase());
}.observes('firstName')
}); Observer
var john = App.Person.create();
john.set('firstName', 'John');
john.get("login"); // john
http://jsfiddle.net/X7QBU/3/
12
Time for Dojo
• Scrum board
• Stories and tasks (executed by a person)
• I want to create stories (tasks)
• I want to edit stories (tasks)
• I want to delete stories (tasks)
• I want to assign a task for me
• No server integration (for now)
Next dev-day /o/
(ember-data)
18
C for Controller
• Controller simple controller
• ObjectController support to manipulate
an Object
• ArrayController support to manipulate a
collection
25
C for Controller
Accessing the content
App.ContactController = Em.ObjectController.extend({
someProperty: 'cool-value',
destroyRecord: function() {
this.get('content').destroy();
}
});
pushing a object to a controller’s collection
App.ContactsController = Em.ArrayController.extend({
createContact: function(name) {
push
var contact = App.Contact.create({ name: name });
this.pushObject(contact);
},
});
Remember that all
binding’s magic apply to
Controllers
26
V for View
• Always associated with a template
• Your friend when dealing with browser
events
• touch (touchStart), keyboard (keyDown),
mouse (mouseDown), form (submit), drag
and drop (dragStart),
28