SlideShare uma empresa Scribd logo
Filipe Giusti
Roadmap
● Introdução
● Básico
○
○
○
○
○

Características
Model
View
Eventos
Router

● Além
Introdução
● Estrutura mínima para uma app decente
● Release inicial 10/2010
● MV alguma coisa
○ Porque sempre tem MV?

● Única dependência: Underscore.js
○ Para usar router e persistência: jQuery ou Zepto

● Comunidade: suficiente
Básico - Características
Backbone.js gives structure to web applications
by providing models with key-value binding
and custom events, collections with a rich API
of enumerable functions, views with declarative
event handling, and connects it all to your
existing API over a RESTful JSON interface.
Básico - Model
// Our basic **Todo** model has `title`, `order`, and `completed` attributes.
app.Todo = Backbone.Model.extend({
defaults: {
title: '',
completed: false
},

// Toggle the `completed` state of this todo item.
toggle: function () {
this.save({completed: !this.get('completed')});
}
});
var todo1 = new app.Todo({title: 'First title', order: 1});
Básico - Model
●
●
●
●
●
●
●

initialize
get & set
id
attributes
changedAttributes
parse
toJSON
Básico - Model
● Observer pattern
● Validação
○ isValid - validation
○ Backbone.validation

● Relações
○ backbone-relational.js
○ backbone-associations
○ supermodel.js
Básico - Model
● Persistência
○
○
○
○
○
○

url - urlRoot
parse
sync - fetch - save - destroy
REST JSON
LocalStorage?
Websockets?
Básico - Model - Persistência
app.Todo = Backbone.Model.extend({
urlRoot: '/todos'
});
var todo2 = new app.Todo({title: 'First title', order: 1});
var todo3 = new app.Todo({id: 5, title: 'First title', order:
1});
todo2.url(); // "/todos"
todo3.url(); // "/todos/5"
Básico - Model - Collections
app.TodosCollection = Backbone.Collection.extend({
model: app.Todo
});
var todos = new app.TodosCollection([todo2, todo3]);
todos.length; // 2
todos.fetch();
todos.create({});
todos.add(todo2);
Backbone.sync(method, model, options);

