-
-
Save prologic/11db57d48bf71a98644d to your computer and use it in GitHub Desktop.
A simplistic port of circuits for Python to JavaScript / NodeJS
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
/** | |
* circuits Component Framework for JavaScript | |
* | |
* @module circuits | |
*/ | |
var EventEmitter = require("events").EventEmitter, | |
EventManager; | |
manager = new EventEmitter(); | |
/** | |
* Component Base Class | |
* | |
* @class | |
*/ | |
function Component() { | |
} | |
// Component prototype inhertits from manager. | |
Component.prototype = Object.create(manager); | |
Component.prototype.constructor = Component; | |
module.exports = { | |
"manager": manager, | |
"Component": Component | |
}; |
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
#!/usr/bin/env node | |
var circuits = require("./circuits"); | |
var a = new circuits.Component(); | |
var b = new circuits.Component(); | |
a.on("foo", function () { | |
console.log("foo"); | |
console.log(arguments); | |
}); | |
b.on("bar", function () { | |
console.log("bar"); | |
console.log(arguments); | |
}); | |
a.emit("foo", 1, 2, 3); | |
b.emit("foo", 1, 2, 3); | |
a.emit("bar", 1, 2, 3); | |
b.emit("bar", 1, 2, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample Output: