Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save betterkenly/3f6ba4bc7b0ce25bae0fe46a2bd0479c to your computer and use it in GitHub Desktop.
Save betterkenly/3f6ba4bc7b0ce25bae0fe46a2bd0479c to your computer and use it in GitHub Desktop.
message bus
let messageBus = {
subscribers: [],
publish: (message) => {
this.subscribers.forEach((subscriber) => {
subscriber.fn(message);
});
},
subscribe: (type, subscriber, fn) => {
this.subscribers.push({
'type': type,
'subscriber': subscriber,
'fn': fn
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment