Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Component
class Component {
constructor(o) {
this.components = {};
this.listeners = {};
}
init(o) {
}
install(name, c) {
c.t = this;
this.components[name] = c;
let topics = c.interestedTopics();
for (let t of topics) {
this.addListener(c, t);
}
}
addListener(c, t) {
if (!this.listeners[t]) {
this.listeners[t] = [];
}
this.listeners[t].push(c);
}
grab(name) {
return this.components[name];
}
loop() {
}
loopComponents() {
var keys = Object.keys(this.components);
for (let key of keys) {
var c = this.components[key];
this.components[key].loop();
}
}
msg(title, body) {
let listenerGroup = this.listeners[title];
if (listenerGroup) {
for (let listener of listenerGroup) {
listener.handleMessage(title, body);
}
}
let componentKeys = Object.keys(this.components);
for (let key of componentKeys) {
var c = this.components[key];
this.components[key].msg(title, body);
}
}
handleMessage(title, body) {
}
interestedTopics() {
return [];
}
}
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.