js-model
A cheatsheet by @rstacruz|Refreshed 7 months ago.Refresh|View source on Github

Example

Example

Project = Model "project", ->
  @extend
    findByTitle: (title) -> ...

  @include
    markAsDone: -> ...

  # ActiveRecord::Base.include_root_in_json = false
project = Project.find(1)
project = Project.findByTitle("hello")

project.markAsDone()

Persistence

Persistence

Project "hi", ->
  @persistence Model.REST, "/projects"
  @persistence Model.localStorage
Project.load ->
  # loaded

Attrs

Attrs

project = new Project(name: "Hello")

project.attr('name', "Hey")
project.attr('name')

project.save()
project.destroy()

Collection

Collection

Food.add(egg)
Food.all()
Food.select (food) -> ...
Food.first()
Food.find(id)

Events

Events

# Classes
Project.bind "add", (obj) ->
Project.bind "remove", (obj) ->
# Instances
project.bind "update", ->
project.bind "destroy", ->
project.trigger "turn_blue"