项目作者: coroutine

项目描述 :
A JS library that laughs at your four winds.
高级语言: CoffeeScript
项目地址: git://github.com/coroutine/crom.git
创建时间: 2014-11-04T04:01:43Z
项目社区:https://github.com/coroutine/crom

开源协议:MIT License

下载


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:

  1. {
  2. "depth": 40,
  3. "units": "meters",
  4. "owner": {
  5. "name": "Crom",
  6. "title": "God of Steel"
  7. },
  8. "snakes": [
  9. {
  10. "length": "20",
  11. "units": "meters",
  12. "isVenomous": true,
  13. "likes": "killing the shit out of people."
  14. },
  15. {
  16. "length": "12",
  17. "units": "meters",
  18. "isVenomous": false,
  19. "likes": "long walks on the beach."
  20. }
  21. ]
  22. }

Crom Models

And now, the corresponding Backbone Models, leveraging Crom:

Person

  1. class Person extends Crom.Model
  2. defaults:
  3. name: null
  4. title: null

Snake

  1. class Snake extends Crom.Model
  2. defaults:
  3. length: 0
  4. units: null
  5. isVenomous: false
  6. likes: null

Snakes (Collection)

  1. class Snakes extends Crom.Collection
  2. model: Snake

Snakepit

  1. class Snakepit extends Crom.Model
  2. # our glorious RESTful endpoint
  3. url: 'http://example.com/snakepits'
  4. defaults:
  5. depth: 0
  6. units: null
  7. # Here we have some nested data
  8. nested: ->
  9. owner: Person
  10. snakes: Snakes

Putting it all together

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

  1. snakepit = new Snakepit(id: 1)
  2. snakepit.fetch()
  3. snakepit.owner # -> an instance of the Person model
  4. snakepit.snakes # -> an instance of the Snakes collection