• Core Concepts
• Public API
• Adapter/Serializer API
• Internals
Slide 3
Slide 3 text
Why Ember Data?
Slide 4
Slide 4 text
Things It‘s Still
Hard to Do in 2012
(which is bullshit)
Slide 5
Slide 5 text
Creating two records, setting
up a relationship between
them, then saving them.
Slide 6
Slide 6 text
Easily starting with fixture
data if your server isn‘t
ready yet.
Slide 7
Slide 7 text
Changing the JSON
representation of your model
without changing app code.
Slide 8
Slide 8 text
Only loading models you
don‘t have cached.
Slide 9
Slide 9 text
Keeping the DOM
up-to-date with model changes.
Slide 10
Slide 10 text
Dynamically switching
between a server and
offline cache.
Slide 11
Slide 11 text
Using awesome new browser
features like WebSockets and
TypedArrays.
Slide 12
Slide 12 text
These problems are
SO
COMMON!
Slide 13
Slide 13 text
Why do we all do
it by hand?!
Slide 14
Slide 14 text
Convention Over
Configuration
Slide 15
Slide 15 text
conventional
conventional
{
json: "lol"
}
WHY IS THIS
NOT CONVENTIONAL?!?!
Slide 16
Slide 16 text
Ember Data
Slide 17
Slide 17 text
Architecture
Overview
Slide 18
Slide 18 text
Store
Adapter Serializer
Record Record Record Record
Slide 19
Slide 19 text
Store
Adapter Serializer
Record Record Record Record
Server
Semantics
Application
Semantics
Things that wouldn't change if your
backend changed.
I.e., ignoring your server protocol,
how would you ideally model your
data? How do you think about your
models?
Things that are specific to
your server/backend/
persistence layer.
Slide 20
Slide 20 text
Loading a Record
Slide 21
Slide 21 text
Store
Application
App.Post.find(1)
Record
Slide 22
Slide 22 text
Store
Application
Person.find([1, 2, 3])
RecordArray
Slide 23
Slide 23 text
Store
Application
Person.find()
RecordArray
Slide 24
Slide 24 text
// State for '/posts'
App.PostsState = Ember.State.extend({
setupControllers: function() {
var posts = App.Post.find();
this.set('controller.content', posts);
}
});
Slide 25
Slide 25 text
Store
Application
App.Post.find(1)
Adapter
Record
loading
isLoaded
isDirty
isSaving
isDeleted
isError
isNew
isValid
These are derived from the
current state object, which
is awesome!
Slide 59
Slide 59 text
• Each record has an associated
state manager.
• The store does not make
changes to records directly.
• Instead, events are sent to the
record.
• The record responds based on
its current state.
Slide 60
Slide 60 text
Uncaught Error: could not
respond to event setProperty in state
rootState.loaded.created.inFlight.
=
You tried to change a record
while it was being saved.
• Are relationships saved in
the parent or the child?
• What payloads are sent
to what URLs?
• What actions map to
what HTTP verbs?
• What is the name of the
primary key?
• What are the names of
attributes?
• Are objects embedded or
referred to by ID?
Serializer
Adapter
Slide 66
Slide 66 text
Serializer
JSONSerializer
RESTSerializer
Slide 67
Slide 67 text
Serializer
Transform Values
new Date() to
"2007-04-05T14:30"
(and vice versa)