Created
July 10, 2011 18:17
-
-
Save goloroden/1074798 to your computer and use it in GitHub Desktop.
EBCs in CoffeeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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