SlideShare uma empresa Scribd logo
1 de 41
Baixar para ler offline
Riding the Edge with Ember.js
Houston.js
June 2013
Who am I?
• Aaron Ortbals
• Full-stack developer at Chaione
• @aaronortbals
• me@aaronortbals.com
What is Ember.js?
A client-side javascript framework used for building complex web
applications
The Creators
• Tom Dale @tomdale
• worked on Sproutcore framework at Apple and the MobileMe/iCloud
applications
• Yehuda Katz @wykats
• rails core contributor
• heavily involved in open source
• Ember core team is 8 strong
Tilde
• Tom andYehuda co-founded Tilde, a product & consultancy company
with Carl Lerche, and Leah Silber
• Heavily focused on open source
• Team members contributing to jQuery, Rails, Ember, Bundler...
• Tom andYehuda met through Sproutcore and a startup called Strobe
Picking a Framework
(and some history)
Circa 2005...
What was the web was like in 2005?
• IE 6
• jQuery was coming next year
• And along came server-side web application frameworks like Ruby on
Rails and Django
“No one wants a megabyte of
sprinkles.”
Provide a better experience with JS
• Many studies have shown that latency can significantly impact usage
• You can cache but page reloads require re-parsing, executing CSS & JS,
etc...
• To improve latencies, many sites have moved to Single Page Applications
Give us a backbone
• In late 2010, when Backbone.js was released, a lightbulb
went off in a lot of people’s heads
• It’s fast, light-weight, and very easy to jump into
• But what if you want (need?) more?
The Rise of the SPA
So Why Ember?
The Ember Philosophy
• Ember favors convention over configuration
• Ember forces you to do things correctly from the start
• When you use it you might notice similarities to Cocoa and Rails
Conventions
• Strong conventions are really meant to help when you are a team of
more than one
• When a team member adds a new feature, it shouldn’t break old
features
Designing the Ember API
• The team was very focused on getting the API correct pre-1.0
• Led to breaking API changes which pissed people off
• It is all about taking use cases and constraints and designing an API
that will work the best given those constraints
Why did I pick it?
• I really like the structure (especially for large apps)
• The core team is very good and I like the roadmap
• I’ve been highly productive after I crossed the chasm
• While definitely not required, Ember works very well with Rails
Benefits
• Fully featured
• They really care about URLs
• Good community, vastly improving docs
• Once you grok, developer productivity can be very high
Disadvantages
• Still young, but we are close to a 1.0 release (1.0-RC6)
• Backbone,Angular, and others are more mature, less risk
• Development of Ember-testing is trailing the API
• Ember-data is not 1.0 (what is Ember-data?)
What’s Coming for Ember?
• Focused on documentation and the 1.0 release
• Continued work on Ember-testing and Ember-data
• Working with the standard’s bodies to plan for and incorporate the
next generation of JS
• Traditional SPAs do all their rendering on the client
• What about indexing?
• Hybrid rendering is the future
• Both the client and the server can render the page
• Ember has an up-and-coming solution to this with Handlebars
The Problem
So how do I use it already?
{{}}
Fundamentals
• Templates
• Views
• Models
• Router
• Controllers
Templates
• Ember uses Handlebars which wraps {{things}} in curly braces
• You can do things like
{{#linkTo post}}Welcome to Ember!{{/linkTo}}
• or
<ul>
      {{#each model}}
      <li>
        {{partial 'posts/show'}}
      </li>
      {{/each}}
    </ul>
Template Helpers
Build a helper when you want to present data in a specific way.
Handlebars.registerHelper 'fullName', ->
  person.firstName + " " + person.lastName
<span class="name">{{fullName aaron}}</span>
Use it like:
Views
• A view translates events in your template to events that have meaning
to your application
• Typically only written in cases where you want to handle complex user
events or create reusable components
click Delete Controller Router
deleteItem
is deleteItem here?
ChildViews
album_view.js.coffee
App.AlbumView = Ember.View.extend
  templateName: 'album'
 
  title:  "Animals"
artist:  "Pink Floyd"
 
  detailsView: Ember.View.extend
    templateName: 'details'
 
    year:   1977
    genre:  "Progressive Rock"
<h1>
{{view.title}} by {{view.artist}}
</h1>
{{view view.detailsView}}
<div class="year">
From {{view.year}}
</div>
<div class="genre">
In {{view.genre}}
</div>
album.handlebars
details.handlebars
Ember Data
• Ember Data is a library that is designed to:
• make it easy to retrieve records from a server
• make changes in the browser
• save those changes back to the server
• Think of it as providing facilities similar to what an ORM does on the
server
• Works with Rails out of the box if it follows the
active_model_serializers gem’s conventions
Getting Setup with Ember Data
• store.js.coffee
• Remember, Ember Data is pre-1.0, so watch for breaking changes
App.Store = DS.Store.extend
  revision: 12
Models
• Models work well with Ember Data, but can use any persistence layer
• A model looks like this:
• Find a user:
App.User = DS.Model.extend
  firstName:  DS.attr('string')
  lastName:   DS.attr('string')
  email:      DS.attr('string')
  username:   DS.attr('string')
user = App.User.find({ name: "Aaron" })
Relationships
• A model can have relationships. Look familiar?
App.Request = DS.Model.extend
  name:       DS.attr('string')
  user:       DS.belongsTo('App.User')
  filled:     DS.attr('boolean')
  createdAt:  DS.attr('date')
  updatedAt:  DS.attr('date')
Ember Data Alternatives
• Ember-Model - extracted from a live application by core-team
member Erik Bryn
• Ember-Resource - from Zendesk
• Others: Ember-RESTless, Emu, Ember-REST, JQuery directly
Router
• Ember.js represents each of the possible states in your application as a
URL
• Or the user hits the back button
• Avoid losing state when the user uses traditional navigation
View
interacts event
Wiring up some routes
• Static routes
• Resource routes
• Nested resources
• Use the browser history
API (no hash bangs!)
App.Router.map (match) ->
  @route 'app', { path: '/'}
  @route 'login'
  @route 'signup'
 
  @resource 'users', ->
    @route 'new'
    @resource 'user',
      path: ':user_id'
 
  @resource 'requests', ->
    @route 'new'
    @resource 'request',
      path: ':request_id'
 
# Use the browser history API
App.Router.reopen
   location: 'history'
A Route
• Each route has a route handler
• It finds the model, hands it to the controller, then renders a bound
template
App.UsersRoute = Ember.Route.extend
  model: ->
    App.User.find()
 
App.UsersNewRoute = Ember.Route.extend
  model: ->
    App.User.createRecord()
 
App.SignupRoute = App.UsersNewRoute
Controllers
• Models have properties that are saved to the server, while controllers
have properties that don’t need to be saved to the server
• In other words, anything that is specific to the current session
App.UserController = Ember.ObjectController.extend
  delete: ->
    if (window.confirm "Are you sure you want to delete this user?")
      @get('content').deleteRecord()
      @get('store').commit()
      @transitionToRoute('users')
An Example User Controller:
Coupling
Template
Controller
Model
Templates know about controllers, controllers know about models...
But not the reverse
Other stuff to check out
Ember Inspector
Yehuda is working on an extension for Chrome that exposes what is
happening in Ember. Check it out!
Who is using Ember?
Open Source!
Credits & Resources
• Emberjs.com
• Tilde.io
• Thoughbot Episode #53
• Herding Code #169
• Ember Weekly
• Embrace Javascript
• Emberwatch
So what does a structured app
look like?

Mais conteúdo relacionado

Mais procurados

SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
Sébastien Levert
 

Mais procurados (20)

Ember presentation
Ember presentationEmber presentation
Ember presentation
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and Joomla
 
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotionFrom Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
From Ruby on Rails to RubyMotion - Writing your First iOS App with RubyMotion
 
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
SharePoint Saturday Lisbon 2017 - SharePoint Framework, Angular & Azure Funct...
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
Rails as iOS Application Backend
Rails as iOS Application BackendRails as iOS Application Backend
Rails as iOS Application Backend
 
Best Practices for Building WordPress Applications
Best Practices for Building WordPress ApplicationsBest Practices for Building WordPress Applications
Best Practices for Building WordPress Applications
 
A Day of REST
A Day of RESTA Day of REST
A Day of REST
 
Modern javascript
Modern javascriptModern javascript
Modern javascript
 
Creating an Effective Mobile API
Creating an Effective Mobile API Creating an Effective Mobile API
Creating an Effective Mobile API
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
 
JSLink for ITPros - SharePoint Saturday Jersey
JSLink for ITPros - SharePoint Saturday JerseyJSLink for ITPros - SharePoint Saturday Jersey
JSLink for ITPros - SharePoint Saturday Jersey
 
Cross-Platform Desktop Apps with Electron (JSConf UY)
Cross-Platform Desktop Apps with Electron (JSConf UY)Cross-Platform Desktop Apps with Electron (JSConf UY)
Cross-Platform Desktop Apps with Electron (JSConf UY)
 
How NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscapeHow NOT to get lost in the current JavaScript landscape
How NOT to get lost in the current JavaScript landscape
 
Cross-Platform Desktop Apps with Electron (Condensed Version)
Cross-Platform Desktop Apps with Electron (Condensed Version)Cross-Platform Desktop Apps with Electron (Condensed Version)
Cross-Platform Desktop Apps with Electron (Condensed Version)
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Plone api
Plone apiPlone api
Plone api
 
Ember,js: Hipster Hamster Framework
Ember,js: Hipster Hamster FrameworkEmber,js: Hipster Hamster Framework
Ember,js: Hipster Hamster Framework
 
Managing SharePoint Anywhere with Windows PowerShell
Managing SharePoint Anywhere with Windows PowerShellManaging SharePoint Anywhere with Windows PowerShell
Managing SharePoint Anywhere with Windows PowerShell
 
Mobile native-hacks
Mobile native-hacksMobile native-hacks
Mobile native-hacks
 

Destaque (6)

Rails & Backbone.js
Rails & Backbone.jsRails & Backbone.js
Rails & Backbone.js
 
Knockout js
Knockout jsKnockout js
Knockout js
 
Segmentry: Developing for Salesforce Lightning and Classic using ReactJS and ...
Segmentry: Developing for Salesforce Lightning and Classic using ReactJS and ...Segmentry: Developing for Salesforce Lightning and Classic using ReactJS and ...
Segmentry: Developing for Salesforce Lightning and Classic using ReactJS and ...
 
Intoduction to Angularjs
Intoduction to AngularjsIntoduction to Angularjs
Intoduction to Angularjs
 
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and BackboneJavascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
Javascript Frameworks Comparison - Angular, Knockout, Ember and Backbone
 
Mouse model: Pros & Cons
Mouse model: Pros & ConsMouse model: Pros & Cons
Mouse model: Pros & Cons
 

Semelhante a Riding the Edge with Ember.js

Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
tboyt
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
Avi Kedar
 

Semelhante a Riding the Edge with Ember.js (20)

The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
A Beginner's Guide to Ember
A Beginner's Guide to EmberA Beginner's Guide to Ember
A Beginner's Guide to Ember
 
Ember vs Backbone
Ember vs BackboneEmber vs Backbone
Ember vs Backbone
 
Introduction to Ember.js and how we used it at FlowPro.io
Introduction to Ember.js and how we used it at FlowPro.ioIntroduction to Ember.js and how we used it at FlowPro.io
Introduction to Ember.js and how we used it at FlowPro.io
 
Node.js
Node.jsNode.js
Node.js
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
APIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadAPIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidad
 
SGCE 2015 REST APIs
SGCE 2015 REST APIsSGCE 2015 REST APIs
SGCE 2015 REST APIs
 
Lessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptxLessons learned on the Azure API Stewardship Journey.pptx
Lessons learned on the Azure API Stewardship Journey.pptx
 
Web Development using Ruby on Rails
Web Development using Ruby on RailsWeb Development using Ruby on Rails
Web Development using Ruby on Rails
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
 
DSpace UI prototype dsember
DSpace UI prototype dsemberDSpace UI prototype dsember
DSpace UI prototype dsember
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Azure Functions Real World Examples
Azure Functions Real World Examples Azure Functions Real World Examples
Azure Functions Real World Examples
 
Zero to Sixty with Oracle ApEx
Zero to Sixty with Oracle ApExZero to Sixty with Oracle ApEx
Zero to Sixty with Oracle ApEx
 
Portal and Intranets
Portal and Intranets Portal and Intranets
Portal and Intranets
 
2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar Slides2.28.17 Introducing DSpace 7 Webinar Slides
2.28.17 Introducing DSpace 7 Webinar Slides
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

Riding the Edge with Ember.js

  • 1. Riding the Edge with Ember.js Houston.js June 2013
  • 2. Who am I? • Aaron Ortbals • Full-stack developer at Chaione • @aaronortbals • me@aaronortbals.com
  • 3. What is Ember.js? A client-side javascript framework used for building complex web applications
  • 4. The Creators • Tom Dale @tomdale • worked on Sproutcore framework at Apple and the MobileMe/iCloud applications • Yehuda Katz @wykats • rails core contributor • heavily involved in open source • Ember core team is 8 strong
  • 5. Tilde • Tom andYehuda co-founded Tilde, a product & consultancy company with Carl Lerche, and Leah Silber • Heavily focused on open source • Team members contributing to jQuery, Rails, Ember, Bundler... • Tom andYehuda met through Sproutcore and a startup called Strobe
  • 6. Picking a Framework (and some history)
  • 7. Circa 2005... What was the web was like in 2005? • IE 6 • jQuery was coming next year • And along came server-side web application frameworks like Ruby on Rails and Django
  • 8. “No one wants a megabyte of sprinkles.”
  • 9. Provide a better experience with JS • Many studies have shown that latency can significantly impact usage • You can cache but page reloads require re-parsing, executing CSS & JS, etc... • To improve latencies, many sites have moved to Single Page Applications
  • 10. Give us a backbone • In late 2010, when Backbone.js was released, a lightbulb went off in a lot of people’s heads • It’s fast, light-weight, and very easy to jump into • But what if you want (need?) more?
  • 11. The Rise of the SPA
  • 13. The Ember Philosophy • Ember favors convention over configuration • Ember forces you to do things correctly from the start • When you use it you might notice similarities to Cocoa and Rails
  • 14. Conventions • Strong conventions are really meant to help when you are a team of more than one • When a team member adds a new feature, it shouldn’t break old features
  • 15. Designing the Ember API • The team was very focused on getting the API correct pre-1.0 • Led to breaking API changes which pissed people off • It is all about taking use cases and constraints and designing an API that will work the best given those constraints
  • 16. Why did I pick it? • I really like the structure (especially for large apps) • The core team is very good and I like the roadmap • I’ve been highly productive after I crossed the chasm • While definitely not required, Ember works very well with Rails
  • 17. Benefits • Fully featured • They really care about URLs • Good community, vastly improving docs • Once you grok, developer productivity can be very high
  • 18. Disadvantages • Still young, but we are close to a 1.0 release (1.0-RC6) • Backbone,Angular, and others are more mature, less risk • Development of Ember-testing is trailing the API • Ember-data is not 1.0 (what is Ember-data?)
  • 19. What’s Coming for Ember? • Focused on documentation and the 1.0 release • Continued work on Ember-testing and Ember-data • Working with the standard’s bodies to plan for and incorporate the next generation of JS
  • 20. • Traditional SPAs do all their rendering on the client • What about indexing? • Hybrid rendering is the future • Both the client and the server can render the page • Ember has an up-and-coming solution to this with Handlebars The Problem
  • 21. So how do I use it already? {{}}
  • 22. Fundamentals • Templates • Views • Models • Router • Controllers
  • 23. Templates • Ember uses Handlebars which wraps {{things}} in curly braces • You can do things like {{#linkTo post}}Welcome to Ember!{{/linkTo}} • or <ul>       {{#each model}}       <li>         {{partial 'posts/show'}}       </li>       {{/each}}     </ul>
  • 24. Template Helpers Build a helper when you want to present data in a specific way. Handlebars.registerHelper 'fullName', ->   person.firstName + " " + person.lastName <span class="name">{{fullName aaron}}</span> Use it like:
  • 25. Views • A view translates events in your template to events that have meaning to your application • Typically only written in cases where you want to handle complex user events or create reusable components click Delete Controller Router deleteItem is deleteItem here?
  • 26. ChildViews album_view.js.coffee App.AlbumView = Ember.View.extend   templateName: 'album'     title:  "Animals" artist:  "Pink Floyd"     detailsView: Ember.View.extend     templateName: 'details'       year:   1977     genre:  "Progressive Rock" <h1> {{view.title}} by {{view.artist}} </h1> {{view view.detailsView}} <div class="year"> From {{view.year}} </div> <div class="genre"> In {{view.genre}} </div> album.handlebars details.handlebars
  • 27. Ember Data • Ember Data is a library that is designed to: • make it easy to retrieve records from a server • make changes in the browser • save those changes back to the server • Think of it as providing facilities similar to what an ORM does on the server • Works with Rails out of the box if it follows the active_model_serializers gem’s conventions
  • 28. Getting Setup with Ember Data • store.js.coffee • Remember, Ember Data is pre-1.0, so watch for breaking changes App.Store = DS.Store.extend   revision: 12
  • 29. Models • Models work well with Ember Data, but can use any persistence layer • A model looks like this: • Find a user: App.User = DS.Model.extend   firstName:  DS.attr('string')   lastName:   DS.attr('string')   email:      DS.attr('string')   username:   DS.attr('string') user = App.User.find({ name: "Aaron" })
  • 30. Relationships • A model can have relationships. Look familiar? App.Request = DS.Model.extend   name:       DS.attr('string')   user:       DS.belongsTo('App.User')   filled:     DS.attr('boolean')   createdAt:  DS.attr('date')   updatedAt:  DS.attr('date')
  • 31. Ember Data Alternatives • Ember-Model - extracted from a live application by core-team member Erik Bryn • Ember-Resource - from Zendesk • Others: Ember-RESTless, Emu, Ember-REST, JQuery directly
  • 32. Router • Ember.js represents each of the possible states in your application as a URL • Or the user hits the back button • Avoid losing state when the user uses traditional navigation View interacts event
  • 33. Wiring up some routes • Static routes • Resource routes • Nested resources • Use the browser history API (no hash bangs!) App.Router.map (match) ->   @route 'app', { path: '/'}   @route 'login'   @route 'signup'     @resource 'users', ->     @route 'new'     @resource 'user',       path: ':user_id'     @resource 'requests', ->     @route 'new'     @resource 'request',       path: ':request_id'   # Use the browser history API App.Router.reopen    location: 'history'
  • 34. A Route • Each route has a route handler • It finds the model, hands it to the controller, then renders a bound template App.UsersRoute = Ember.Route.extend   model: ->     App.User.find()   App.UsersNewRoute = Ember.Route.extend   model: ->     App.User.createRecord()   App.SignupRoute = App.UsersNewRoute
  • 35. Controllers • Models have properties that are saved to the server, while controllers have properties that don’t need to be saved to the server • In other words, anything that is specific to the current session App.UserController = Ember.ObjectController.extend   delete: ->     if (window.confirm "Are you sure you want to delete this user?")       @get('content').deleteRecord()       @get('store').commit()       @transitionToRoute('users') An Example User Controller:
  • 36. Coupling Template Controller Model Templates know about controllers, controllers know about models... But not the reverse
  • 37. Other stuff to check out
  • 38. Ember Inspector Yehuda is working on an extension for Chrome that exposes what is happening in Ember. Check it out!
  • 39. Who is using Ember? Open Source!
  • 40. Credits & Resources • Emberjs.com • Tilde.io • Thoughbot Episode #53 • Herding Code #169 • Ember Weekly • Embrace Javascript • Emberwatch
  • 41. So what does a structured app look like?