Backbone.js, laravel, Mercurial and Amazon Web Services SimpleDB

Yeah! working with all of these technologies for a microsite, all new to me so stay tuned for progress updates.
Backbone.js is more than powerful, it's a paradigm shift.

An update 9/7/2011
Backbone.js
- remember for each view method to include each method in the call to _.bindAll() so that this can be used
- if I want to use regex in a Router it appears I have to manually add the route in initialize() e.g.
this.route(/search/, "search", this.list); // matches url with /search in it and calls list()
- be careful of what model/model events you bind views to; can have unintended consequences
- backbone.js is a new framework, there are some examples and Q&A on stackoverflow but some questions are harder to answer. I would also like to see a little more in the documentation e.g. using regex in route
- I think I created too many view classes for parts of the main list page. So I removed 2 views and just consolidated them into the main list view class. Other view elements which appear in multiple places remain their own view at this time.
- See post re Rest and url params. The wisdom of such an approach when using backbone is being tested since backbone routes can parse out urls but not url params. So I'm having to do that manually.
- Lots of learning from the trenches for model.save() how it works for php and in case of errors. It's still not sending just the attribute(s) I changed and passed to save(). Plus if I return a 404 error from save() the model stay set to what was sent.



Laravel
- nice simple framework especially for acting as a rest api server
- I can see it has an active community
- but very basic in what it offers, e.g. I have to add my own logger class , packages. Kind of understandable since it was basically launched this year, 2011. For a fully fledged site I would stick with symfony which is much more a complete framework .

Amazon Web Services
- a breeze, props to amazon on the design, implementation, videos, docs and php sdk
- to support dev, test and prod I think I'll need to create separate SimpleDB domains and use appropriately depending on the env defined in laravel

Mercurial
- Tortoise has a Hg ui. So I committed and pushed. Seems straightforward but I've only learned the basics thus far.




Some Notes I've taken based on reading posts etc.

Model responsible for:
 storing data
 provide setters/getters
 fire event when modified
 optionally make rest calls for persistence
 in Chrome can create new model in console e.g.
  customization = new Customization({customizationId: 'CustId1', salesAssociateId: 'Denis'})
 

View responsible for:
 displaying data (taking model and redering using template and putting into the doc)
 listening for events
 redisplay based on data changes

Collections 
 manage groups of Models
 expect to use one for each kind of model (probably)
 events: add, remove, reset

BackBone views
--------------
Backbone views are built around data. Views react to changes in data. You change the data and the views react.
this.el - what html element view is associated with, backbone will generate a div by default,
            but you can change from div to something else using "tagName" property (built in attribute)
  but could actually define what el is in property as view e.g. el:
  can also pass in "tagName" into the ctor of a view

Pass Custom props to view
  can pass into ctor, then referenced in initialize   initialize: function(params) { this.name = params.name}
  or could also set as property in view var once created

View Events
  events: {'click #say-hello': 'render'
  },
  - this says when user clicks elem with id 'say-hello' call the render method  , could also use a css class as selector
  - but be careful, since these selectors look within the el for the view, i.e. uses context of element view is associated with
     
Calling super on ParentView  
Here's how you'd call a ParentView ctor from child initialize()
  ParentView.prototype.initialize.call(this);

Templating
Backbone comes with the underscore templating engine, but can also use jQuery templating instead


Routers
-------
"The rule that I use for controller methods is that they should only do 3 things:
(1) get the data from the server to populate the models,
(2) process that data for the views, and
(3) instantiate the views."

Comments

Post a Comment

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more