Skip to content

Instantly share code, notes, and snippets.

@goloroden

goloroden/app.coffee

Created Jul 10, 2011
Embed
What would you like to do?
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
You can’t perform that action at this time.