Last active
August 29, 2015 14:21
-
-
Save kumavis/5f928bdacfb87e02b2cf to your computer and use it in GitHub Desktop.
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
app = App() | |
hg.app(document.body, app, render) | |
peerLookup = {} | |
function onNewPeer(peerData){ | |
var newPeer = hg.struct({ | |
name: peerData.name, | |
upTime: peerData.upTime, | |
}) | |
peerLookup[peerData.name] = newPeer | |
app.peers.push(newPeer) | |
} | |
function onRemovePeer(peerData){ | |
var peer = peerLookup[peerData.name] | |
// ... | |
// read the docs https://github.com/Raynos/observ-array | |
} | |
function App() { | |
return hg.state({ | |
peers: hg.array([]), | |
}) | |
} | |
function render(state) { | |
return renderTable( | |
['col1', 'col2'], | |
state.peers.map(function(peerState){ | |
return [peerState.name, peerState.upTime] | |
}) | |
) | |
} | |
function renderTable(labels, data) { | |
return h('table',[ | |
h('thead', labels.map(function(label){ | |
return h('th', label) | |
})), | |
h('tbody', data.map(function(row){ | |
return h('tr', row.map(function(cell){ | |
var value = cell && cell.toString && cell.toString() | |
return h('td', value) | |
})) | |
})), | |
]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment