SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
Ember VS Backbone
• Structure overview	

• Stand alone JS app	

• Using with RoR
Backbone came out in June 2010	

Many popular applications use the Backbone framework,
including Twitter, Foursquare, and LinkedIn Mobile.Also
worth noting is that a number of music apps were built
with Backbone, including Soundcloud, Pitchfork, and
Pandora. 	

Backbone weight just 6.4K.
Logic is outside of the DOM	

Structure logic	

Developed for work with REST API’s	

Almost MVC - Model,View, Route + Collection
Philosophy
Model
Can be created, validated, destroyed, and saved to the
server	

!
model.get('attr')
model.set('attr', val)
model.validate(attributes, options)
There is no two-way data binding between your
BackboneViews and Models	

But it can be added by using next solutions:	

http://rivetsjs.com/	

http://nytimes.github.io/backbone.stickit/
Bindings
View
The main idea is to organize your code and give you an
opportunity to use different callbacks and events
triggers.
el
All views have a DOM element at all times (the el
property), whether they've already been inserted into
the page or not.	

!
!
template: JST[‚tutorials/new_tutor']
!
var BodyView = Backbone.View.extend({
el: 'body'
});
!
@$el.html(@template)
Events
events:
'keyup #tutor-input': 'updatePreview'
'click .submit-tutorial': 'submitTutor'
!
'click #bold': 'boldStyler'
Collections
Is a sortable collection of models, which can filter,
manage and control them.	

Accessing models:	

collection.models
collection.at
collection.get
collection.add([{key: val}, {key: val}])	

collection.remove	

collection.set	

collection.get(id)	

colleaction.at(index)	

collection.push(model, [options])	

collection.pop(model, [options])	

collection.pluck(“attr”)	

collection.where({job:‘Some’})	

!
collection.fetch	

!
Underscore methods:	

find, contains, sortBy, groupBy, toArray, size, first, last, indexOf,
isEmpty
Routes
Hash navigation - localhost#search/users/2	

!
class Tutors.Routers.Tutorials.New extends
Backbone.Router
routes:
'.*': 'addTutor'
'addTutor': 'addTutor'
navigate router.navigate(fragment, [options])
!
!
!
!
Execute method is called internally within the
router:
var Router = Backbone.Router.extend({
execute: function(callback, args) {
args.push(parseQueryString(args.pop()));
if (callback) callback.apply(this, args);
}
});
History serves as a global router to handle hashchange
events, match the appropriate route, and trigger
callbacks.You shouldn't ever have to create one of these
yourself since Backbone.history already contains one.	

Just call it like this - Backbone.history.start
Backbone.history
Events
Events is a module that can be mixed in to any object, giving the object the ability to bind and
trigger custom named events.	

book.on({
"change:title": titleView.update,
"change:author": authorPane.update,
"destroy": bookView.remove
});
!
// Removes just the `onChange` callback.
object.off("change", onChange);
!
view.listenTo(model, 'change',
view.render);
!
Catalog of Events	

• "add" (model, collection, options) — when a model is added to a collection.	

• "remove" (model, collection, options) — when a model is removed from a collection.	

• "reset" (collection, options) — when the collection's entire contents have been replaced.	

• "sort" (collection, options) — when the collection has been re-sorted.	

• "change" (model, options) — when a model's attributes have changed.	

• "change:[attribute]" (model, value, options) — when a specific attribute has been updated.	

• "destroy" (model, collection, options) — when a model is destroyed.	

• "request" (model_or_collection, xhr, options) — when a model or collection has started a
request to the server.	

• "sync" (model_or_collection, resp, options) — when a model or collection has been
successfully synced with the server.	

• "error" (model_or_collection, resp, options) — when model's or collection's request to
remote server has failed.	

• "invalid" (model, error, options) — when a model's validation fails on the client.	

• "route:[name]" (params) — Fired by the router when a specific route is matched.	

• "route" (route, params) — Fired by the router when any route has been matched.	

• "route" (router, route, params) — Fired by history when any route has been matched.	

• "all" — this special event fires for any triggered event, passing the event name as the first
Benefits
1) Standatized architecture of application, which will be very friendly for rails developers	

2) Easy scallable and refactoring	

3) A lot of methods for working with events, callbacks, models and collections	

With Backbone, you have some given assertions:	

Data lies in JavaScript objects, not the DOM	

Event handling lies in JavaScript objects, not jQuery event bindings	

The way you save data in a backend server is done through the objects that contain the data	

http://backbonejs.org/
Initially released in 2011, Ember just hit version 1.0 last year.	

LivingSocial, Groupon, Zendesk, Discourse, and Square are
some of the most well-known applications that have adopted
Ember. Ember creators Tom Dale andYehuda Katz say it’s
easy to see when a site is using Ember because of its loading
speed.	

69K minified and zipped
The first step to creating an Ember.js application is to
make an instance of Ember.Application and assign it to a
global variable.	

!
window.App = Ember.Application.create();
!
INITIALIZING AN APPLICATION
CORE CONCEPTS
• TEMPLATES	

• ROUTER	

• COMPONENTS	

• MODELS	

• CONTROLLERS	

• VIEWS
When your application boots, Ember will look for these objects:!
!
!
App.ApplicationRoute!
App.ApplicationModel!
App.ApplicationController!
the application template!
A template, written in the Handlebars templating language, describes the user interface of your application.
Each template is backed by a model, and the template automatically updates itself if the model changes.	

In addition to plain HTML, templates can contain:	

• Expressions, like {{firstName}}, which take information from the template's model and put it into
HTML.	

• Outlets, which are placeholders for other templates.As users move around your app, different
templates can be plugged into the outlet by the router.You can put outlets into your template using
the {{outlet}} helper.	

• Components, custom HTML elements that you can use to clean up repetitive templates or create
reusable controls.
Templates
Router
The router translates a URL into a series of nested templates, each backed
by a model.As the templates or models being shown to the user change,
Ember automatically keeps the URL in the browser's address bar up-to-date.	

A route is an object that tells the template which model it should display.	

