Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandra Patni committed Aug 28, 2011
1 parent 7308e24 commit ded0532
Showing 1 changed file with 73 additions and 64 deletions.
137 changes: 73 additions & 64 deletions README.md
@@ -1,99 +1,108 @@
= AASM.js - CoffeeScript state machines
AASM.js - CoffeeScript state machine
========

This package contains AASM, a library for adding finite state machines to CoffeeScript classes.

AASM has the following features:

* States
* Machines
* Events
* Transitions
* States
* Machines
* Events
* Transitions

== Download
Download
--------

The latest AASM can currently be pulled from the git repository on github.

* http://github.com/rubyorchard/aasm.js/tree/master
http://github.com/rubyorchard/aasm-js/tree/master


== Installation
Installation
--------

=== From npm repository
From npm repository
--------

% npm install aasm-js
npm install aasm-js

== Simple Example
Simple Example
--------

Here's a quick example highlighting some of the features.

AASM = require 'aasm'
AASM = require 'aasm'

module.exports = class Conversation
AASM.include(this)
module.exports = class Conversation
AASM.include(this)

@aasmInitialState 'needsAttention'
@aasmInitialState 'needsAttention'

@aasmState 'needsAttention'
@aasmState 'read'
@aasmState 'closed'
@aasmState 'awaitingResponse'
@aasmState 'junk'
@aasmState 'needsAttention'
@aasmState 'read'
@aasmState 'closed'
@aasmState 'awaitingResponse'
@aasmState 'junk'

@aasmEvent 'newMessage', ()->
@aasmEvent 'newMessage', ()->

@aasmEvent 'view', ()->
@transitions {to: 'read', from: ['needsAttention']}
@aasmEvent 'view', ()->
@transitions {to: 'read', from: ['needsAttention']}

@aasmEvent 'reply', ()->
@aasmEvent 'reply', ()->

@aasmEvent 'close', ()->
@transitions {to: 'closed', from: ['read', 'awaitingResponse']}
@aasmEvent 'close', ()->
@transitions {to: 'closed', from: ['read', 'awaitingResponse']}

@aasmEvent 'junk', ()->
@transitions {to: 'junk', from: ['read']}
@aasmEvent 'junk', ()->
@transitions {to: 'junk', from: ['read']}

@aasmEvent 'unjunk', ()->
@aasmEvent 'unjunk', ()->


== A Slightly More Complex Example
A Slightly More Complex Example
--------

This example uses a few of the more complex features available.

class Relationship
AASM.include(this)

@aasmInitialState (relationship) ->
if relationship.isStrictlyForFun() then 'intimate' else 'dating'

@aasmState 'dating', {enter: 'makeHappy', exit: 'makeDepressed'}
@aasmState 'intimate', {enter: 'makeVeryHappy', exit: 'neverSpeakAgain'}
@aasmState 'married', {enter: 'makeHappy', exit: 'buyExoticCarAndWearACombover'}

@aasmEvent 'getIntimate', ->
@transitions to: 'intimate', from: ['dating'], guard: 'isDrunk'
@aasmEvent 'getMarried', ->
@transitions to: 'married', from: ['dating', 'married'], guard: 'isWillingToGiveUpManhood'

isStrictlyForFun: ->
isDrunk: ->
isWillingToGiveUpManhood: ->
makeHappy: ->
makeDepressed: ->
makeVeryHappy: ->
neverSpeakAgain: ->
giveUpIntimacy: ->
buyExoticCarAndWearACombover: ->

= Other Stuff
Based On:: Scott Barron aasm for ruby
Author:: Chandra Patni
License:: Original code Copyright 2011 by Chandra Patni.
class Relationship
AASM.include(this)

@aasmInitialState (relationship) ->
if relationship.isStrictlyForFun() then 'intimate' else 'dating'

@aasmState 'dating', {enter: 'makeHappy', exit: 'makeDepressed'}
@aasmState 'intimate', {enter: 'makeVeryHappy', exit: 'neverSpeakAgain'}
@aasmState 'married', {enter: 'makeHappy', exit: 'buyExoticCarAndWearACombover'}

@aasmEvent 'getIntimate', ->
@transitions to: 'intimate', from: ['dating'], guard: 'isDrunk'
@aasmEvent 'getMarried', ->
@transitions to: 'married', from: ['dating', 'married'], guard: 'isWillingToGiveUpManhood'

isStrictlyForFun: ->
isDrunk: ->
isWillingToGiveUpManhood: ->
makeHappy: ->
makeDepressed: ->
makeVeryHappy: ->
neverSpeakAgain: ->
giveUpIntimacy: ->
buyExoticCarAndWearACombover: ->

Other Stuff
--------

Based On:: Scott Barron aasm for ruby
Author:: Chandra Patni
License:: Original code Copyright 2011 by Chandra Patni.
Released under an MIT-style license. See the LICENSE file
included in the distribution.

== Warranty
Warranty
--------

This software is provided "as is" and without any express or
implied warranties, including, without limitation, the implied
warranties of merchantibility and fitness for a particular
purpose.
This software is provided "as is" and without any express or
implied warranties, including, without limitation, the implied
warranties of merchantibility and fitness for a particular
purpose.

0 comments on commit ded0532

Please sign in to comment.