Slide 1

Slide 1 text

REBOOT Ember Data Paul Chavard Capitaine Train September 24, 2013

Slide 2

Slide 2 text

Why ? • Difficult to customize for custom APIs • Fragile States • Competition (Ember Model / EPF)

Slide 3

Slide 3 text

How ? • Remove Dirty Lock • Default merge strategy • Replace Error state with Error flag • Promisification • Containerization

Slide 4

Slide 4 text

Whats New? • push, update and pushPayload • save on hasMany relationships • Serializer / Adapter rewrite

Slide 5

Slide 5 text

Ember Data #ProTips

Slide 6

Slide 6 text

Filters Route model: function() { return this.store.filter(’post’, {}, Ember.K); } Controller searchText: ’’, searchTextDidChange: function() { var searchText = this.get(’searchText’); var filterFunction = Ember.isEmpty(searchText) ? Ember.K : function(record) { return record.get(’title’) .toLowerCase() .match(searchText.toLowerCase()); }; this.set(’model.filterFunction’, filterFunction); }.observes(’searchText’),

Slide 7

Slide 7 text

Batch Saves Save Multiple Models Ember.RSVP.all(post.get(’comments’).invoke(’save’)) .then(function() { alert(’All Saved!’); }, function(reason) { alert(’There was an error because ’ + reason); }); Save Parent Before Child post.save().then(function() { return comment.save(); }).then(function() { alert(’All Saved!’); }, function(reason) { alert(’There was an error because ’ + reason); });

Slide 8

Slide 8 text

Unload Records Unload Single Record this.store.find(’post’, 1).unloadRecord(); Unload Record and its relationships unloadRecord: function() { this.eachRelationship(function(key, relationship) { if (relationship.kind === ’hasMany’) { this.get(key).toArray().invoke(’unloadRecord’); } else { this.get(key).unloadRecord(); } }, this); this._super(); }

Slide 9

Slide 9 text

Ember Extension (Demo)

Slide 10

Slide 10 text

The End