# cyclejs-fundamentals

Plunker example for cycleJS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div id="app"></div>
  
  <script src="https://unpkg.com/xstream@10.9.0/dist/xstream.js"></script>
  <script>window.xs=xstream.default</script>
  <script src="script.js"></script>
</body>
</html>
</html>
function main() {
    return {
        DOM: xs.periodic(1000)                       
           .fold(prev => prev + 1, 0)        
           .map(i => `Seconds elapsed: ${i}`),
        log: xs.periodic(2000)                       
           .fold(prev => prev + 1, 0)
    } 
}

function domDriver(text$) {
   text$.subscribe({
    next: str => {
        const elem = document.querySelector('#app');
        elem.textContent = str;
     }
    })  
}

function logDriver(msg$) {
    msg$.subscribe({ next: msg => { console.log(msg); }})
}

function run(mainFn, drivers) {
    const sinks = mainFn();
    Object.keys(drivers).forEach(key => {
        if (sinks[key]) {
            drivers[key](sinks[key]);
        }
    });
}

run(main, {
    DOM: domDriver,
    log: logDriver,
    
});