Last active
January 30, 2017 06:07
-
-
Save gt3/7ba8810f0f7662d504320b932677653b to your computer and use it in GitHub Desktop.
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
let next = it => v => it.next(v).value | |
function* mult(t) { | |
let acc = 0 | |
while (true) yield acc = acc + t | |
} | |
function* cell(value) { | |
value = yield (<th key={value}>{value}</th>) | |
while (true) value = yield (<td key={value}>{value}</td>) | |
} | |
function* cells(operation, t) { | |
let nextOp = next(operation(t)), c = cell(nextOp()), nextCell = next(c) | |
let acc = [nextCell()] | |
while (true) { | |
yield acc | |
acc = acc.concat(nextCell(nextOp())) | |
} | |
} | |
let Row = ({refHandler, children}) => <tr ref={refHandler}>{children}</tr> | |
let addClickHandler = handler => node => node ? node.onclick = handler : null | |
let makeRefHandler = props => addClickHandler(renderer(props)) | |
let PrintTable = props => ( | |
<table> | |
<tbody> | |
<Row refHandler={makeRefHandler(props)}>{props.update()}</Row> | |
</tbody> | |
</table> | |
) | |
let renderer = props => ReactDOM.render.bind(null, <PrintTable {...props}/>, props.rootNode, null) | |
let render = rootNode => renderer({rootNode, update: next(cells(mult, 5))})() //render multiples of 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment