Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann

maxhoffmann/clicks.js

Last active Dec 7, 2016
Embed
What would you like to do?
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