Skip to content

Instantly share code, notes, and snippets.

View alissoncs's full-sized avatar
🎯
Focusing

Alisson Carvalho alissoncs

🎯
Focusing
  • Porto Alegre, Brazil
View GitHub Profile
@alissoncs
alissoncs / event.js
Last active May 9, 2020 19:56
Event.js
var Event = function() {
var callbacks = {};
function emit(name, params) {
if (callbacks[name]) {
callbacks[name].map(function(item) {
item(params);
});
}
}
window.onload = function () {
Application.listAllAwards(function (awards) {
console.log(awards);
document.getElementById('awards-list').innerHTML = '';
for (var i in awards) {
var award = awards[i];
var div = document.createElement('div');
div.id = 'award-' + award.id;
var text = 'Name: ' + award.name + ', Price: $' + award.price;
div.appendChild(document.createTextNode(text));
@alissoncs
alissoncs / Application.js
Created May 9, 2020 18:58
Application.js
var Application = {
listAllAwards: function (success, err) {
return http.Connection('/Awards', {}, function () {
return success(mockAwardsList);
}, err);
},
BuyTicket: function (awardId, success, err) {
return http.Connection('/BuyTicket', {
awardId: awardId,
}, success, err);
var http = {
Connection: function (url, data, success, err) {
setTimeout(function () {
success();
}, 3000); // fake request time
}
}
@alissoncs
alissoncs / awardshtml.html
Created May 9, 2020 18:55
awardshtml.html
<h1>
Awards List
</h1>
<div id='awards-list'>
Loading...
</div>
<h2>
My cart
</h2>
@alissoncs
alissoncs / mockAwardsList.js
Created May 9, 2020 18:53
mockAwardsList.js
var mockAwardsList = [
{
id: 1,
name: 'The Game Awards 2019',
price: 199,
},
{
id: 2,
name: 'New York Game Awards ',
price: 99,
@alissoncs
alissoncs / updateTotal.js
Last active May 9, 2020 18:43
updateTotal.js
var total = 0;
function updateTotal() {
document.getElementById('total').innerHTML = total;
}
@alissoncs
alissoncs / addAwardToCart.js
Created May 9, 2020 18:42
addAwardToCart.js
function addAwardToCart(award) {
var div = document.createElement('div');
div.id = 'cart-item-' + award.id;
if (document.getElementById(div.id)) {
return;
}
div.appendChild(document.createTextNode('Added: ' + award.name + ', Price: $' + award.price));
var button = document.createElement('button');
@alissoncs
alissoncs / Application.js
Last active May 9, 2020 18:28
Legacy Javascript DOM Oriented
var Application = {
listAllAwards: function (success, err) {
console.info('ListAll Awards');
return http.Connection('/Awards', {}, function () {
return success(mockAwardsList);
}, err);
},
BuyTicket: function (awardId, success, err) {
return http.Connection('/BuyTicket', {
awardId: awardId,