Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann
Last active December 7, 2016 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxhoffmann/f8bc15332940f9941c22c40f16bf28e2 to your computer and use it in GitHub Desktop.
Save maxhoffmann/f8bc15332940f9941c22c40f16bf28e2 to your computer and use it in GitHub Desktop.
buzz API
import buzz from '@maxhoffmann/buzz';
function clicks(broadcast) {
window.addEventListener('click', broadcast('click'));
}
const logger = () => console.log;
const services = [logger, clicks];
buzz(services);
import buzz from '@maxhoffmann/buzz';
const logger = () => console.log;
function clicks(broadcast) {
window.addEventListener('click', broadcast('click'));
}
function counter(broadcast) {
let state = 0;
return message => {
if (message.type === 'click') {
state += 1;
broadcast('counter')(state);
}
}
}
const services = [logger, clicks, counter];
buzz(services);
import buzz from '@maxhoffmann/buzz';
function clicks(broadcast) {
window.addEventListener('click', broadcast('click'));
}
function counter(broadcast) {
let state = 0;
return message => {
if (message.type === 'click') {
state += 1;
broadcast('counter')(state);
}
}
}
function view() {
return message => {
if (message.type === 'counter') {
document.body.innerHTML = message.data;
}
}
}
const services = [clicks, counter, view];
buzz(services);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment