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

Building Modern Web Apps: Framework is not a four letter word

Building Modern Web Apps: Framework is not a four letter word

JSCamp.asia 2012 presentation discussing the benefits of client-side frameworks, when to use them and why you should use Ember.js for your next web application.

Bradley Priest

November 29, 2012
Tweet

More Decks by Bradley Priest

Other Decks in Programming

Transcript

  1. What I'll cover - Existing options when building for the

    web - When you should use a framework - My recommendation: Ember.js
  2. It's no longer good enough to build web apps around

    full page loads and then "progressively enhance" them to behave more dynamically. Building apps which are fast, responsive and modern require you to completely rethink your approach. This is a big transition to make and it is further complicated by the plethora of great options out there. Don't just sit around and wait for things to shake out. ThroneOfJS
  3. Option 2: Server-Side Rendering Twitter: Improving performance on twitter.com Basecamp

    Next: How Basecamp Next got to be so damn fast without using much client-side UI
  4. Server-Side - PJAX/Turbolinks ... it keeps the current page instance

    alive and replaces only the body and the title in the head.
  5. Option 3: Client-Side Rendering Send JSON... or BSON or XML

    or ... Cons - May duplicate logic Pros - Less data - Reusable API - More flexible
  6. A Little Structure If you're building something substantial, use a

    framework (or write your own...*) * I'm kidding please don't write a new framework, every time someone writes a new JS MVC framework god kills a kitten. Seriously, there's plenty of existing frameworks that would love your help.
  7. What are you building? Traditional Website - Basic user interaction

    - JS mostly presentational - Little/No AJAX
  8. What are you building? Interactive Website - Some user-interaction -

    Page reflects interactive data - Multiple areas can change
  9. What are you building? Web Application - Lots of user-interaction

    - Frequent data communication - Could constitute a desktop/mobile app
  10. Ember - Convention over Configuration - Laziness is a virtue

    Manage the complex, boring stuff for you and leaves you free to work on the exciting problems
  11. { todos: [ { name: "Get out of bed", isDone:

    false }, { name: "Brush Teeth", isDone: false }, { name: "Put on pants", isDone: false }, ] itemsLeft: 3, completedItems: 0 }
  12. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: false }, { name: "Put on pants", isDone: false }, ] itemsLeft: 2, completedItems: 1 } Dom Changes: 3
  13. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: true }, { name: "Put on pants", isDone: false }, ] itemsLeft: 1, completedItems: 2 } Dom Changes: 6
  14. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: true }, { name: "Put on pants", isDone: true }, ] itemsLeft: 0, completedItems: 3 } Dom Changes: 9
  15. Vs

  16. { todos: [ { name: "Get out of bed", isDone:

    false }, { name: "Brush Teeth", isDone: false }, { name: "Put on pants", isDone: false }, ] itemsLeft: 3, completedItems: 0 }
  17. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: false }, { name: "Put on pants", isDone: false }, ] itemsLeft: -, completedItems: - } Dom Changes: 0
  18. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: true }, { name: "Put on pants", isDone: false }, ] itemsLeft: -, completedItems: - } Dom Changes: 0
  19. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: true }, { name: "Put on pants", isDone: true }, ] itemsLeft: -, completedItems: - } Dom Changes: 0
  20. { todos: [ { name: "Get out of bed", isDone:

    true }, { name: "Brush Teeth", isDone: true }, { name: "Put on pants", isDone: true }, ] itemsLeft: 0, completedItems: 3 } Dom Changes: 5
  21. The Run Loop - Triggered by Browser Events touchstart touchmove

    touchend touchcancel keydown keyup keypress mousedown mouseup contextmenu click dblclick mousemove focusin focusout mouseenter mouseleave submit input change dragstart drag dragenter dragleave dragover drop dragend
  22. Ember - Convention over Configuration Application Structure - View Lifecycle

    management - Setup/teardown of bindings/observers - Event handling
  23. Ember.Router - View setup post: Ember.Route.extend({ route: "/post", show: Ember.Route.extend({

    route: ":post_id", goToEdit: Ember.Route.transitionTo('edit'), connectOutlets: function(router, context){ router.get('applicationController').connectOutlet({ viewClass: App.PostShowView, controller: router.get('postController'), context: App.Post.find(context) }) }, }) edit: Ember.Route.extend({ }) })
  24. View teardown - Parent views are aware of their child

    views - Automatic binding/observer teardown
  25. View Setup/Teardown - 3rd Party Libraries App.DateFieldView = Ember.TextField.extend({ didInsertElement:

    function(){ this.$().datepicker({ autoclose: true, format: moment.formats.picker }).on("changeDate", function(context){ this.set("date", context.date) }) } }) didInsertElement/willDestroyElement
  26. Event Handling post: Ember.Route.extend({ route: "/post", show: Ember.Route.extend({ route: ":post_id",

    goToEdit: Ember.Route.transitionTo('edit'), connectOutlets: function(router, context){ router.get('applicationController').connectOutlet({ viewClass: App.PostShowView, controller: router.get('postController'), context: App.Post.find(context) }) }, }) edit: Ember.Route.extend({ }) })