
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
skinny-coffee-machine
Advanced tools
A simple JavaScript state machine with observers, for browsers and Node.js.

Skinny Coffee Machine is a simple JavaScript state machine written in CoffeeScript. It is being developed for the 2.0 rewrite of jQuery Endless Scroll.
If you use npm, you can grab the source code by:
npm install skinny-coffee-machine
@coffeeMachine.power = new SkinnyCoffeeMachine
default: 'off'
events:
turnOn:
off: 'on'
turnOff:
on: 'off'
on:
turnOn: (from, to) -> "#{from.toUpperCase()} to #{to.toUpperCase()}"
turnOff: (from, to) -> "#{from.toUpperCase()} to #{to.toUpperCase()}"
before:
turnOff: (from, to) -> "Before switching to #{to.toUpperCase()}"
after:
turnOn: (from, to) -> "After switching to #{to.toUpperCase()}"
turnOff: (from, to) -> "After switching to #{to.toUpperCase()}"
@coffeeMachine.mode = new SkinnyCoffeeMachine
default: 'latte'
events:
next:
latte: 'cappuccino'
cappuccino: 'espresso'
espresso: 'lungo'
lungo: 'latte'
last:
latte: 'lungo'
lungo: 'espresso'
espresso: 'cappuccino'
cappuccino: 'latte'
You may use either switch or change for switching states:
@coffeeMachine.power.currentState() #=> "off"
@coffeeMachine.power.switch('turnOn')
@coffeeMachine.power.currentState() #=> "on"
To change states multiple times:
@coffeeMachine.mode.currentState() #=> "latte"
@coffeeMachine.mode.change('next', 3)
@coffeeMachine.mode.currentState() #=> "cappuccino"
In order to provide more flexibility on state transition callbacks, you may use observers to dynamically add and remove events.
To start observing:
@coffeeMachine.power.observeBefore('turnOn').start 'labelA', (from, to) => "Observer A before switching to #{to.toUpperCase()}"
@coffeeMachine.power.observeOn( 'turnOn').start 'labelB', (from, to) => "Observer B on switching to #{to.toUpperCase()}"
@coffeeMachine.power.observeAfter( 'turnOn').start 'labelC', (from, to) => "Observer C after switching to #{to.toUpperCase()}"
To stop observing:
@coffeeMachine.power.observeBefore('turnOn').stop('labelA')
Skinny Coffee Machine uses Grunt, PhantomJS and Mocha.
After you have Grunt and PhantomJS set up, you may run tests by:
grunt
To automatically compile CoffeeScript as well as run tests during development, you may use:
grunt watch
Copyright (c) 2012 Fred Wu
Licensed under the MIT license.
FAQs
A simple JavaScript state machine with observers, for browsers and Node.js.
We found that skinny-coffee-machine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.