@@ -16,86 +16,26 @@ $ npm install
16
16
17
17
## Steps.
18
18
19
- ### 1. Open ` src/js/apiWeather .js `
19
+ ### 1. Open ` src/js/apiIceAndFire .js `
20
20
21
21
``` diff
22
- var apiWeather = apiWeather || {};
23
-
24
- (function (apiWeather) {
25
- apiWeather.Service = class Service {
26
- constructor(apiKey = '855fb3867fa7108f3d6a43d7405878e6') {
27
- this.apiKey = apiKey;
28
- this.city = null;
29
- }
30
-
31
- setCity(city) {
32
- this.city = city; // obj:{ name: string, id: int}
33
- }
34
-
35
- getCurrentWeather(err, callback) {
36
- const url = `http://api.openweathermap.org/data/2.5/weather?q=${this.city.name}&appid=${this.apiKey}`;
37
- const req = new XMLHttpRequest();
38
- - req.open('get', url, true);
39
- + req.open('get', url, false);
40
- req.send();
41
- req.onload = callback;
42
- req.onerror = err;
43
- }
44
-
45
- getForecastWeather(err, callback) {
46
- const url = `http://api.openweathermap.org/data/2.5/forecast?q=${this.city.name}&appid=${this.apiKey}`;
47
- const req = new XMLHttpRequest();
48
- req.onload = callback;
49
- req.onerror = err;
50
- - req.open('get', url, true);
51
- + req.open('get', url, false);
52
- req.send();
53
- }
54
- }
55
-
56
- })(apiWeather);
22
+ const sendGetRequest = (req, url) => {
23
+ - req.open('get', url, true);
24
+ + req.open('get', url, false);
25
+ req.send();
26
+ };
57
27
58
28
```
59
29
* This way ` XHR ` work SYNC.
60
30
61
31
### 2. Now if we change these values again we can watch that goes on parallel
62
32
63
- ``` diff apiWeather.js
64
- var apiWeather = apiWeather || {};
65
-
66
- (function (apiWeather) {
67
- apiWeather.Service = class Service {
68
- constructor(apiKey = '855fb3867fa7108f3d6a43d7405878e6') {
69
- this.apiKey = apiKey;
70
- this.city = null;
71
- }
72
-
73
- setCity(city) {
74
- this.city = city; // obj:{ name: string, id: int}
75
- }
76
-
77
- getCurrentWeather(err, callback) {
78
- const url = `http://api.openweathermap.org/data/2.5/weather?q=${this.city.name}&appid=${this.apiKey}`;
79
- const req = new XMLHttpRequest();
80
- + req.open('get', url, true);
81
- - req.open('get', url, false);
82
- req.send();
83
- req.onload = callback;
84
- req.onerror = err;
85
- }
86
-
87
- getForecastWeather(err, callback) {
88
- const url = `http://api.openweathermap.org/data/2.5/forecast?q=${this.city.name}&appid=${this.apiKey}`;
89
- const req = new XMLHttpRequest();
90
- req.onload = callback;
91
- req.onerror = err;
92
- + req.open('get', url, true);
93
- - req.open('get', url, false);
94
- req.send();
95
- }
96
- }
97
-
98
- })(apiWeather);
33
+ ``` diff apiIceAndFire.js
34
+ const sendGetRequest = (req, url) => {
35
+ + req.open('get', url, true);
36
+ - req.open('get', url, false);
37
+ req.send();
38
+ };
99
39
100
40
```
101
41
* Open and show results on developer tools.
0 commit comments