Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 108 #2

Open
wants to merge 99 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
ab419cb
lesson-5
iamshaunjp Feb 11, 2019
e7df143
lesson-6
iamshaunjp Feb 12, 2019
b904f58
lesson-7
iamshaunjp Feb 12, 2019
01c317c
lesson-9
iamshaunjp Feb 12, 2019
f5375f9
lesson-10
iamshaunjp Feb 12, 2019
cd84c40
lesson-11
iamshaunjp Feb 12, 2019
b8bef93
lesson-12
iamshaunjp Feb 12, 2019
b4ff9bc
lesson-13
iamshaunjp Feb 12, 2019
9ec6f63
lesson-14
iamshaunjp Feb 12, 2019
fd44d92
lesson-15
iamshaunjp Feb 12, 2019
bdbad72
lesson-16
iamshaunjp Feb 12, 2019
35183c1
lesson-17
iamshaunjp Feb 12, 2019
de50d2b
lesson-19
iamshaunjp Feb 12, 2019
cf0b823
lesson-20
iamshaunjp Feb 12, 2019
eb3e1da
lesson-21
iamshaunjp Feb 12, 2019
be5bc48
lesson-22
iamshaunjp Feb 12, 2019
59bd310
lesson-23
iamshaunjp Feb 12, 2019
95655fc
lesson-24
iamshaunjp Feb 12, 2019
a1d4bc6
lesson-25
iamshaunjp Feb 12, 2019
cf01a95
lesson-26
iamshaunjp Feb 12, 2019
dfbd828
lesson-27
iamshaunjp Feb 12, 2019
0a790de
lesson-28
iamshaunjp Feb 12, 2019
bda9d91
lesson-30
iamshaunjp Feb 12, 2019
f1f5777
lesson-31
iamshaunjp Feb 12, 2019
cdff15f
lesson-32
iamshaunjp Feb 13, 2019
563c623
lesson-33
iamshaunjp Feb 13, 2019
d573f79
lesson-34
iamshaunjp Feb 13, 2019
ecfa54b
lesson-35
iamshaunjp Feb 15, 2019
30c5d52
lesson-35
iamshaunjp Feb 15, 2019
aac6888
lesson-38
iamshaunjp Feb 15, 2019
dde0235
lesson-39
iamshaunjp Feb 15, 2019
00e56d4
lesson-40
iamshaunjp Feb 15, 2019
85743ad
lesson-41
iamshaunjp Feb 15, 2019
4f6f59e
lesson-42
iamshaunjp Feb 15, 2019
57750b1
lesson-43
iamshaunjp Feb 15, 2019
3cce4ec
lesson-46
iamshaunjp Feb 15, 2019
fdb0140
lesson-47
iamshaunjp Feb 15, 2019
d82d159
lesson-48
iamshaunjp Feb 15, 2019
458d0f3
lesson-49
iamshaunjp Feb 15, 2019
910990a
lesson-50
iamshaunjp Feb 15, 2019
0ed709b
lesson-51
iamshaunjp Feb 15, 2019
aeb459f
lesson-52
iamshaunjp Feb 15, 2019
3e9e9b7
lesson-53
iamshaunjp Feb 15, 2019
3cb4c50
lesson-54
iamshaunjp Feb 15, 2019
1b37219
lesson-55
iamshaunjp Feb 15, 2019
9684721
lesson-56
iamshaunjp Feb 15, 2019
45f133a
lesson-57
iamshaunjp Feb 15, 2019
26dcf8f
lesson-59
iamshaunjp Feb 16, 2019
c83cd9a
lesson-61
iamshaunjp Feb 16, 2019
522f7e2
lesson-62
iamshaunjp Feb 16, 2019
54edca1
lesson-63
iamshaunjp Feb 16, 2019
3ad2840
lesson-65
iamshaunjp Feb 16, 2019
6f6144c
lesson-65
iamshaunjp Feb 16, 2019
eec1d7a
lesson-65
iamshaunjp Feb 17, 2019
880b11a
lesson-66
iamshaunjp Feb 17, 2019
9fdd0b1
lesson-67
iamshaunjp Feb 17, 2019
0a92c5d
lesson-68
iamshaunjp Feb 17, 2019
be3b3ea
lesson-69
iamshaunjp Feb 17, 2019
3eaaa6b
lesson-70
iamshaunjp Feb 17, 2019
4895d1d
lesson-71
iamshaunjp Feb 18, 2019
e65c2b7
lesson-72
iamshaunjp Feb 18, 2019
42125d0
lesson-73
iamshaunjp Feb 18, 2019
7f4074e
lesson-74
iamshaunjp Feb 18, 2019
2ecefac
lesson-75
iamshaunjp Feb 18, 2019
124126e
lesson-76
iamshaunjp Feb 18, 2019
2056eb0
lesson-77
iamshaunjp Feb 18, 2019
acec2df
lesson-78
iamshaunjp Feb 18, 2019
1953c7d
lesson-79
iamshaunjp Feb 19, 2019
1d54d02
lesson-79
iamshaunjp Feb 19, 2019
7309f96
lesson-80
iamshaunjp Feb 19, 2019
9f9190e
lesson-81
iamshaunjp Feb 19, 2019
e0dc927
lesson-81
iamshaunjp Feb 19, 2019
d8cc465
lesson-82
iamshaunjp Feb 19, 2019
a91f39e
lesson-83
iamshaunjp Feb 19, 2019
feeef15
lesson-84
iamshaunjp Feb 19, 2019
e0f884d
lesson-85
iamshaunjp Feb 19, 2019
c943f33
lesson-87
iamshaunjp Feb 21, 2019
0a5f767
lesson-89
iamshaunjp Feb 21, 2019
0c4e97f
lesson-89
iamshaunjp Feb 21, 2019
9b3bd2e
lesson-89
iamshaunjp Feb 21, 2019
8ce51be
lesson-90
iamshaunjp Feb 21, 2019
2559ac8
lesson-91
iamshaunjp Feb 21, 2019
e61deeb
lesson-92
iamshaunjp Feb 21, 2019
d24b0eb
lesson-93
iamshaunjp Feb 21, 2019
b461abd
lesson-94
iamshaunjp Feb 21, 2019
275f927
lesson-95
iamshaunjp Feb 21, 2019
868d9ca
lesson-96
iamshaunjp Feb 21, 2019
06cdc27
lesson-97
iamshaunjp Feb 21, 2019
27777e1
lesson-98
iamshaunjp Feb 21, 2019
5a59bf2
lesson-99
iamshaunjp Feb 25, 2019
db4ce97
lesson-100
iamshaunjp Feb 25, 2019
934d1ce
lesson-101
iamshaunjp Feb 25, 2019
4cda4d5
lesson-102
iamshaunjp Feb 25, 2019
dbc38fe
lesson-103
iamshaunjp Feb 25, 2019
e59f7e5
lesson-104
iamshaunjp Feb 25, 2019
5f82a5f
lesson-105
iamshaunjp Feb 25, 2019
275114d
lesson-106
iamshaunjp Feb 25, 2019
0c3a1d4
lesson-107
iamshaunjp Feb 25, 2019
4fa8460
lesson-108
iamshaunjp Feb 25, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
lesson-94
  • Loading branch information
iamshaunjp committed Feb 21, 2019
commit b461abdd04d22b6134282f45ea905fe4298086c4
64 changes: 43 additions & 21 deletions chapter_12/sandbox.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,51 @@
const getTodos = (resource, callback) => {
const getTodos = (resource) => {

const request = new XMLHttpRequest();
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();

request.addEventListener('readystatechange', () => {
request.addEventListener('readystatechange', () => {

if(request.readyState === 4 && request.status === 200){
const data = JSON.parse(request.responseText);
resolve(data);
} else if (request.readyState === 4){
reject('could not fetch the data');
}

});

request.open('GET', resource);
request.send();
});

};

if(request.readyState === 4 && request.status === 200){
const data = JSON.parse(request.responseText);
callback(undefined, data);
} else if (request.readyState === 4){
callback('could not fetch the data', undefined);
}
getTodos('json/luigi.json').then(data => {
console.log('promise resolved:', data);
}).catch(err => {
console.log('promise rejected:', err);
});

// promise example
const getSomething = () => {

return new Promise((resolve, reject) => {
// do something (fetch data)
// resolve('some data');
reject('some error');
});

request.open('GET', resource);
request.send();

};

getTodos('json/luigi.json', (err, data) => {
console.log(data);
getTodos('json/mario.json', (err, data) => {
console.log(data);
getTodos('json/shaun.json', (err, data) => {
console.log(data);
});
});
});
// getSomething().then(data => {
// console.log('promise resolved:', data);
// }, err => {
// console.log('promise rejected:', err);
// });

// getSomething().then(data => {
// console.log('promise resolved:', data);
// }).catch(err => {
// console.log('promise rejected:', err);
// });