Each of your routes will have a controller, and a template with the same
name as the route.
App.Router.map(function() {
this.route("about", { path: "/about" });
this.route("favorites", { path: "/
favs" });
});
!
Now, when the user visits /about, Ember.js will render the about template.
Visiting /favs will render the favorites template.	

{{#link-to 'index'}}<img class="logo">{{/link-to}}
!
<nav>
{{#link-to 'about'}}About{{/link-to}}
{{#link-to 'favorites'}}Favorites{{/link-to}}
</nav>
COMPONENTS
A component is a custom HTML tag whose behavior
you implement using JavaScript and whose appearance
you describe using Handlebars templates. 	

They allow you to create reusable controls that can
simplify your application's templates.
<script type="text/x-handlebars" id="components/blog-post">
<h1>Blog Post</h1>
<p>Lorem ipsum dolor sit amet.</p>
</script>
!
<h1>My Blog</h1>
{{#each}}
{{blog-post}}
{{/each}}
<script type="text/x-handlebars" id="components/blog-post">
<h1>Component: {{title}}</h1>
<p>Lorem ipsum dolor sit amet.</p>
</script>
!
!
App.IndexRoute = Ember.Route.extend({
model: function() {
return {
title: "Rails is awesome!"
};
}
});
!
!
{{blog-post title=title}}
Passing an arguments
MODELS
A model is an object that stores persistent state.
Templates are responsible for displaying the model to
the user by turning it into HTML. In many applications,
models are loaded via an HTTP JSON API, although
Ember is agnostic to the backend that you choose.
App.Person = DS.Model.extend();
!
store.find('person', 1);
ONE-TO-ONE	

App.User = DS.Model.extend({
profile: DS.belongsTo('profile')
});
!
App.Profile = DS.Model.extend({
user: DS.belongsTo('user')
});
ONE-TO-MANY
App.Post = DS.Model.extend({
comments: DS.hasMany('comment')
});
!
App.Comment = DS.Model.extend({
post: DS.belongsTo('post')
});
MANY-TO-MANY
App.Post = DS.Model.extend({
tags: DS.hasMany('tag')
});
!
App.Tag = DS.Model.extend({
posts: DS.hasMany('post')
});
store.createRecord('post', {
title: 'Rails is Omakase',
body: 'Lorem ipsum'
});
store.find('post', 1).then(function (post) {
post.deleteRecord();
post.get('isDeleted'); // => true
post.save(); // => DELETE to /posts/1
});
!
// OR
store.find('post', 2).then(function (post) {
post.destroyRecord(); // => DELETE to /posts/2
});
DELETING RECORDS
CREATING RECORDS
ADAPTERS
App.PostAdapter = DS.RESTAdapter.extend({
namespace: 'api/v1'
});
CONTROLLERS
A controller is an object that stores application state.A
template can optionally have a controller in addition to
a model, and can retrieve properties from both.
REPRESENTING A
SINGLE MODEL
App.SongController =
Ember.ObjectController.extend({
soundVolume: 1
});
<p>
<strong>Song</strong>: {{name}} by {{artist}}
</p>
<p>
<strong>Current Volume</strong>: {{soundVolume}}
</p>
REPRESENTING
MULTIPLE MODELS
App.SongsController = Ember.ArrayController.extend({
longSongCount: function() {
var longSongs = this.filter(function(song) {
return song.get('duration') > 30;
});
return longSongs.get('length');
}.property('@each.duration')
});
!
!
!
<ul>
{{#each}}
<li>{{name}} by {{artist}}</li>
{{/each}}
</ul>
!
{{longSongCount}} songs over 30 seconds.
VIEWS
Views in Ember.js are typically only created for the following
reasons:	

• When you need sophisticated handling of user events	

• When you want to create a re-usable component
var view = Ember.View.create({
templateName: 'say-hello',
name: "Bob"
});
!
!
view.appendTo('#container');
Handling events
{{#view App.ClickableView}}
This is a clickable area!
{{/view}}
!
!
App.ClickableView = Ember.View.extend({
click: function(evt) {
alert("ClickableView was clicked!");
}
});
INSERTING VIEWS IN TEMPLATES
// Define parent view
App.UserView = Ember.View.extend({
templateName: 'user',
!
firstName: "Albert",
lastName: "Hofmann"
});
!
// Define child view
App.InfoView = Ember.View.extend({
templateName: 'info',
!
posts: 25,
hobbies: "Riding bicycles"
});
!
<script type="text/x-handlebars" data-template-name="user">
User: {{view.firstName}} {{view.lastName}}
{{view App.InfoView}}
</script>
!
<script type="text/x-handlebars" data-template-name="info">
<b>Posts:</b> {{view.posts}}
<br>
<b>Hobbies:</b> {{view.hobbies}}
</script>
RESULT
User: Albert Hofmann
<div>
<b>Posts:</b> 25
<br>
<b>Hobbies:</b> Riding bicycles
</div>
Benefits
• Two-way data binding: objects in Ember are able to
register bindings between one another.That way,
whenever a bound property changes, the other one
is updated automatically.	

• Computed properties: if you wish to have a
property that is a result of a function, you can
create them and assign a property as computed by
that function.	

• Template auto-updates: when an object is updated
in your app, all the views currently displayed in the
screen that are bound to that object automatically
reflect the change, with no boilerplate.
Stand alone JS app
http://yeoman.io/
Backbone.js generator
• npm install -g generator-backbone	

• mkdir my-new-project && cd $_	

• yo backbone [app-name]	

!
https://github.com/yeoman/generator-backbone
Ember.js Generator
• npm install -g generator-ember	

• mkdir myemberapp && cd myemberapp(The
directory's name is your application's name)	

• yo ember	

• npm install -g grunt-mocha	

• grunt serve
Rails + JS Framework
• Backbone on Rails	

• ember-rails
Backbone on Rails
gem 'backbone-on-rails'	

bundle install	

rails generate backbone:install	

rails generate backbone:scaffold NAME	

https://github.com/meleyal/backbone-on-rails	

http://moxa.ws/en/adding-backbone-js-in-rails-app-in-5-
seconds/
Ember on Rails
gem 'ember-rails'	

gem 'ember-source', '1.5.0' # or the version you need	

bundle install	

rails g ember:bootstrap -g --javascript-engine coffee	

!
https://github.com/emberjs/ember-rails
QUESTIONS?

Más contenido relacionado

La actualidad más candente

Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGMarakana Inc.
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web DesignMike Wilcox
 
Web Components v1
Web Components v1Web Components v1
Web Components v1Mike Wilcox
 
WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...
WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...
WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...Patrick Lauke
 
Real Life MAF (2.2) Oracle Open World 2015
Real Life MAF (2.2) Oracle Open World 2015Real Life MAF (2.2) Oracle Open World 2015
Real Life MAF (2.2) Oracle Open World 2015Luc Bors
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptAndrew Lovett-Barron
 
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
 Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg... Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...Brian Mann
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling RewriterJustin Edelson
 
RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014Henry Van Styn
 
WAI-ARIA is More Than Accessibility
WAI-ARIA is More Than AccessibilityWAI-ARIA is More Than Accessibility
WAI-ARIA is More Than Accessibility偉格 高
 
Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017Henry Van Styn
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsJoseph Khan
 
Building Web Sites that Work Everywhere
Building Web Sites that Work EverywhereBuilding Web Sites that Work Everywhere
Building Web Sites that Work EverywhereDoris Chen
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shintutorialsruby
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6Yuval Ararat
 

La actualidad más candente (20)

Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUG
 
Great Responsive-ability Web Design
Great Responsive-ability Web DesignGreat Responsive-ability Web Design
Great Responsive-ability Web Design
 
Web Components v1
Web Components v1Web Components v1
Web Components v1
 
WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...
WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...
WAI-ARIA - an introduction to accessible rich internet applications (1 day wo...
 
Real Life MAF (2.2) Oracle Open World 2015
Real Life MAF (2.2) Oracle Open World 2015Real Life MAF (2.2) Oracle Open World 2015
Real Life MAF (2.2) Oracle Open World 2015
 
Intro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate JavascriptIntro to BackboneJS + Intermediate Javascript
Intro to BackboneJS + Intermediate Javascript
 
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
 Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg... Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
Little Opinions, Big Possibilities: The Tools and Patterns for Building Larg...
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
 
RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
ParisJS #10 : RequireJS
ParisJS #10 : RequireJSParisJS #10 : RequireJS
ParisJS #10 : RequireJS
 
WAI-ARIA is More Than Accessibility
WAI-ARIA is More Than AccessibilityWAI-ARIA is More Than Accessibility
WAI-ARIA is More Than Accessibility
 
Handlebars & Require JS
Handlebars  & Require JSHandlebars  & Require JS
Handlebars & Require JS
 
Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017Rapi::Blog talk - TPC 2017
Rapi::Blog talk - TPC 2017
 
BackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applicationsBackboneJS Training - Giving Backbone to your applications
BackboneJS Training - Giving Backbone to your applications
 
Building Web Sites that Work Everywhere
Building Web Sites that Work EverywhereBuilding Web Sites that Work Everywhere
Building Web Sites that Work Everywhere
 
td_mxc_rubyrails_shin
td_mxc_rubyrails_shintd_mxc_rubyrails_shin
td_mxc_rubyrails_shin
 
Bootstrap 4 ppt
Bootstrap 4 pptBootstrap 4 ppt
Bootstrap 4 ppt
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 

Similar a Ember vs Backbone

Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.jsaortbals
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.jsreybango
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application danceNicholas Valbusa
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsAlessandro DS
 
Introduction to Ember.js
Introduction to Ember.jsIntroduction to Ember.js
Introduction to Ember.jsJeremy Brown
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
iPhone Web Development and Ruby On Rails
iPhone Web Development and Ruby On RailsiPhone Web Development and Ruby On Rails
iPhone Web Development and Ruby On RailsJose de Leon
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile appsIvano Malavolta
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Againjonknapp
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Dimitri de Putte
 
Client Side MVC with Backbone and Rails
Client Side MVC with Backbone and RailsClient Side MVC with Backbone and Rails
Client Side MVC with Backbone and RailsTom Z Zeng
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.jsMatthew Beale
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Create an application with ember
Create an application with ember Create an application with ember
Create an application with ember Chandra Sekar
 
Javascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web AppsJavascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web Appsdnelson-cs
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolvertboyt
 

Similar a Ember vs Backbone (20)

Riding the Edge with Ember.js
Riding the Edge with Ember.jsRiding the Edge with Ember.js
Riding the Edge with Ember.js
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.js
 
Make your Backbone Application dance
Make your Backbone Application danceMake your Backbone Application dance
Make your Backbone Application dance
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Introduction to Ember.js
Introduction to Ember.jsIntroduction to Ember.js
Introduction to Ember.js
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
iPhone Web Development and Ruby On Rails
iPhone Web Development and Ruby On RailsiPhone Web Development and Ruby On Rails
iPhone Web Development and Ruby On Rails
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
 
Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012Backbonification for dummies - Arrrrug 10/1/2012
Backbonification for dummies - Arrrrug 10/1/2012
 
Client Side MVC with Backbone and Rails
Client Side MVC with Backbone and RailsClient Side MVC with Backbone and Rails
Client Side MVC with Backbone and Rails
 
Parse Apps with Ember.js
Parse Apps with Ember.jsParse Apps with Ember.js
Parse Apps with Ember.js
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Create an application with ember
Create an application with ember Create an application with ember
Create an application with ember
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Javascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web AppsJavascript Frameworks for Well Architected, Immersive Web Apps
Javascript Frameworks for Well Architected, Immersive Web Apps
 
Intro lift
Intro liftIntro lift
Intro lift
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
Ember App Kit & The Ember Resolver
Ember App Kit & The Ember ResolverEmber App Kit & The Ember Resolver
Ember App Kit & The Ember Resolver
 

Último

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 

Último (20)

Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 

Ember vs Backbone

  • 2. • Structure overview • Stand alone JS app • Using with RoR
  • 3. Backbone came out in June 2010 Many popular applications use the Backbone framework, including Twitter, Foursquare, and LinkedIn Mobile.Also worth noting is that a number of music apps were built with Backbone, including Soundcloud, Pitchfork, and Pandora. Backbone weight just 6.4K.
  • 4. Logic is outside of the DOM Structure logic Developed for work with REST API’s Almost MVC - Model,View, Route + Collection Philosophy
  • 5. Model Can be created, validated, destroyed, and saved to the server ! model.get('attr') model.set('attr', val) model.validate(attributes, options)
  • 6. There is no two-way data binding between your BackboneViews and Models But it can be added by using next solutions: http://rivetsjs.com/ http://nytimes.github.io/backbone.stickit/ Bindings
  • 7. View The main idea is to organize your code and give you an opportunity to use different callbacks and events triggers.
  • 8. el All views have a DOM element at all times (the el property), whether they've already been inserted into the page or not. ! ! template: JST[‚tutorials/new_tutor'] ! var BodyView = Backbone.View.extend({ el: 'body' }); ! @$el.html(@template)
  • 9. Events events: 'keyup #tutor-input': 'updatePreview' 'click .submit-tutorial': 'submitTutor' ! 'click #bold': 'boldStyler'
  • 10. Collections Is a sortable collection of models, which can filter, manage and control them. Accessing models: collection.models collection.at collection.get
  • 11. collection.add([{key: val}, {key: val}]) collection.remove collection.set collection.get(id) colleaction.at(index) collection.push(model, [options]) collection.pop(model, [options]) collection.pluck(“attr”) collection.where({job:‘Some’}) ! collection.fetch ! Underscore methods: find, contains, sortBy, groupBy, toArray, size, first, last, indexOf, isEmpty
  • 12. Routes Hash navigation - localhost#search/users/2 ! class Tutors.Routers.Tutorials.New extends Backbone.Router routes: '.*': 'addTutor' 'addTutor': 'addTutor'
  • 13. navigate router.navigate(fragment, [options]) ! ! ! ! Execute method is called internally within the router: var Router = Backbone.Router.extend({ execute: function(callback, args) { args.push(parseQueryString(args.pop())); if (callback) callback.apply(this, args); } });
  • 14. History serves as a global router to handle hashchange events, match the appropriate route, and trigger callbacks.You shouldn't ever have to create one of these yourself since Backbone.history already contains one. Just call it like this - Backbone.history.start Backbone.history
  • 15. Events Events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. book.on({ "change:title": titleView.update, "change:author": authorPane.update, "destroy": bookView.remove }); ! // Removes just the `onChange` callback. object.off("change", onChange); ! view.listenTo(model, 'change', view.render); !
  • 16. Catalog of Events • "add" (model, collection, options) — when a model is added to a collection. • "remove" (model, collection, options) — when a model is removed from a collection. • "reset" (collection, options) — when the collection's entire contents have been replaced. • "sort" (collection, options) — when the collection has been re-sorted. • "change" (model, options) — when a model's attributes have changed. • "change:[attribute]" (model, value, options) — when a specific attribute has been updated. • "destroy" (model, collection, options) — when a model is destroyed. • "request" (model_or_collection, xhr, options) — when a model or collection has started a request to the server. • "sync" (model_or_collection, resp, options) — when a model or collection has been successfully synced with the server. • "error" (model_or_collection, resp, options) — when model's or collection's request to remote server has failed. • "invalid" (model, error, options) — when a model's validation fails on the client. • "route:[name]" (params) — Fired by the router when a specific route is matched. • "route" (route, params) — Fired by the router when any route has been matched. • "route" (router, route, params) — Fired by history when any route has been matched. • "all" — this special event fires for any triggered event, passing the event name as the first
  • 17. Benefits 1) Standatized architecture of application, which will be very friendly for rails developers 2) Easy scallable and refactoring 3) A lot of methods for working with events, callbacks, models and collections With Backbone, you have some given assertions: Data lies in JavaScript objects, not the DOM Event handling lies in JavaScript objects, not jQuery event bindings The way you save data in a backend server is done through the objects that contain the data http://backbonejs.org/
  • 18.
  • 19. Initially released in 2011, Ember just hit version 1.0 last year. LivingSocial, Groupon, Zendesk, Discourse, and Square are some of the most well-known applications that have adopted Ember. Ember creators Tom Dale andYehuda Katz say it’s easy to see when a site is using Ember because of its loading speed. 69K minified and zipped
  • 20. The first step to creating an Ember.js application is to make an instance of Ember.Application and assign it to a global variable. ! window.App = Ember.Application.create(); ! INITIALIZING AN APPLICATION
  • 21. CORE CONCEPTS • TEMPLATES • ROUTER • COMPONENTS • MODELS • CONTROLLERS • VIEWS
  • 22. When your application boots, Ember will look for these objects:! ! ! App.ApplicationRoute! App.ApplicationModel! App.ApplicationController! the application template!
  • 23. A template, written in the Handlebars templating language, describes the user interface of your application. Each template is backed by a model, and the template automatically updates itself if the model changes. In addition to plain HTML, templates can contain: • Expressions, like {{firstName}}, which take information from the template's model and put it into HTML. • Outlets, which are placeholders for other templates.As users move around your app, different templates can be plugged into the outlet by the router.You can put outlets into your template using the {{outlet}} helper. • Components, custom HTML elements that you can use to clean up repetitive templates or create reusable controls. Templates
  • 24. Router The router translates a URL into a series of nested templates, each backed by a model.As the templates or models being shown to the user change, Ember automatically keeps the URL in the browser's address bar up-to-date. A route is an object that tells the template which model it should display. Each of your routes will have a controller, and a template with the same name as the route.
  • 25. App.Router.map(function() { this.route("about", { path: "/about" }); this.route("favorites", { path: "/ favs" }); }); ! Now, when the user visits /about, Ember.js will render the about template. Visiting /favs will render the favorites template. {{#link-to 'index'}}<img class="logo">{{/link-to}} ! <nav> {{#link-to 'about'}}About{{/link-to}} {{#link-to 'favorites'}}Favorites{{/link-to}} </nav>
  • 26. COMPONENTS A component is a custom HTML tag whose behavior you implement using JavaScript and whose appearance you describe using Handlebars templates. They allow you to create reusable controls that can simplify your application's templates.
  • 27. <script type="text/x-handlebars" id="components/blog-post"> <h1>Blog Post</h1> <p>Lorem ipsum dolor sit amet.</p> </script> ! <h1>My Blog</h1> {{#each}} {{blog-post}} {{/each}}
  • 28. <script type="text/x-handlebars" id="components/blog-post"> <h1>Component: {{title}}</h1> <p>Lorem ipsum dolor sit amet.</p> </script> ! ! App.IndexRoute = Ember.Route.extend({ model: function() { return { title: "Rails is awesome!" }; } }); ! ! {{blog-post title=title}} Passing an arguments
  • 29. MODELS A model is an object that stores persistent state. Templates are responsible for displaying the model to the user by turning it into HTML. In many applications, models are loaded via an HTTP JSON API, although Ember is agnostic to the backend that you choose. App.Person = DS.Model.extend(); ! store.find('person', 1);
  • 30. ONE-TO-ONE App.User = DS.Model.extend({ profile: DS.belongsTo('profile') }); ! App.Profile = DS.Model.extend({ user: DS.belongsTo('user') }); ONE-TO-MANY App.Post = DS.Model.extend({ comments: DS.hasMany('comment') }); ! App.Comment = DS.Model.extend({ post: DS.belongsTo('post') }); MANY-TO-MANY App.Post = DS.Model.extend({ tags: DS.hasMany('tag') }); ! App.Tag = DS.Model.extend({ posts: DS.hasMany('post') });
  • 31. store.createRecord('post', { title: 'Rails is Omakase', body: 'Lorem ipsum' }); store.find('post', 1).then(function (post) { post.deleteRecord(); post.get('isDeleted'); // => true post.save(); // => DELETE to /posts/1 }); ! // OR store.find('post', 2).then(function (post) { post.destroyRecord(); // => DELETE to /posts/2 }); DELETING RECORDS CREATING RECORDS
  • 33. CONTROLLERS A controller is an object that stores application state.A template can optionally have a controller in addition to a model, and can retrieve properties from both.
  • 34. REPRESENTING A SINGLE MODEL App.SongController = Ember.ObjectController.extend({ soundVolume: 1 }); <p> <strong>Song</strong>: {{name}} by {{artist}} </p> <p> <strong>Current Volume</strong>: {{soundVolume}} </p>
  • 35. REPRESENTING MULTIPLE MODELS App.SongsController = Ember.ArrayController.extend({ longSongCount: function() { var longSongs = this.filter(function(song) { return song.get('duration') > 30; }); return longSongs.get('length'); }.property('@each.duration') }); ! ! ! <ul> {{#each}} <li>{{name}} by {{artist}}</li> {{/each}} </ul> ! {{longSongCount}} songs over 30 seconds.
  • 36. VIEWS Views in Ember.js are typically only created for the following reasons: • When you need sophisticated handling of user events • When you want to create a re-usable component var view = Ember.View.create({ templateName: 'say-hello', name: "Bob" }); ! ! view.appendTo('#container');
  • 37. Handling events {{#view App.ClickableView}} This is a clickable area! {{/view}} ! ! App.ClickableView = Ember.View.extend({ click: function(evt) { alert("ClickableView was clicked!"); } });
  • 38. INSERTING VIEWS IN TEMPLATES // Define parent view App.UserView = Ember.View.extend({ templateName: 'user', ! firstName: "Albert", lastName: "Hofmann" }); ! // Define child view App.InfoView = Ember.View.extend({ templateName: 'info', ! posts: 25, hobbies: "Riding bicycles" }); ! <script type="text/x-handlebars" data-template-name="user"> User: {{view.firstName}} {{view.lastName}} {{view App.InfoView}} </script> ! <script type="text/x-handlebars" data-template-name="info"> <b>Posts:</b> {{view.posts}} <br> <b>Hobbies:</b> {{view.hobbies}} </script> RESULT User: Albert Hofmann <div> <b>Posts:</b> 25 <br> <b>Hobbies:</b> Riding bicycles </div>
  • 39. Benefits • Two-way data binding: objects in Ember are able to register bindings between one another.That way, whenever a bound property changes, the other one is updated automatically. • Computed properties: if you wish to have a property that is a result of a function, you can create them and assign a property as computed by that function. • Template auto-updates: when an object is updated in your app, all the views currently displayed in the screen that are bound to that object automatically reflect the change, with no boilerplate.
  • 40. Stand alone JS app http://yeoman.io/
  • 41. Backbone.js generator • npm install -g generator-backbone • mkdir my-new-project && cd $_ • yo backbone [app-name] ! https://github.com/yeoman/generator-backbone
  • 42. Ember.js Generator • npm install -g generator-ember • mkdir myemberapp && cd myemberapp(The directory's name is your application's name) • yo ember • npm install -g grunt-mocha • grunt serve
  • 43. Rails + JS Framework • Backbone on Rails • ember-rails
  • 44. Backbone on Rails gem 'backbone-on-rails' bundle install rails generate backbone:install rails generate backbone:scaffold NAME https://github.com/meleyal/backbone-on-rails http://moxa.ws/en/adding-backbone-js-in-rails-app-in-5- seconds/
  • 45. Ember on Rails gem 'ember-rails' gem 'ember-source', '1.5.0' # or the version you need bundle install rails g ember:bootstrap -g --javascript-engine coffee ! https://github.com/emberjs/ember-rails