Backbone-Atlas is an extension for Backbone that provides a cleaner way of loading relations and data within any model. It does not overwrites Backbone.Atlas and helps in having chained relations.
In an ager for finding a cleaner way for working with Rails but in the client side I started to work with Backbone and realized that it provides a huge set of tools to create incredible rich client side applications.
One of the most common helpers to use within a ruby application is current_user and I'd really like to have something similar in my client application. So with that in mind I started to code.
Atlas provides attribute accessibility like ruby instead of using the .get(attr) from backbone. So instead of writing
current_user.get('posts')
Now you can do this
current_user.posts
There are some rules to make this extension to work. You must inherit from Backbone.Atlas.Model and you must be explicit in the key you want to use this is an example
class @Post extends Backbone.Atlas.Model
initialize: (attributes) ->
@has attributes,
comments: CommentList
author: User
This will give you an author attribute to the model, initializated nil after creation, if loaded with json data will instance the model for the relation
post = new Post({
id: 1,
title: 'Uber Title',
author: {
id: 29,
name: 'Joe Doe'
}
})
Now accesible like this:
post.id # => nil
post.author # => User
post.author.name # => Joe Doe
You can find more in Backbone Atlas with more examples. This is really simple but supports deep nesting of objects and relations.
In a few days a new version will be available, with npm support and internal identity map.