Skip to content

Instantly share code, notes, and snippets.

@sminutoli
Created September 13, 2016 14:58
Show Gist options
  • Save sminutoli/ca9119e42e8cefdb5f18201beee0df25 to your computer and use it in GitHub Desktop.
Save sminutoli/ca9119e42e8cefdb5f18201beee0df25 to your computer and use it in GitHub Desktop.
require('./API');
require('./CategoryList');
const App = {
selector: '#app',
fetchAPI: API,
run(){
this.fetchAPI
.categories()
.then(this.addCategoriesToList.bind(this)) // cómo se puede preservar el this dentro de las promises? bluebird soporta un bind() pero parece que ES2015 no :(
.then(this.listToHTML.bind(this))
.then(this.renderHTML.bind(this));
},
addCategoriesToList(categories){
return CategoryList.from({ categories });
},
listToHTML(categoryList){
return categoryList.toHTML();
},
renderHTML(html){
$(this.selector).html(html);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment