Skip to content

Instantly share code, notes, and snippets.

View rbren's full-sized avatar
🐢
I may be slow to respond.

Robert Brennan rbren

🐢
I may be slow to respond.
  • Fairwinds
  • Boston, Massachusetts
View GitHub Profile
let reddit = require('@datafire/reddit_rss').actions;
reddit.frontPage().then(frontPage => {
console.log(frontPage.feed.entries);
})
paths:
/gifs:
get:
action: reddit_rss/subreddit
input:
subreddit: gifs
// In traditional JavaScript
var messages = document.getElementsByClassname('message');
messages.forEach(function(message) {
message.className = message.className + " visible";
});
// With jQuery
$('.message').addClass('visible');
let filenames = ['index.html', 'blog.html', 'terms.html'];
Promise.all(filenames.map(readFilePromise))
.then(files => {
console.log('index:', files[0]);
console.log('blog:', files[1]);
console.log('terms:', files[2]);
})
function readFilePromise(filename) {
if (!filename) {
return Promise.reject(new Error("Filename not specified"));
}
if (filename === 'index.html') {
return Promise.resolve('<h1>Hello!</h1>');
}
return new Promise((resolve, reject) => {/*...*/})
}
Promise.resolve()
.then(_ => api.deleteItem(1))
.then(_ => api.deleteItem(2))
.then(_ => api.deleteItem(3))
.then(_ => api.deleteItem(4))
.then(_ => api.deleteItem(5));
Promise.resolve()
.then(_ => api.getItem(1))
.then(item => {
item.amount++;
return api.updateItem(1, item);
})
.catch(e => {
console.log('failed to get or update item');
})
api.getItem(1)
.then(item => {
item.amount++;
api.updateItem(1, item)
.then(update => {
api.deleteItem(1)
.then(deletion => {
console.log('done!');
})
})
api.getItem(1)
.then(item => {
item.amount++;
return api.updateItem(1, item);
})
.then(update => {
return api.deleteItem(1);
})
.then(deletion => {
console.log('done!');
api.getItem(1)
.then(item => {
item.amount++;
api.updateItem(1, item);
})
.then(update => {
return api.deleteItem(1);
})
.then(deletion => {
console.log('done!');