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

Ember.js Application Patterns

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

Ember.js Application Patterns

Avatar for Adam Hawkins

Adam Hawkins

January 21, 2013
Tweet

More Decks by Adam Hawkins

Other Decks in Programming

Transcript

  1. Wer bin Ich? • Adam Hawkins • broadcastingadam.com • twitter.com/adman65

    • github.com/twinturbo • speaker.com/u/twinturbo • Jeden Tag arbeite ich an ember Apps
  2. Why? • More designer friendly • Styling and markup is

    not application level, it’s presentation • Hard to track down where markup happens • Break this rule: when you have more complex views
  3. • Just because you can reach out, doesn’t mean you

    should • Views use their controller, not others • Controller provides everything a view needs Why?
  4. Ember.View.extend({ // we need a reference to this resizeListener: (function({

    $.proxy this.windowDidResize, this }).property(), windowDidResize: function({ // your logic here }), didInsertElement: function({ $(window).on('resize', this.resizeListener) }), didRemoveElement: function({ $(window).off('resize', this.resizeListener) }) });
  5. • Respect the boundary at the top • User’s interact

    with your app via the URL and DOM • Controllers do most of the work • Handlebars represents the UI at any given point • Controllers don’t interact directly with views • Views interact with the DOM via didInsertElement and friends
  6. • Forces your mind into an API box • Extremely

    test unfriendly • Development & testing concerns mix with production concerns • Fixtures are not application model, they are API responses Wieso?
  7. DS.InMemoryAdapter • Uses a “pass through” serializer • Instantiate the

    DS.Model objects you want and call commit() • No need to track FK’s. Just add to the association and call commit() • Focus on application data • Leverage the boundary for your benefit
  8. Bad Post.FIXTURES = [ { id: "1", title: "Post 1",

    text: "Lorem...." comment_ids: ["1", "2"] } ] Comment.FIXTURES = [ { id: "1" text: "Zomg" post_id: "1" } ]
  9. Good post = Post.createRecord({ title: "Post 1" text: "Lorem..." });

    comment = Comment.createRecord({ text: "Zomg" }); post.get('comments').pushObject(comment); store.commit()
  10. • Ember.Binding.oneWay when applicable • Ember.Computed.alias (in the works) •

    Use a build tool (Iridium is the best) • If using Rails + Ember Data, then use ActiveModel::Serializers • Push async code to the edge of your application • Controllers decorate objects Grab Bag