Skip to content

Repository files navigation

Crom

A JS library that laughs at your four winds.

Crom!

Example

Server Response

Below is our example JSON response from the RESTful API endpoint http://example.com/snakepits/1.json:

{
"depth": 40,
"units": "meters",
"owner": {
"name": "Crom",
"title": "God of Steel"
},
"snakes": [
{
"length": "20",
"units": "meters",
"isVenomous": true,
"likes": "killing the shit out of people."
},
{
"length": "12",
"units": "meters",
"isVenomous": false,
"likes": "long walks on the beach."
}
]
}

Crom Models

And now, the corresponding Backbone Models, leveraging Crom:

Person

classPersonextendsCrom.Modeldefaults:name:nulltitle:null

Snake

classSnakeextendsCrom.Modeldefaults:length:0units:nullisVenomous:falselikes:null

Snakes (Collection)

classSnakesextendsCrom.Collectionmodel: Snake

Snakepit

classSnakepitextendsCrom.Model# our glorious RESTful endpointurl:'http://example.com/snakepits'defaults:depth:0units:null# Here we have some nested datanested:->owner: Person
snakes: Snakes

Putting it all together

Now we're able to put our models to the test:

snakepit=newSnakepit(id:1)
snakepit.fetch()
snakepit.owner# -> an instance of the Person modelsnakepit.snakes# -> an instance of the Snakes collection

About

A JS library that laughs at your four winds.

Topics

Resources

Stars

0 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages