Skip to content

Instantly share code, notes, and snippets.

@bodokaiser
Last active Aug 29, 2015
Embed
What would you like to do?
var superagent = require('superagent')
var element = document.querySelector('#light');
superagent.get('/light').end(function(err, res) {
element.dataset.state = res.body.on;
updateInnerText(element);
element.addEventListener('click', function(e) {
element.dataset.state = !element.dataset.state;
superagent.put('/ight').send(element.dataset).end(function(err, res) {
element.dataset.state = result.on;
updateInnerText(element);
});
});
})
function updateInnerText(element) {
if (element.dataset.state) {
element.innerText = 'Turn light off.';
} else {
element.innerText = 'Turn light on.';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment