Last active
June 10, 2018 10:10
-
-
Save jalalazimi/4b260b8c6a7f1013391dd376210894b9 to your computer and use it in GitHub Desktop.
Separate Logic from Effects in Cycle.js
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 characters
'use strict'; | |
window.xs = xstream['default']; | |
// Logic | |
xs.periodic(1000).fold(function (prev) { | |
return prev + 1; | |
}, 0).map(function (i) { | |
return 'Second elapse ' + i; | |
}) | |
// Efects | |
.subscribe({ | |
next: function next(str) { | |
console.log(str); | |
var elm = document.querySelector('#app'); | |
elm.textContent = str; | |
} | |
}); |
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 characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="app"></div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/xstream/11.4.0/xstream.min.js"></script> | |
<script id="jsbin-javascript"> | |
'use strict'; | |
window.xs = xstream['default']; | |
// Logic | |
xs.periodic(1000).fold(function (prev) { | |
return prev + 1; | |
}, 0).map(function (i) { | |
return 'Second elapse ' + i; | |
}) | |
// Efects | |
.subscribe({ | |
next: function next(str) { | |
console.log(str); | |
var elm = document.querySelector('#app'); | |
elm.textContent = str; | |
} | |
}); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">window.xs = xstream.default; | |
// Logic | |
xs.periodic(1000) | |
.fold( prev => prev +1 ,0) | |
.map( i => `Second elapse ${i}`) | |
// Efects | |
.subscribe({ | |
next: str => { | |
console.log(str) | |
const elm = document.querySelector('#app'); | |
elm.textContent = str; | |
} | |
})</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment