Skip to content

Instantly share code, notes, and snippets.

@niksamokhvalov
Created September 24, 2019 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksamokhvalov/47f482d84acdcb0a93cc3b2e30faa97a to your computer and use it in GitHub Desktop.
Save niksamokhvalov/47f482d84acdcb0a93cc3b2e30faa97a to your computer and use it in GitHub Desktop.
JS Code Review
import axios from 'axios'
class RenderList {
constructor( params ) {
super(params);
window.addEventListener( 'resize' , this.render);
}
getData()
{
this.loading = true;
try {
axios.get("/data.json").then((values) => {
this.data = data;
this.render()
}).catch(function (error) {
console.log(error);
}).finally(function () {
this.loading = false
});
} catch (e) {
console.log(e);
}
}
normalizeData(item) {
return {
id: item.id,
name: item.title,
href: item.url
}
}
render() {
let list = '';
this.data.forEach((item) => {
item = this.normalizeData(item);
list += `<a href="https://www.someTest.org/${item.href}"><li>item.name</li></a>`
});
window.document.getElementById('Sidebar').appendChild(`
<div>
<ul>
${list}
</ul>
</div>
`)
}
}
let renderList = new RenderList();
renderList.getData();
renderList.render();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment