Last active
December 7, 2016 17:08
-
-
Save maxhoffmann/f8bc15332940f9941c22c40f16bf28e2 to your computer and use it in GitHub Desktop.
buzz API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import buzz from '@maxhoffmann/buzz'; | |
function clicks(broadcast) { | |
window.addEventListener('click', broadcast('click')); | |
} | |
const logger = () => console.log; | |
const services = [logger, clicks]; | |
buzz(services); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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