E diversos métodos do Underscore.js.
Básico - View
● Duas partes
○ Declarativa
■ el
■ model binding
■ events
○ Procedural
■ render
■ Controller
Básico - View
app.TodoView = Backbone.View.extend({
el: '#todo',
events: {
'keypress .edit': 'updateOnEnter',
'blur .edit':
'close'
},
render: function() {
return this.$el.html( TemplateEngine.run( this.model.toJSON() ) );
},
close: function() { // executed when todo loses focus },
updateOnEnter: function( e ) { // executed on each keypress when in todo edit mode }
});
var todoView = new app.TodoView({model: todo2});
todoview.render();
Básico - Eventos
Backbone.on('event', function() {console.log('Handled Backbone event');});
Backbone.trigger('event'); // logs: Handled Backbone event

● on - off - trigger - once - listenTo
● Eventos do backbone
○ add - remove - reset - sort - change - error - route

● Custom
Básico - Router
app.TodoRouter = Backbone.Router.extend({
routes: {
"about" : "showAbout",
/* http://example.com/#about */
"todo/:id" : "getTodo",
/* http://example.com/#todo/5 */
"todos/:id/download/*documentPath" : "downloadDocument",
/* http://example.com/#todos/5/download/files/Meeting_schedule.doc */
},
showAbout: function(){
},
getTodo: function(id){
},
getTodo: function(id, path){
}
});
var myTodoRouter = new app.TodoRouter();
Backbone.history.start();
myTodoRouter.navigate('todo/5');
Além do Backbone
● Funcionalidade ausentes
○ Atributos virtuais
○ Hierarquia nas views
○ Form validation

● Marionette
○ Seta alguns padrões como o template
○ Facilita as views
■ Subview, regions, layout

● Crescimento da aplicação
Referências
● http://backbonejs.org/
● http://todomvc.com/architectureexamples/backbone/
● http://addyosmani.github.io/backbonefundamentals/

Mais conteúdo relacionado

PDF
Spa com angular js flisol 2015 - aquidauana ms
PDF
Tutorial AngularJS - Episódio 4 - Controllers
PDF
Backbone.js - Desenvolvimento de Sistemas Corporativos - UFPB - Campus IV
PDF
LabMM3 - Aula teórica 09
PDF
jQuery básico (parte 3)
PDF
JavaScript Model-View no Frontend
PDF
AngularJS Components - Semana da Informática 2016
PPTX
Criando serviços com AngularJS
Spa com angular js flisol 2015 - aquidauana ms
Tutorial AngularJS - Episódio 4 - Controllers
Backbone.js - Desenvolvimento de Sistemas Corporativos - UFPB - Campus IV
LabMM3 - Aula teórica 09
jQuery básico (parte 3)
JavaScript Model-View no Frontend
AngularJS Components - Semana da Informática 2016
Criando serviços com AngularJS

Mais procurados (12)

PDF
Angular js
PPT
BDD com Easyb
PDF
Backbone.js + Rails - Front-end e back-end conectados
PDF
(A11) LabMM3 - JavaScript - Subalgoritmos e scope
PDF
T11_LM3: Subalgoritmose colisões (2013-2014)
PDF
Workshop React Hooks
PDF
TDC2015 Porto Alegre - Interfaces ricas com Rails e React.JS
PDF
Zend Framework 1.11
PDF
Interfaces ricas com Rails e React.JS @ Rubyconf 2015
PDF
Node.js - #7 - Core Modules - http - Parte 1 - Rodrigo Branas
PDF
Desenvolvimento Front end (AngularJS e Bootstrap)
Angular js
BDD com Easyb
Backbone.js + Rails - Front-end e back-end conectados
(A11) LabMM3 - JavaScript - Subalgoritmos e scope
T11_LM3: Subalgoritmose colisões (2013-2014)
Workshop React Hooks
TDC2015 Porto Alegre - Interfaces ricas com Rails e React.JS
Zend Framework 1.11
Interfaces ricas com Rails e React.JS @ Rubyconf 2015
Node.js - #7 - Core Modules - http - Parte 1 - Rodrigo Branas
Desenvolvimento Front end (AngularJS e Bootstrap)
Anúncio

Destaque (20)

PPT
BIMobject for manufacturers 2013
PPTX
Webvisions talk 2015 09252015 final
PDF
Microsoft word mengurus perubahan
PPTX
Ppt recount
PPTX
Bark & Co
PDF
NCCU School of Business Year In Review
PDF
Eia2012 Early Release
PDF
Freello | Mobile Marketing 4 Media
PDF
Securitisation and Standby Servicing - a strategic solution from HML
PPTX
Get a Seat at the Table: Utah's Legislature and How it Impacts Your Business
DOCX
Project proposal
PDF
La DoloMeetCard con l'hotel Gianna
PDF
PDF
Freello #JustOneRing
DOCX
Loving Avacados
PDF
Freello mobile-marketing-4-brands
PPT
Car Trading Meeting
PPTX
Personal Injury Cases: Case Intake and Screening
PPTX
2014 c-delaware (us compared) - rev 1.1
PPTX
Cijferend optellen3
BIMobject for manufacturers 2013
Webvisions talk 2015 09252015 final
Microsoft word mengurus perubahan
Ppt recount
Bark & Co
NCCU School of Business Year In Review
Eia2012 Early Release
Freello | Mobile Marketing 4 Media
Securitisation and Standby Servicing - a strategic solution from HML
Get a Seat at the Table: Utah's Legislature and How it Impacts Your Business
Project proposal
La DoloMeetCard con l'hotel Gianna
Freello #JustOneRing
Loving Avacados
Freello mobile-marketing-4-brands
Car Trading Meeting
Personal Injury Cases: Case Intake and Screening
2014 c-delaware (us compared) - rev 1.1
Cijferend optellen3
Anúncio

Semelhante a Backbone.js (20)

PDF
Construindo portlets para IBM WebSphere Portal – Parte 2
PDF
Programando para programadores: Desafios na evolução de um Framework
PDF
TDC São Paulo 2015 - Interfaces Ricas com Rails e React.JS
PPTX
PDF
Introdução ao Zend Framework 2
PDF
(A10) LabMM3 - JavaScript - Subalgoritmos
PDF
Kotlin first
PDF
Testando Rails apps com RSpec
PPTX
Material Design - Melhorando a experiência de seu App
PDF
Utiizando o Celular no Apoio à Gerência de configuração
PDF
iOS Delegates - Mobile Conf Rio 2014
PDF
JSF 2.0 e ScrumToys
PDF
Desenvolvimento de Aplicações para o Google App Engine (CPBR5)
PDF
Desenvolvimento de aplicações para o Google App Engine
PDF
Caelum Day In Rio
PPTX
Aula02 android hands_on
PDF
Padrões-05 - Padrões Arquiteturais - MVC
PDF
Spring MVC Framework
PDF
Criando uma arquitetura de front-end do zero
PDF
O que esperar do Zend Framework 3
Construindo portlets para IBM WebSphere Portal – Parte 2
Programando para programadores: Desafios na evolução de um Framework
TDC São Paulo 2015 - Interfaces Ricas com Rails e React.JS
Introdução ao Zend Framework 2
(A10) LabMM3 - JavaScript - Subalgoritmos
Kotlin first
Testando Rails apps com RSpec
Material Design - Melhorando a experiência de seu App
Utiizando o Celular no Apoio à Gerência de configuração
iOS Delegates - Mobile Conf Rio 2014
JSF 2.0 e ScrumToys
Desenvolvimento de Aplicações para o Google App Engine (CPBR5)
Desenvolvimento de aplicações para o Google App Engine
Caelum Day In Rio
Aula02 android hands_on
Padrões-05 - Padrões Arquiteturais - MVC
Spring MVC Framework
Criando uma arquitetura de front-end do zero
O que esperar do Zend Framework 3

Último (20)

PDF
Fullfilment AI - Forum ecommerce 2025 // Distrito e Total Express
PPTX
Émile Durkheim slide elaborado muito bom
PDF
Custos e liquidação no SAP Transportation Management, TM130 Col18
PPTX
Curso de Java 15 - (Uso de Servlets (Entendendo a Estrutura)).pptx
PDF
Apple Pippin Uma breve introdução. - David Glotz
PPTX
BANCO DE DADOS - AULAS INICIAIS-sgbd.pptx
PDF
Gestão de transportes básica no SAP S/4HANA, S4611 Col20
PDF
Custos e faturamento no SAP S/4HANA Transportation Management, S4TM3 Col26
PPTX
Aula 18 - Manipulacao De Arquivos python
PPTX
Curso de Java 12 - (JDBC, Transation, Commit e Rollback).pptx
PPTX
Gestao-de-Bugs-em-Software-Introducao.pptxxxxxxxx
PPTX
Curso de Java 13 - (JavaEE (JSP e Servlets)).pptx
PDF
Mergulho profundo técnico para gestão de transportes no SAP S/4HANA, S4TM6 Col14
PDF
Fundamentos de gerenciamento de ordens e planejamento no SAP TransportationMa...
PPTX
Curso de Java 11 - (Serializable (Serialização de Objetos)).pptx
PPTX
Curso de Java 9 - (Threads) Multitarefas.pptx
PDF
Processos na gestão de transportes, TM100 Col18
PDF
Otimizador de planejamento e execução no SAP Transportation Management, TM120...
PDF
COBITxITIL-Entenda as diferença em uso governança TI
PPTX
Programação - Linguagem C - Variáveis, Palavras Reservadas, tipos de dados, c...
Fullfilment AI - Forum ecommerce 2025 // Distrito e Total Express
Émile Durkheim slide elaborado muito bom
Custos e liquidação no SAP Transportation Management, TM130 Col18
Curso de Java 15 - (Uso de Servlets (Entendendo a Estrutura)).pptx
Apple Pippin Uma breve introdução. - David Glotz
BANCO DE DADOS - AULAS INICIAIS-sgbd.pptx
Gestão de transportes básica no SAP S/4HANA, S4611 Col20
Custos e faturamento no SAP S/4HANA Transportation Management, S4TM3 Col26
Aula 18 - Manipulacao De Arquivos python
Curso de Java 12 - (JDBC, Transation, Commit e Rollback).pptx
Gestao-de-Bugs-em-Software-Introducao.pptxxxxxxxx
Curso de Java 13 - (JavaEE (JSP e Servlets)).pptx
Mergulho profundo técnico para gestão de transportes no SAP S/4HANA, S4TM6 Col14
Fundamentos de gerenciamento de ordens e planejamento no SAP TransportationMa...
Curso de Java 11 - (Serializable (Serialização de Objetos)).pptx
Curso de Java 9 - (Threads) Multitarefas.pptx
Processos na gestão de transportes, TM100 Col18
Otimizador de planejamento e execução no SAP Transportation Management, TM120...
COBITxITIL-Entenda as diferença em uso governança TI
Programação - Linguagem C - Variáveis, Palavras Reservadas, tipos de dados, c...

Backbone.js

  • 3. Introdução ● Estrutura mínima para uma app decente ● Release inicial 10/2010 ● MV alguma coisa ○ Porque sempre tem MV? ● Única dependência: Underscore.js ○ Para usar router e persistência: jQuery ou Zepto ● Comunidade: suficiente
  • 4. Básico - Características Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 5. Básico - Model // Our basic **Todo** model has `title`, `order`, and `completed` attributes. app.Todo = Backbone.Model.extend({ defaults: { title: '', completed: false }, // Toggle the `completed` state of this todo item. toggle: function () { this.save({completed: !this.get('completed')}); } }); var todo1 = new app.Todo({title: 'First title', order: 1});
  • 6. Básico - Model ● ● ● ● ● ● ● initialize get & set id attributes changedAttributes parse toJSON
  • 7. Básico - Model ● Observer pattern ● Validação ○ isValid - validation ○ Backbone.validation ● Relações ○ backbone-relational.js ○ backbone-associations ○ supermodel.js
  • 8. Básico - Model ● Persistência ○ ○ ○ ○ ○ ○ url - urlRoot parse sync - fetch - save - destroy REST JSON LocalStorage? Websockets?
  • 9. Básico - Model - Persistência app.Todo = Backbone.Model.extend({ urlRoot: '/todos' }); var todo2 = new app.Todo({title: 'First title', order: 1}); var todo3 = new app.Todo({id: 5, title: 'First title', order: 1}); todo2.url(); // "/todos" todo3.url(); // "/todos/5"
  • 10. Básico - Model - Collections app.TodosCollection = Backbone.Collection.extend({ model: app.Todo }); var todos = new app.TodosCollection([todo2, todo3]); todos.length; // 2 todos.fetch(); todos.create({}); todos.add(todo2); Backbone.sync(method, model, options); E diversos métodos do Underscore.js.
  • 11. Básico - View ● Duas partes ○ Declarativa ■ el ■ model binding ■ events ○ Procedural ■ render ■ Controller
  • 12. Básico - View app.TodoView = Backbone.View.extend({ el: '#todo', events: { 'keypress .edit': 'updateOnEnter', 'blur .edit': 'close' }, render: function() { return this.$el.html( TemplateEngine.run( this.model.toJSON() ) ); }, close: function() { // executed when todo loses focus }, updateOnEnter: function( e ) { // executed on each keypress when in todo edit mode } }); var todoView = new app.TodoView({model: todo2}); todoview.render();
  • 13. Básico - Eventos Backbone.on('event', function() {console.log('Handled Backbone event');}); Backbone.trigger('event'); // logs: Handled Backbone event ● on - off - trigger - once - listenTo ● Eventos do backbone ○ add - remove - reset - sort - change - error - route ● Custom
  • 14. Básico - Router app.TodoRouter = Backbone.Router.extend({ routes: { "about" : "showAbout", /* http://example.com/#about */ "todo/:id" : "getTodo", /* http://example.com/#todo/5 */ "todos/:id/download/*documentPath" : "downloadDocument", /* http://example.com/#todos/5/download/files/Meeting_schedule.doc */ }, showAbout: function(){ }, getTodo: function(id){ }, getTodo: function(id, path){ } }); var myTodoRouter = new app.TodoRouter(); Backbone.history.start(); myTodoRouter.navigate('todo/5');
  • 15. Além do Backbone ● Funcionalidade ausentes ○ Atributos virtuais ○ Hierarquia nas views ○ Form validation ● Marionette ○ Seta alguns padrões como o template ○ Facilita as views ■ Subview, regions, layout ● Crescimento da aplicação