I have been playing with backbonejs and CouchDB in my (limited) spare time to see how usable they are together.
Well I have a backbone collection and figured I would fetch a couch view into the collection. Now backbone expects an JSON array and couch gives you a single JSON object that has total and a rows etc.
I started to look around for someone on git that may have done this, not much luck. There were a couple of customisations that have been written but there were a few issues with using the latest backbone release.
I figured I’d start writing my own backbone extension that overrides the sync and fetch functions. I had already done a simple OData JSONP extension for work so I got started.
Then something in the back of my mind said ….list….
I realised you didn’t need to modify backbone, I could use a list function in couch. I even found someone on stackoverflow that had already written one (WIN)
The more I think about it couch is designed to do things like this, it will add in etags to help cache the list and I can even modify the list to handle different content types.
Hope this helps in some way.
I’ve been playing with CouchApp lately and I like the idea of making single page apps the rely a lot on Ajax and a chatty rather than chunky. I saw mustache.js the other day and decided to use it in my CouchApp.
I was rather surprised with it and I really like it. There is this simplicity to it that I really like. You have a model, you define a template, parse both into a function and bam you have yourself an output for data (almost).
I come from an asp.net background and data binding was a staple for me. I would define these data sources and then i would define a grid and then bind the data to the grid columns. Most of the time the standard controls would get you out of trouble but occasionally you would define a custom template the would automagically display what you wanted.
It wasn’t bad but it doesn’t feel as natural as mustache does. I picked this up very quickly and enjoy playing with it. Defining how a list was displayed was just as easy as displaying a single object. In .net land this was 2 separate data bound controls and some server side logic, in mustache it’s much more lean.
What I really like is how you just parse a template and a model through the mustache object. For me this is where you can separate logic, your views are objects that are platform agnostic and your mustache templates are browser specific (Mikito Takada’s single page app put this idea in my head).
I work in an environment where IE6 (don’t hate) is still the standard browser and we often run into the issues towards the end where a simple layout in standards land just looks crap on IE6. I intend to play with this some more and I believe this is going to save us time in the long haul.
If we just push things to the client as models and then have templates that are specific to a client then we should be a lot sweeter… In theory, all things work well in my head. I will test this out and post more on how things go later.
I would say that my organisation is responsible for Australia still being 0.8% on ie6countdown :)
I’ve been playing with CouchApp lately and have found it quite enjoyable. The version I’m playing with is the node.couchapp.js version. I installed it on my windows pc originally with a few hiccups due to paths for node modules.
After this I managed to do the same thing on Cloud 9 ide but more on this later.
One thing that annoyed me was the boiler command doesn’t feel complete. It gets you 80% there and then leaves you wanting.
The main thing was sammy doesn’t seem to work. I’m am publishing to a cloud based CouchDB server but I don’t think this should matter. I looked around at the repo history on git and comments were made to ignore sammy altogether.
It isn’t a big deal because you still have the crux of what boiler is supposed to do but having sammy there would be awesome in my opinion because it would just make the design doc feel a lot more app like.
A missing feature I would like to see is a ‘couchapp pull’ meaning i could go to a couchdb and download their design doc and it would get converted into a couchapp with the relevant JS file and attachments in my local directory.
One last thing is you should try cloud 9 IDE, it integrates with git and I’ve managed to install node and CouchApp on there. In the end I have a full end to end development environment that runs from a browser. Data is pushed to iriscouch, source is stored on git and cloud 9 is my ide.
I’ve been using this for a week now and haven’t had an issue with it. I’ll blog more details on this later.