Skip to content

Instantly share code, notes, and snippets.

@goloroden
Created July 10, 2011 18:17
Show Gist options
  • Save goloroden/1074798 to your computer and use it in GitHub Desktop.
Save goloroden/1074798 to your computer and use it in GitHub Desktop.
EBCs in CoffeeScript
# Resolve dependencies.
EventEmitter = (require 'events').EventEmitter;
# Define EBCs.
class HelloWorldGenerator extends EventEmitter
generate: ->
this.emit 'generated', 'Hello World!'
class UpperCaseTransformer extends EventEmitter
transform: (text) ->
this.emit 'transformed', text.toUpperCase()
class ConsoleWriter extends EventEmitter
write: (text) ->
console.log text
# Create EBC instances.
helloWorldGenerator = new HelloWorldGenerator()
upperCaseTransformer = new UpperCaseTransformer()
consoleWriter = new ConsoleWriter()
# Wire up EBC instances.
helloWorldGenerator.on 'generated', (text) ->
upperCaseTransformer.transform text
upperCaseTransformer.on 'transformed', (text) ->
consoleWriter.write text
# Run application.
helloWorldGenerator.generate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment