Js Model Cheat Sheet

From WikiOD

Here is the cheatsheat of Js Model and basic guide on how to use Js Model

Example[edit | edit source]

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[edit | edit source]

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

Attrs[edit | edit source]

project = new Project(name: "Hello")

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

project.save()
project.destroy()

Collection[edit | edit source]

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

Events[edit | edit source]

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

References[edit | edit source]

{: .-one-column}

Credit:rstacruz