Last active
January 24, 2019 06:35
-
-
Save tarasowski/39770c3651140414cf9b467e15594b19 to your computer and use it in GitHub Desktop.
Pure function composition, no assignments.
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
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x) | |
const useState = init => | |
([init, (init => | |
x => | |
useState(init + x))(init)]) | |
const createState = useState => | |
useState(3) | |
const render = ([count, setCount]) => | |
(`<div><p>${count}</p></div> | |
<button onclick=${setCount}>My button</button> | |
<div><p>${count}</p></div>`) | |
const component = useState => | |
compose( | |
render, | |
createState | |
)(useState) | |
console.log( | |
component(useState), | |
) | |
// "<div><p>3</p></div>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment