Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
84 changes: 12 additions & 72 deletions 02 How to avoid blocking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,86 +16,26 @@ $ npm install

## Steps.

### 1. Open `src/js/apiWeather.js`
### 1. Open `src/js/apiIceAndFire.js`

```diff
var apiWeather = apiWeather || {};

(function (apiWeather) {
apiWeather.Service = class Service {
constructor(apiKey = '855fb3867fa7108f3d6a43d7405878e6') {
this.apiKey = apiKey;
this.city = null;
}

setCity(city) {
this.city = city; // obj:{ name: string, id: int}
}

getCurrentWeather(err, callback) {
const url = `http://api.openweathermap.org/data/2.5/weather?q=${this.city.name}&appid=${this.apiKey}`;
const req = new XMLHttpRequest();
- req.open('get', url, true);
+ req.open('get', url, false);
req.send();
req.onload = callback;
req.onerror = err;
}

getForecastWeather(err, callback) {
const url = `http://api.openweathermap.org/data/2.5/forecast?q=${this.city.name}&appid=${this.apiKey}`;
const req = new XMLHttpRequest();
req.onload = callback;
req.onerror = err;
- req.open('get', url, true);
+ req.open('get', url, false);
req.send();
}
}

})(apiWeather);
const sendGetRequest = (req, url) => {
- req.open('get', url, true);
+ req.open('get', url, false);
req.send();
};

```
* This way `XHR` work SYNC.

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

```diff apiWeather.js
var apiWeather = apiWeather || {};

(function (apiWeather) {
apiWeather.Service = class Service {
constructor(apiKey = '855fb3867fa7108f3d6a43d7405878e6') {
this.apiKey = apiKey;
this.city = null;
}

setCity(city) {
this.city = city; // obj:{ name: string, id: int}
}

getCurrentWeather(err, callback) {
const url = `http://api.openweathermap.org/data/2.5/weather?q=${this.city.name}&appid=${this.apiKey}`;
const req = new XMLHttpRequest();
+ req.open('get', url, true);
- req.open('get', url, false);
req.send();
req.onload = callback;
req.onerror = err;
}

getForecastWeather(err, callback) {
const url = `http://api.openweathermap.org/data/2.5/forecast?q=${this.city.name}&appid=${this.apiKey}`;
const req = new XMLHttpRequest();
req.onload = callback;
req.onerror = err;
+ req.open('get', url, true);
- req.open('get', url, false);
req.send();
}
}

})(apiWeather);
```diff apiIceAndFire.js
const sendGetRequest = (req, url) => {
+ req.open('get', url, true);
- req.open('get', url, false);
req.send();
};

```
* Open and show results on developer tools.
24 changes: 0 additions & 24 deletions 02 How to avoid blocking/gulpfile.js

This file was deleted.

Loading