• Complain

RachelLeach - Developing Backbone.js applications: [building better JavaScript applications]

Here you can read online RachelLeach - Developing Backbone.js applications: [building better JavaScript applications] full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: Beijing;Köln, year: 2013, publisher: OReilly Media, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

RachelLeach Developing Backbone.js applications: [building better JavaScript applications]

Developing Backbone.js applications: [building better JavaScript applications]: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Developing Backbone.js applications: [building better JavaScript applications]" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

If you want to build your sites frontend with the single-page application (SPA) model, this hands-on book shows you how to get the job done with Backbone.js. Youll learn how to create structured JavaScript applications, using Backbones own flavor of model-view-controller (MVC) architecture.

RachelLeach: author's other books


Who wrote Developing Backbone.js applications: [building better JavaScript applications]? Find out the surname, the name of the author of the book and a list of all author's works by series.

Developing Backbone.js applications: [building better JavaScript applications] — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Developing Backbone.js applications: [building better JavaScript applications]" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Appendix A. Further Learning
A Simple JavaScript MVC Implementation

A comprehensive discussion of Backbones implementation is beyond the scope of this book. I can, however, present a simple MVC librarywhich we will call Cranium.jsthat illustrates how frameworks such as Backbone implement the MVC pattern.

Like Backbone, we will rely on Underscore for inheritance and templating.

Event System

At the heart of our JavaScript MVC implementation is an Event system (object) based on the publisher-subscriber pattern, which makes it possible for MVC components to communicate in an elegant, decoupled manner. Subscribers listen for specific events of interest and react when publishers broadcast these events.

Event is mixed into both the view and model components so that instances of either of these components can publish events of interest.

// cranium.js - Cranium.EventsvarCranium=Cranium||{};// Set DOM selection utilityvar$=document.querySelector.bind(document)||this.jQuery||this.Zepto;// Mix in to any object in order to provide it with custom events.varEvents=Cranium.Events={// Keeps list of events and associated listenerschannels:{},// CountereventNumber:0,// Announce events and passes data to the listeners;trigger:function(events,data){for(vartopicinCranium.Events.channels){if(Cranium.Events.channels.hasOwnProperty(topic)){if(topic.split("-")[0]==events){Cranium.Events.channels[topic](data)!==false||deleteCranium.Events.channels[topic];}}}},// Registers an event type and its listeneron:function(events,callback){Cranium.Events.channels[events+--Cranium.Events.eventNumber]=callback;},// Unregisters an event type and its listeneroff:function(topic){deleteCranium.Events.channels[topic];}};

The Event system makes it possible for:

  • A view to notify its subscribers of user interaction (such as clicks or input in a form), to update/rerender its presentation, etc.

  • A model whose data has changed to notify its subscribers to update themselves (for example, view to rerender to show accurate/updated data) and so on.

Models

Models manage the (domain-specific) data for an application. They are concerned with neither the user interface nor presentation layers, but instead represent structured data that an application may require. When a model changes (such as when it is updated), it will typically notify its observers (subscribers) that a change has occurred so that they may react accordingly.

Lets see a simple implementation of the model:

// cranium.js - Cranium.Model// Attributes represents data, model's properties.// These are to be passed at Model instantiation.// Also we are creating id for each Model instance// so that it can identify itself (e.g., on chage// announcements)varModel=Cranium.Model=function(attributes){this.id=_.uniqueId('model');this.attributes=attributes||{};};// Getter (accessor) method;// returns named data itemCranium.Model.prototype.get=function(attrName){returnthis.attributes[attrName];};// Setter (mutator) method;// Set/mix in into model mapped data (e.g.{name: "John"})// and publishes the change eventCranium.Model.prototype.set=function(attrs){if(_.isObject(attrs)){_.extend(this.attributes,attrs);this.change(this.attributes);}returnthis;};// Returns clone of the Models data object// (used for view template rendering)Cranium.Model.prototype.toJSON=function(options){return_.clone(this.attributes);};// Helper function that announces changes to the Model// and passes the new dataCranium.Model.prototype.change=function(attrs){this.trigger(this.id
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Developing Backbone.js applications: [building better JavaScript applications]»

Look at similar books to Developing Backbone.js applications: [building better JavaScript applications]. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Developing Backbone.js applications: [building better JavaScript applications]»

Discussion, reviews of the book Developing Backbone.js applications: [building better JavaScript applications] and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.