Skip to content

Commit 8d38743

Browse files
authored
Merge pull request #193 from otmon76/1.11.2
Promise
2 parents 2a8d3ee + b7be750 commit 8d38743

File tree

11 files changed

+219
-218
lines changed

11 files changed

+219
-218
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
The output is: `1`.
1+
Výstup je: `1`.
22

3-
The second call to `resolve` is ignored, because only the first call of `reject/resolve` is taken into account. Further calls are ignored.
3+
Druhé volání `splň` se ignoruje, protože v úvahu se bere vždy jen první volání `splň/zamítni`. Další volání jsou ignorována.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
# Re-resolve a promise?
2+
# Znovusplnění příslibu?
33

44

5-
What's the output of the code below?
5+
Jaký je výstup následujícího kódu?
66

77
```js
8-
let promise = new Promise(function(resolve, reject) {
9-
resolve(1);
8+
let příslib = new Promise(function(splň, zamítni) {
9+
splň(1);
1010

11-
setTimeout(() => resolve(2), 1000);
11+
setTimeout(() => splň(2), 1000);
1212
});
1313

14-
promise.then(alert);
14+
příslib.then(alert);
1515
```
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
```js run
2-
function delay(ms) {
3-
return new Promise(resolve => setTimeout(resolve, ms));
2+
function čekej(ms) {
3+
return new Promise(splň => setTimeout(splň, ms));
44
}
55

6-
delay(3000).then(() => alert('runs after 3 seconds'));
6+
čekej(3000).then(() => alert('spustí se za 3 sekundy'));
77
```
88

9-
Please note that in this task `resolve` is called without arguments. We don't return any value from `delay`, just ensure the delay.
9+
Prosíme všimněte si, že v této úloze je `splň` voláno bez argumentů. Z funkce `čekej` nevracíme žádnou hodnotu, jen zajistíme čekání.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
# Delay with a promise
2+
# Čekání s příslibem
33

4-
The built-in function `setTimeout` uses callbacks. Create a promise-based alternative.
4+
Vestavěná funkce `setTimeout` používá callbacky. Vytvořte alternativu založenou na příslibech.
55

6-
The function `delay(ms)` should return a promise. That promise should resolve after `ms` milliseconds, so that we can add `.then` to it, like this:
6+
Funkce `čekej(ms)` by měla vrátit příslib. Tento příslib by se měl splnit za `ms` milisekund, takže do něj můžeme přidat `.then`, například:
77

88
```js
9-
function delay(ms) {
10-
// your code
9+
function čekej(ms) {
10+
// váš kód
1111
}
1212

13-
delay(3000).then(() => alert('runs after 3 seconds'));
13+
čekej(3000).then(() => alert('spustí se za 3 sekundy'));
1414
```

1-js/11-async/02-promise-basics/03-animate-circle-promise/solution.view/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222

2323
<body>
2424

25-
<button onclick="go()">Click me</button>
25+
<button onclick="spusť()">Klikni na mne</button>
2626

2727
<script>
2828

29-
function go() {
30-
showCircle(150, 150, 100).then(div => {
29+
function spusť() {
30+
zobrazKruh(150, 150, 100).then(div => {
3131
div.classList.add('message-ball');
32-
div.append("Hello, world!");
32+
div.append("Ahoj, světe!");
3333
});
3434
}
3535

36-
function showCircle(cx, cy, radius) {
36+
function zobrazKruh(cx, cy, poloměr) {
3737
let div = document.createElement('div');
3838
div.style.width = 0;
3939
div.style.height = 0;
@@ -44,8 +44,8 @@
4444

4545
return new Promise(resolve => {
4646
setTimeout(() => {
47-
div.style.width = radius * 2 + 'px';
48-
div.style.height = radius * 2 + 'px';
47+
div.style.width = poloměr * 2 + 'px';
48+
div.style.height = poloměr * 2 + 'px';
4949

5050
div.addEventListener('transitionend', function handler() {
5151
div.removeEventListener('transitionend', handler);
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

2-
# Animated circle with promise
2+
# Animovaný kruh s příslibem
33

4-
Rewrite the `showCircle` function in the solution of the task <info:task/animate-circle-callback> so that it returns a promise instead of accepting a callback.
4+
Přepište funkci `zobrazKruh` v řešení úlohy <info:task/animate-circle-callback> tak, aby místo přijímání callbacku vracela příslib.
55

6-
The new usage:
6+
Nové použití:
77

88
```js
9-
showCircle(150, 150, 100).then(div => {
9+
zobrazKruh(150, 150, 100).then(div => {
1010
div.classList.add('message-ball');
11-
div.append("Hello, world!");
11+
div.append("Ahoj, světe!");
1212
});
1313
```
1414

15-
Take the solution of the task <info:task/animate-circle-callback> as the base.
15+
Jako základ vezměte řešení úlohy <info:task/animate-circle-callback>.

1-js/11-async/02-promise-basics/article.md

Lines changed: 179 additions & 178 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<script>
2-
function loadScript(src) {
2+
function načtiSkript(src) {
33
return new Promise(function(resolve, reject) {
4-
let script = document.createElement('script');
5-
script.src = src;
4+
let skript = document.createElement('script');
5+
skript.src = src;
66

7-
script.onload = () => resolve(script);
8-
script.onerror = () => reject(new Error("Script load error: " + src));
7+
skript.onload = () => resolve(skript);
8+
skript.onerror = () => reject(new Error("Chyba při načítání skriptu: " + src));
99

10-
document.head.append(script);
10+
document.head.append(skript);
1111
});
1212
}
1313
</script>
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)