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

SF Ember.js Meetup 10/30

9bf3a766e037b9d5a4da0a6f9d0f4f68?s=47 tomdale
October 30, 2012

SF Ember.js Meetup 10/30

In this talk, Tom drops some rapid-fire knowledge bombs about Ember Data–what it is, where it's at currently, and what's coming in the pipeline.

9bf3a766e037b9d5a4da0a6f9d0f4f68?s=128

tomdale

October 30, 2012
Tweet

Transcript

  1. None
  2. Ember Data

  3. None
  4. None
  5. UPDATE customers SET salesperson = "Mike" WHERE state = "NH"

  6. None
  7. ActiveRecord

  8. None
  9. None
  10. None
  11. $.getJSON('/posts/1', function(data) { controller.set('content', data); });

  12. None
  13. Ember Data

  14. DS.Store Application Semantics Server Semantics translates DS.Adapter

  15. DS.Adapter DS.Serializer

  16. DS.Adapter DS.Serializer • 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?
  17. What's Next?

  18. Full Time!

  19. Bug Fixes!

  20. Per-Type Adapters

  21. Server Team

  22. find: function(store, type, id) { if (type === App.Post) {

    $.ajax('/enterprise_cms/v134uu5/ db-legacy/posts_endpoint-v2/'+id, 'GET', { success: function(json) { store.load(type, json); } }); } else if (type === App.Comment) { $.ajax('/comments/'+id, 'GET', { success: function(json) { store.load(type, json); } }); } }
  23. DS.Store.registerAdapter('App.Post', DS.Adapter.extend({ find: function(store, type, id) { $.ajax(this.buildURL(type), 'GET', {

    success: function(json) { store.load(type, json); } }); } }));
  24. Helps you isolate crazy.

  25. Read-Only Records

  26. App.Serializer = DS.Serializer.extend({ optionsForMaterializedAttribute: function(type, attributeName) { if (attributeName ===

    'updatedAt') { return { readOnly: true }; } } });
  27. App.Serializer = DS.Serializer.extend({ materializeOptions: function(record, hash) { if (hash.read_only ===

    true) { record.materializeOptions({ readOnly: true }); } } });
  28. None
  29. DS.RESTAdapter.map('App.Tweet', { updatedAt: { readOnly: true, keyName: 'last_date' } });

  30. DS.RESTAdapter.configure('App.Tweet', { readOnly: true });

  31. Embedded Data

  32. // GET /comments/789 { "comment": { "id": 789, "title": "Browser

    question", "body": "the question, \"What browser am I using, and why does it matter?\"", "user": { "firstName": "Jeff", "lastName": "Chang" } } }
  33. None
  34. // PUT /comments/789 { "comment": { "id": 789, "title": "Browser

    questions", "body": "the question, \"What browser am I using, and why does it matter?\"" } } // PUT /users/123 { "user": { "id": 123, "firstName": "Jeffrey", "lastName": "Chang" } } Embedded Loading
  35. DS.RESTAdapter.map('App.Comment', { user: { embedded: "load" } }); Embedded Loading

  36. // PUT /comments/789 { "comment": { "id": 789, "title": "Browser

    questions", "body": "the question, \"What browser am I using, and why does it matter?\"", "user": { "firstName": "Jeffrey", "lastName": "Chang" } } } Embedded
  37. DS.RESTAdapter.map('App.Comment', { user: { embedded: "always" } }); Embedded

  38. github.com/ emberjs/data

  39. Alpha!

  40. Thank you. Questions? http://plus.tomdale.net http://emberjs.com