Modular & Event driven
   UI Architecture
     Vytautas Butkus
Content
•   Modules
•   Event driven architecture
•   Backbone.js - MV* framework
•   Questions
Modules
• What is it?
• Single, solid unit
• Have interfaces defined
• Made of multiple other modules
Modules
• What is it?
• Why use it?
•   Loose coupling
•   Easier maintanance
•   Changes affects only changed modules
•   Removed module does not break page
Modules
• What is it?
• Why use it?
• Modules in real life
Gmail system
Possible modules
Modules structure
Event driven architecture
• What is it?
Publish/Subscribe pattern
Event driven architecture
• What is it?
• Where is it used?
•   Node.js
•   jQuery.events
•   Backbone.js
•   OS interrups

$(“.button”).on(“click”, function(){
$(“body”).on(“click”, function(){
    $(“body”).trigger(“alarm”);
    alert(“Clicked”);
});
$(“body”).on(“alarm”, function(){
    alert(“Alarm alarm!!!”);
});
Backbone.js
                 library
•   Structural framework
•   Very popular
•   Huge community
•   Still under v1.0
•   RESTful JSON interface
•   Based on MVC paradigm
                MV*
Backbone tools
•   Models                         => { } with events & sync

•   Views                          => DOM controller

•   Collections (not controller)   => Array of models

•   Router                         => URL controller

•   Events                         => Extend native { }
Underscore.js
•   Utility-belt library
•   Eases work with collections, arrays & objects
•   Provides function helpers
•   The only one Backbone.js dependency
Other MV* frameworks
•   AngularJS (by Google)
•   Ember.js
•   YUI (by Yahoo!)
•   KnockoutJS
...many more

• Check them out at
Gmail example with Backbone.js
•   Collection -> Message List
•   Model -> Message
•   Views -> Message, Message List
•   Router -> URL
Model
Collection
Message View
Message list view
Router
Init
Source code
• https://github.com/bytasv/gmail-example
Thank you!

Modular & Event driven UI Architecture