Skip to content

Instantly share code, notes, and snippets.

@prologic
Forked from hsubra89/index.js
Last active August 29, 2015 14:04
Show Gist options
  • Save prologic/11db57d48bf71a98644d to your computer and use it in GitHub Desktop.
Save prologic/11db57d48bf71a98644d to your computer and use it in GitHub Desktop.
A simplistic port of circuits for Python to JavaScript / NodeJS
/**
* 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
};
#!/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);
@prologic
Copy link
Author

prologic commented Aug 4, 2014

Sample Output:

$ node -i test.js
foo
{ '0': 1, '1': 2, '2': 3 }
foo
{ '0': 1, '1': 2, '2': 3 }
bar
{ '0': 1, '1': 2, '2': 3 }
bar
{ '0': 1, '1': 2, '2': 3 }

@hsubra89
Copy link

hsubra89 commented Aug 4, 2014

yeah, same structure :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment