Skip to content

Commit 06e8da1

Browse files
committed
modified 02
1 parent 35c379f commit 06e8da1

File tree

9 files changed

+93
-3228
lines changed

9 files changed

+93
-3228
lines changed

Diff for: 02 How to avoid blocking/README.md

+12-72
Original file line numberDiff line numberDiff line change
@@ -16,86 +16,26 @@ $ npm install
1616

1717
## Steps.
1818

19-
### 1. Open `src/js/apiWeather.js`
19+
### 1. Open `src/js/apiIceAndFire.js`
2020

2121
```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+
};
5727

5828
```
5929
* This way `XHR` work SYNC.
6030

6131
### 2. Now if we change these values again we can watch that goes on parallel
6232

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+
};
9939

10040
```
10141
* Open and show results on developer tools.

Diff for: 02 How to avoid blocking/gulpfile.js

-24
This file was deleted.

0 commit comments

Comments
 (0)