Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ember Data REBOOT

Paul Chavard
September 24, 2013

Ember Data REBOOT

Paul Chavard

September 24, 2013
Tweet

More Decks by Paul Chavard

Other Decks in Programming

Transcript

  1. Why ? • Difficult to customize for custom APIs •

    Fragile States • Competition (Ember Model / EPF)
  2. How ? • Remove Dirty Lock • Default merge strategy

    • Replace Error state with Error flag • Promisification • Containerization
  3. Whats New? • push, update and pushPayload • save on

    hasMany relationships • Serializer / Adapter rewrite
  4. 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’),
  5. 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); });
  6. 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(); }