Skip to content

Instantly share code, notes, and snippets.

@PanJ
PanJ / async-2.js
Created December 24, 2016 18:43
Async/await 2
if (confirm('Are you sure?')) {
console.log('Confirmed');
} else {
console.log('Canceled');
}
@PanJ
PanJ / async-1.js
Created December 24, 2016 18:43
Async/await 1
setTimeout(function () {
console.log('แสดงอันที่สอง (หลังจากอันแรก 1 วินาที)');
}, 1000);
console.log('แสดงอันแรก');
@PanJ
PanJ / ctx-1.js
Last active December 12, 2016 15:04
Context-ful Architecture 1
// import stuffs
app.delete('/todos/:id', (req, res) => { // deletes a todo and return current todo list
const ctx = new TodoContext(req);
Promise.resolve()
.then(() => authorize(['user', 'admin']))
.then(({ user, roles }) => {
let promise;
if (roles.indexOf('admin') >= 0 && req.query.permanent)
promise = Todo.remove({ _id: req.params.id});