Batman.js is no longer in production at Shopify and is not actively maintained.

This website is left for reference (and for old times' sake).

batman.js

Batman 0.8.0 released: Association support, pagination, and stability.

posted on 22 November 2011

Batman 0.8.0 is available on github and npm now.

The main new features:

Serious association support

You can now tell your models about their associated records and they will lazily fetch them, reload them, and deserialize them from inline JSON.

class Store extends Batman.Model
  @hasMany 'products'

class Product extends Batman.Model
  @belongsTo 'store'

store = new Store(id: 1)
store.get('products') # returns a Batman.Set which will be populated with the store's products

The objects returned by the association getters are smart enough to know if they have already been loaded, and they define a load function which you can use to reload them. Association can be loaded via inline JSON (like in the Shopify API) and they save themselves by serializing into their parent’s JSON, which means they work out of the box with Rails models which accept_nested_attributes_for their children.

Pagination

Batman can now paginate a large server side set without much work from you. You just have to tell it what parameters to send to the server, and then interpret them on the server side.

class ProductPaginator extends Batman.ModelPaginator
  model: App.Product
  limit: 25
  totalProducts: 100
  # Optionally override paramsForOffsetAndLimit(offset, limit) to define
  # what params to send to the server

products = new ProductPaginator
products.get('page') #=> 1
products.get('toArray') #=> [Product, Product, Product...]

Serious bugfixes

A huge swath of bugs have been squashed, so batman should be even easier build awesome apps with. Batman uses a whole lot less memory now as well, so it should be that much faster. For more information on what bugs have been fixed, see the changelog. As always, if you want to help squash some yourself, you can head over to Batman on Github and help us out!

Thanks

We’d also like to thank all the people on GitHub which have helped us get to this point so far: Pieter van de Bruggen, Damir, Willem van Bergen, Marcin Ciunelis, Brian Beck, Paul Miller, David Mosher, Tobias Lütke, Kyle Finley, Morita Hajime, Fernando Correia, Erik Behrends, cj, Richard Hooker, Rasmus Rønn Nielsen, and Jonathan Rudenberg. Air high five!

You can see the full diff for 0.8.0 here on Github. If you have any questions or run into any problems, feel free to post on the mailing list or come hang out in IRC in #batmanjs on Freenode.

It takes about 10 seconds to get a bare app generated and running on localhost, so it’s easy to start exploring. Take a look at the documentation and examples, build some cool stuff, and tell us all about it :)

Nick, James, Harry, and Kamil