Javascript (Like C++ used to compile to C) Backbone.JS is only one Javascript file at 1,200 lines of code It uses another library called Underscore.JS which has Ruby like operations eg, map, reduce. _.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); }); => [5, 4, 6, 3, 1, 2] The purpose of Backbone to allow a webpage to act like the Gmail client page, it does not need to refresh the entire browser to go to different parts of the application. Monday, 13 February, 12
going from page to page. - Event binding: events that trigger and call methods such as when something changes. You can create your own event classes and call events on anything. - Models and Collections: Store data. Can contain business logic prior to persisting or updating. - Controller: is just a router, normally not containing much code. - View: Contains code which binds models and collections to the screen. Monday, 13 February, 12
lines of code that make up Backbone.js to understand what is going on. There are a lot of online tutorials BUT they all do things in different ways. Monday, 13 February, 12
click on the inbox. The Top URL is: https://mail.google.com/mail/?shva=1#inbox When I clicked on a email the Top URL is: https://mail.google.com/mail/?shva=1#sent/13557e8da95957b5 If I click on Starred, the Top URL is: https://mail.google.com/mail/?shva=1#starred What changed? The webpage didn’t refresh the page, it fetched the content by “ajax” and kept track of the route by the # (hash/pound) symbol. The tracking by #... is called the Route Monday, 13 February, 12
attributes View only displays data on the screen such as forms or tables of data Controller does all the work fetching data from the database CRUD (Create, Read, Update, Delete) Pushing data to the view and saving it to the model C M V Monday, 13 February, 12
storage. R M & C V Models and Collections usually store data which was or is stored on the server, or could be just stored in the client browser. Collections can be joined with views to display data in a list, this is mostly why collections are useful. Collections can also be “bound” to client or server data stores, allowing them to be synchronized when you Create, Read, Update, Delete the collection. Monday, 13 February, 12
storage. R M & C V Collections can also be “bound” to client or server data stores, allowing them to be synchronized when you Create, Read, Update, Delete the collection. Monday, 13 February, 12
storage. R M & C V Models. Models are classes which allow data to be stored. You can place business logic in the models, such as before save. Monday, 13 February, 12
So I cover the following: A. Easy ways to program in it B. Some problems I encountered C. Learning resources, books, videos, etc Monday, 13 February, 12
many “secrets” -> and => have two different meanings. -> means execute in the scope of the caller => means execute in the scope of the object instance If someone clicks on a button then calls a method on a object instance of this class, then testVariable is not in scope because of -> class TEST testVariable = 0 testMethod: -> alert(testVariable) fails Monday, 13 February, 12
a function to be bound to a model or collection, so if the model (or collection) changes, some function can get called. This allows asynchronous events to occur and for code to BIND to events at any time. Monday, 13 February, 12
set values on a model. When a model value is set, a validation event can be triggered which calls a validation function. When a collection is changed, the UI should update automatically! Monday, 13 February, 12
Class which acts as a view, the purpose is to display information to the user and to interact with the user. Views can be nested within views, so its good to have many small views for parts of the screen. Monday, 13 February, 12
difficult to learn. I don’t see anything bad about it. Backbone is good and bad: A. Does not force any way to use it, different to Ruby on Rails which suggests normally a way to use it. This is bad because its hard to get started without knowing the “right” way to use it. Why is Ruby on Rails easy? As there is a right way and easy way to use it. This is good as it gives flexibility, someone with a lot of experience in Backbone would be very good at making a dynamic client UI. But a small amount of experience is not good. Monday, 13 February, 12
minimal library without many features, many people write libraries around it to perform functions. https://github.com/powmedia/backbone-forms BackBone forms makes form binding and validation easier. https://github.com/n-time/backbone.validations Makes form validation easier. Many extensions here, google search backbone js extensions: https://github.com/documentcloud/backbone/wiki/Extensions,- Plugins,-Resources Monday, 13 February, 12
glue between libraries on the UI. That is, it allows javascript libraries from many developers and UI (JQuery) to be glued together, this gives a lot of freedom in controlling and developing the UI. Also freedom to choose form many libraries. D. I don’t like separation of client and server code bases. Liftweb in Scala can keep most Javascript code generated from the server side so most code resides on the server side. E. No books yet, well no published books - lots of other resources. Monday, 13 February, 12