Last active
December 7, 2016 17:08
-
-
Save maxhoffmann/f8bc15332940f9941c22c40f16bf28e2 to your computer and use it in GitHub Desktop.
Revisions
-
Maximilian Hoffmann revised this gist
Dec 7, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import buzz from '@maxhoffmann/buzz'; function clicks(broadcast) { window.addEventListener('click', broadcast('click')); @@ -22,6 +22,6 @@ function view() { } } const services = [clicks, counter, view]; buzz(services); -
Maximilian Hoffmann revised this gist
Dec 7, 2016 . 1 changed file with 27 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ 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); } } } function view() { return message => { if (message.type === 'counter') { document.body.innerHTML = message.data; } } } const services = [logger, clicks, counter, view]; buzz(services); -
Maximilian Hoffmann revised this gist
Dec 7, 2016 . 1 changed file with 0 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +0,0 @@ -
Maximilian Hoffmann renamed this gist
Dec 7, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Maximilian Hoffmann renamed this gist
Dec 7, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Maximilian Hoffmann revised this gist
Dec 7, 2016 . 1 changed file with 29 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ export function buzz(services) { const _bus = []; const _services = []; const broadcast = type => data => { _bus.push({ type, data }); } setupServices(broadcast); requestAnimationFrame(run); function setupServices(broadcast) { for (const service of services) { _services.push(service(broadcast)) } } function run(time) { requestAnimationFrame(run); for (const message of _bus.splice(0, 100)) { for (const service of _services) { if (typeof service === 'function') { service(message); } } } } } -
Maximilian Hoffmann revised this gist
Dec 7, 2016 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import buzz from '@maxhoffmann/buzz'; function clicks(broadcast) { window.addEventListener('click', broadcast('click')); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ import buzz from '@maxhoffmann/buzz'; const logger = () => console.log; -
Maximilian Hoffmann created this gist
Dec 7, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ import buzz from 'buzz'; function clicks(broadcast) { window.addEventListener('click', broadcast('click')); } const logger = () => console.log; const services = [logger, clicks]; buzz(services); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import buzz from '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);