backbone introdunction

25
an intro to the javascript mvc framework

Upload: mzxbupt

Post on 02-Jul-2015

663 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Backbone introdunction

an intro to the javascript mvc framework

Page 2: Backbone introdunction

plan

Why BackboneBackbone architectureExamples

Page 3: Backbone introdunction

What we want to avoid

We have to store object informations into the DOM

Page 4: Backbone introdunction

What we want to avoid

callback hell

Page 5: Backbone introdunction
Page 6: Backbone introdunction

Why Backbone

So, what do we need?• Abstraction.• Decoupling UI from Data.• No more callbacks.

Page 7: Backbone introdunction

Backbone.jsFrom the Backbone website...

Backbone.js gives structure to web applications by providingmodels 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.

represent datas

list of modelmanipulate doms

Page 8: Backbone introdunction

Architecture

Page 9: Backbone introdunction

Backbone s Modelʼ

Representing data

Handling persistence

Throws events

Page 10: Backbone introdunction

Backbone s Modelʼ

Page 11: Backbone introdunction

Backbone s Modelʼ

Page 12: Backbone introdunction

Backbone s ʼ View

Manipulates the Dom

delegates Dom events

Page 13: Backbone introdunction

Backbone s ʼ View

Page 14: Backbone introdunction

Backbone s ʼ View

Page 15: Backbone introdunction

Backbone s ʼ Collections

Collections are ordered sets of models

bind "change" events to be notified when any modelin the collection has been modified

fetch the collection from the server (or otherpersistence layer)

Page 16: Backbone introdunction
Page 17: Backbone introdunction

Backbone s ʼ Collections

_.include([1, 2, 3], 3);=> true

Page 18: Backbone introdunction

APP

Page 19: Backbone introdunction

Architecture

Dependencies:• jQuery or Zepto• Underscore.js 16k

backbone.js 12kMustache.js 14k

Page 20: Backbone introdunction

Examples

Page 21: Backbone introdunction
Page 22: Backbone introdunction
Page 23: Backbone introdunction
Page 24: Backbone introdunction
Page 25: Backbone introdunction

Q u e s t io n s ?