From ad176f6e7c4b3090e0c528e9897835ec89800fae Mon Sep 17 00:00:00 2001 From: Carlos Ortiz Gutierrez Date: Wed, 13 May 2020 16:29:34 -0600 Subject: [PATCH 1/8] 1-11-03-pc Traducido 11 1-11-03-pc Corregido 8 1-11-03-pc Corregido 8 coregido typos --- .../01-then-vs-catch/solution.md | 10 +- .../01-then-vs-catch/task.md | 4 +- 1-js/11-async/03-promise-chaining/article.md | 196 ++++++++---------- .../03-promise-chaining/getMessage.js | 2 +- 1-js/11-async/03-promise-chaining/head.html | 21 +- .../promise-handler-variants.svg | 59 +----- .../promise-then-chain.svg | 39 +--- .../03-promise-chaining/promise-then-many.svg | 33 +-- 1-js/11-async/03-promise-chaining/user.json | 2 +- 9 files changed, 101 insertions(+), 265 deletions(-) diff --git a/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md b/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md index 5a00f348f..b8f65ffbc 100644 --- a/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md +++ b/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md @@ -1,6 +1,6 @@ -The short answer is: **no, they are not the equal**: +La respuesta corta es: **no, no son iguales**: -The difference is that if an error happens in `f1`, then it is handled by `.catch` here: +La diferencia es que si ocurre un error en `f1`, entonces es manejado por `.catch` aquí: ```js run promise @@ -8,13 +8,13 @@ promise .catch(f2); ``` -...But not here: +...Pero no aquí: ```js run promise .then(f1, f2); ``` -That's because an error is passed down the chain, and in the second code piece there's no chain below `f1`. +Esto se debe a que se pasa un error por la cadena y en la segunda pieza del código no hay una cadena debajo de `f1`. -In other words, `.then` passes results/errors to the next `.then/catch`. So in the first example, there's a `catch` below, and in the second one -- there isn't, so the error is unhandled. +En otras palabras, `.then` pasa los resultados/errores al siguiente `.then/catch`. Entonces, en el primer ejemplo, hay un `catch` debajo, y en el segundo no lo hay, por lo que el error no se maneja. diff --git a/1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md b/1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md index cefca60aa..26bbced4a 100644 --- a/1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md +++ b/1-js/11-async/03-promise-chaining/01-then-vs-catch/task.md @@ -1,6 +1,6 @@ -# Promise: then versus catch +# Promesa: then versus catch -Are these code fragments equal? In other words, do they behave the same way in any circumstances, for any handler functions? +¿Son iguales estos fragmentos de código? En otras palabras, ¿se comportan de la misma manera en cualquier circunstancia, para cualquier función de controlador? ```js promise.then(f1).catch(f2); diff --git a/1-js/11-async/03-promise-chaining/article.md b/1-js/11-async/03-promise-chaining/article.md index 9e560d67d..19c6e94a3 100644 --- a/1-js/11-async/03-promise-chaining/article.md +++ b/1-js/11-async/03-promise-chaining/article.md @@ -1,13 +1,13 @@ -# Promises chaining +# Encadenamiento de promesas -Let's return to the problem mentioned in the chapter : we have a sequence of asynchronous tasks to be done one after another. For instance, loading scripts. How can we code it well? +Volvamos al problema mencionado en el capítulo : tenemos una secuencia de tareas asincrónicas que se realizarán una tras otra, por ejemplo, cargar scripts. ¿Cómo podemos codificarlo bien? -Promises provide a couple of recipes to do that. +Las promesas proporcionan un par de recetas para hacer eso. -In this chapter we cover promise chaining. +En este capítulo cubrimos el encadenamiento de promesas. -It looks like this: +Se parece a esto: ```js run new Promise(function(resolve, reject) { @@ -32,43 +32,25 @@ new Promise(function(resolve, reject) { }); ``` -The idea is that the result is passed through the chain of `.then` handlers. +La idea es que el resultado pase a través de la cadena de controladores `.then`. -Here the flow is: -1. The initial promise resolves in 1 second `(*)`, -2. Then the `.then` handler is called `(**)`. -3. The value that it returns is passed to the next `.then` handler `(***)` -4. ...and so on. +Aquí el flujo es: +1. La promesa inicial se resuelve en 1 segundo `(*)`, +2. Entonces se llama el controlador `.then` `(**) `. +3. El valor que devuelve se pasa al siguiente controlador `.then` `(***)` +4. ...y así. -As the result is passed along the chain of handlers, we can see a sequence of `alert` calls: `1` -> `2` -> `4`. +A medida que el resultado se pasa a lo largo de la cadena de controladores, podemos ver una secuencia de llamadas de alerta: `1` -> `2` -> `4`. ![](promise-then-chain.svg) -The whole thing works, because a call to `promise.then` returns a promise, so that we can call the next `.then` on it. +Todo funciona, porque una llamada a `promise.then` devuelve una promesa, para que podamos llamar a la siguiente `.then`. -When a handler returns a value, it becomes the result of that promise, so the next `.then` is called with it. +Cuando un controlador devuelve un valor, se convierte en el resultado de esa promesa, por lo que se llama al siguiente `.then`. -To make these words more clear, here's the start of the chain: +**Un error clásico de novato: técnicamente también podemos agregar muchos '.then' a una sola promesa. Esto no está encadenando.** -```js run -new Promise(function(resolve, reject) { - - setTimeout(() => resolve(1), 1000); - -}).then(function(result) { - - alert(result); - return result * 2; // <-- (1) - -}) // <-- (2) -// .then… -``` - -The value returned by `.then` is a promise, that's why we are able to add another `.then` at `(2)`. When the value is returned in `(1)`, that promise becomes resolved, so the next handler runs with the value. - -**A classic newbie error: technically we can also add many `.then` to a single promise. This is not chaining.** - -For example: +Por ejemplo: ```js run let promise = new Promise(function(resolve, reject) { setTimeout(() => resolve(1), 1000); @@ -90,23 +72,23 @@ promise.then(function(result) { }); ``` -What we did here is just several handlers to one promise. They don't pass the result to each other, instead they process it independently. +Lo que hicimos aquí fue varios controladores para una sola promesa. No se pasan el resultado el uno al otro; en su lugar lo procesan de forma independiente. -Here's the picture (compare it with the chaining above): +Aquí está la imagen (compárela con el encadenamiento anterior): ![](promise-then-many.svg) -All `.then` on the same promise get the same result -- the result of that promise. So in the code above all `alert` show the same: `1`. +Todos los '.then' en la misma promesa obtienen el mismo resultado: el resultado de esa promesa. Entonces, en el código sobre todo `alert` muestra lo mismo: `1`. -In practice we rarely need multiple handlers for one promise. Chaining is used much more often. +En la práctica, rara vez necesitamos múltiples manejadores para una promesa. El encadenamiento se usa mucho más a menudo. -## Returning promises +## Retornando promesas -Normally, a value returned by a `.then` handler is immediately passed to the next handler. But there's an exception. +Un controlador, utilizado en `.then(handler)` puede crear y devolver una promesa. -If the returned value is a promise, then the further execution is suspended until it settles. After that, the result of that promise is given to the next `.then` handler. +En ese caso, otros manejadores esperan hasta que se estabilice y luego obtienen su resultado. -For instance: +Por ejemplo: ```js run new Promise(function(resolve, reject) { @@ -138,15 +120,15 @@ new Promise(function(resolve, reject) { }); ``` -Here the first `.then` shows `1` returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result*2`) is passed on to handler of the second `.then` in the line `(**)`. It shows `2` and does the same thing. +Aquí el primer `.then` muestra `1` y devuelve `new Promise(...)` en la línea `(*)`. Después de un segundo, se resuelve, y el resultado (el argumento de `resolve`, aquí es `result * 2`) se pasa al controlador del segundo `.then`. Ese controlador está en la línea `(**)`, muestra `2` y hace lo mismo. -So the output is again 1 -> 2 -> 4, but now with 1 second delay between `alert` calls. +Por lo tanto, la salida es la misma que en el ejemplo anterior: 1 -> 2 -> 4, pero ahora con 1 segundo de retraso entre las llamadas de alerta. -Returning promises allows us to build chains of asynchronous actions. +Devolver las promesas nos permite construir cadenas de acciones asincrónicas. -## Example: loadScript +## El ejemplo: loadScript -Let's use this feature with `loadScript` to load scripts one by one, in sequence: +Usemos esta función con el `loadScript` prometido, definido en el [capítulo anterior](info:promise-basics#loadscript), para cargar los scripts uno por uno, en secuencia: ```js run loadScript("/article/promise-chaining/one.js") @@ -157,22 +139,22 @@ loadScript("/article/promise-chaining/one.js") return loadScript("/article/promise-chaining/three.js"); }) .then(function(script) { - // use functions declared in scripts - // to show that they indeed loaded + // usar funciones declaradas en scripts + // para mostrar que efectivamente cargaron one(); two(); three(); }); ``` -This code can be made bit shorter with arrow functions: +Este código se puede acortar un poco con las funciones de flecha: ```js run loadScript("/article/promise-chaining/one.js") .then(script => loadScript("/article/promise-chaining/two.js")) .then(script => loadScript("/article/promise-chaining/three.js")) .then(script => { - // scripts are loaded, we can use functions declared there + // los scripts se cargan, podemos usar funciones declaradas allí one(); two(); three(); @@ -180,17 +162,17 @@ loadScript("/article/promise-chaining/one.js") ``` -Here each `loadScript` call returns a promise, and the next `.then` runs when it resolves. Then it initiates the loading of the next script. So scripts are loaded one after another. +Aquí cada llamada a `loadScript` devuelve una promesa, y el siguiente `.then` se ejecuta cuando se resuelve. Luego inicia la carga del siguiente script. Entonces los scripts se cargan uno tras otro. -We can add more asynchronous actions to the chain. Please note that code is still "flat", it grows down, not to the right. There are no signs of "pyramid of doom". +Podemos agregar más acciones asincrónicas a la cadena. Tenga en cuenta que el código sigue siendo "plano": crece hacia abajo, no a la derecha. No hay signos de la "pirámide del destino". -Please note that technically we can add `.then` directly to each `loadScript`, like this: +Técnicamente, podríamos agregar `.then` directamente a cada `loadScript`, así: ```js run loadScript("/article/promise-chaining/one.js").then(script1 => { loadScript("/article/promise-chaining/two.js").then(script2 => { loadScript("/article/promise-chaining/three.js").then(script3 => { - // this function has access to variables script1, script2 and script3 + // esta función tiene acceso a las variables script1, script2 y script3 one(); two(); three(); @@ -199,21 +181,19 @@ loadScript("/article/promise-chaining/one.js").then(script1 => { }); ``` -This code does the same: loads 3 scripts in sequence. But it "grows to the right". So we have the same problem as with callbacks. +Este código hace lo mismo: carga 3 scripts en secuencia. Pero "crece hacia la derecha". Entonces tenemos el mismo problema que con los callbacks. -People who start to use promises sometimes don't know about chaining, so they write it this way. Generally, chaining is preferred. +Las personas que comienzan a usar promesas a veces no saben de encadenamiento, por lo que lo escriben de esta manera. En general, se prefiere el encadenamiento. -Sometimes it's ok to write `.then` directly, because the nested function has access to the outer scope. In the example above the most nested callback has access to all variables `script1`, `script2`, `script3`. But that's an exception rather than a rule. +A veces está bien escribir `.then` directamente, porque la función anidada tiene acceso al ámbito externo. En el ejemplo anterior, el callback más anidado tiene acceso a todas las variables `script1`, `script2`, `script3`. Pero eso es una excepción más que una regla. -````smart header="Thenables" -To be precise, `.then` may return an arbitrary "thenable" object, and it will be treated the same way as a promise. +````smart header="Objetos Thenables" +Para ser precisos, un controlador puede devolver no exactamente una promesa, sino un objeto llamado "thenable", un objeto arbitrario que tiene un método `.then`. Será tratado de la misma manera que una promesa. -A "thenable" object is any object with a method `.then`. +La idea es que las librerias de terceros puedan implementar sus propios objetos "compatibles con la promesa". Pueden tener un conjunto extendido de métodos, pero también pueden ser compatibles con las promesas nativas, porque implementan `.then`. -The idea is that 3rd-party libraries may implement "promise-compatible" objects of their own. They can have extended set of methods, but also be compatible with native promises, because they implement `.then`. - -Here's an example of a thenable object: +Aquí hay un ejemplo de un objeto que se puede guardar: ```js run class Thenable { @@ -221,80 +201,82 @@ class Thenable { this.num = num; } then(resolve, reject) { - alert(resolve); // function() { native code } - // resolve with this.num*2 after the 1 second + alert(resolve); // function() { código nativo } + // resolve con this.num*2 después de 1 segundo setTimeout(() => resolve(this.num * 2), 1000); // (**) } } new Promise(resolve => resolve(1)) .then(result => { +*!* return new Thenable(result); // (*) +*/!* }) - .then(alert); // shows 2 after 1000ms + .then(alert); // muestra 2 después de 1000 ms ``` -JavaScript checks the object returned by `.then` handler in the line `(*)`: if it has a callable method named `then`, then it calls that method providing native functions `resolve`, `reject` as arguments (similar to executor) and waits until one of them is called. In the example above `resolve(2)` is called after 1 second `(**)`. Then the result is passed further down the chain. +JavaScript comprueba el objeto devuelto por el controlador `.then` en la línea `(*)`: si tiene un método invocable llamado `then`, entonces llama a ese método que proporciona funciones nativas `resolve`, `accept` como argumentos (similar a un ejecutor) y espera hasta que se llame a uno de ellos. En el ejemplo anterior, se llama a `resolve(2)` después de 1 segundo `(**)`. Luego, el resultado se pasa más abajo en la cadena. -This feature allows to integrate custom objects with promise chains without having to inherit from `Promise`. +Esta característica nos permite integrar objetos personalizados con cadenas de promesa sin tener que heredar de `Promise`. ```` -## Bigger example: fetch +## Ejemplo más grande: fetch -In frontend programming promises are often used for network requests. So let's see an extended example of that. +En la interfaz de programación, las promesas a menudo se usan para solicitudes de red. Así que veamos un ejemplo extendido de eso. -We'll use the [fetch](mdn:api/WindowOrWorkerGlobalScope/fetch) method to load the information about the user from the remote server. The method is quite complex, it has many optional parameters, but the basic usage is quite simple: +Utilizaremos el método [fetch](info:fetch) para cargar la información sobre el usuario desde el servidor remoto. Tiene muchos parámetros opcionales cubiertos en [capítulos separados](info:fetch), pero la sintaxis básica es bastante simple: ```js let promise = fetch(url); ``` -This makes a network request to the `url` and returns a promise. The promise resolves with a `response` object when the remote server responds with headers, but *before the full response is downloaded*. +Esto hace una solicitud de red a la `url` y devuelve una promesa. La promesa se resuelve con un objeto 'response' cuando el servidor remoto responde con encabezados, pero *antes de que se descargue la respuesta completa*. -To read the full response, we should call a method `response.text()`: it returns a promise that resolves when the full text downloaded from the remote server, with that text as a result. +Para leer la respuesta completa, debemos llamar al método `response.text()`: devuelve una promesa que se resuelve cuando se descarga el texto completo del servidor remoto, con ese texto como resultado. -The code below makes a request to `user.json` and loads its text from the server: +El siguiente código hace una solicitud a `user.json` y carga su texto desde el servidor: ```js run fetch('/article/promise-chaining/user.json') - // .then below runs when the remote server responds + // .a continuación, se ejecuta cuando el servidor remoto responde .then(function(response) { - // response.text() returns a new promise that resolves with the full response text - // when we finish downloading it + // response.text() devuelve una nueva promesa que se resuelve con el texto de respuesta completo + // cuando se carga return response.text(); }) .then(function(text) { - // ...and here's the content of the remote file - alert(text); // {"name": "iliakan", isAdmin: true} + // ...y aquí está el contenido del archivo remoto + alert(text); // {"nombre": "iliakan", isAdmin: true} }); ``` -There is also a method `response.json()` that reads the remote data and parses it as JSON. In our case that's even more convenient, so let's switch to it. +El objeto `response` devuelto por `fetch` también incluye el método `response.json()` que lee los datos remotos y los analiza como JSON. En nuestro caso, eso es aún más conveniente, así que pasemos a ello. -We'll also use arrow functions for brevity: +También usaremos las funciones de flecha por brevedad: ```js run -// same as above, but response.json() parses the remote content as JSON +// igual que el anterior, pero response.json() analiza el contenido remoto como JSON fetch('/article/promise-chaining/user.json') .then(response => response.json()) - .then(user => alert(user.name)); // iliakan + .then(user => alert(user.name)); // iliakan, tengo nombre de usuario ``` -Now let's do something with the loaded user. +Ahora hagamos algo con el usuario cargado. -For instance, we can make one more request to github, load the user profile and show the avatar: +Por ejemplo, podemos hacer una solicitud más a GitHub, cargar el perfil de usuario y mostrar el avatar: ```js run -// Make a request for user.json +// Hacer una solicitud para user.json fetch('/article/promise-chaining/user.json') - // Load it as json + // Cárgalo como json .then(response => response.json()) - // Make a request to github + // Hacer una solicitud a GitHub .then(user => fetch(`https://api.github.com/users/${user.name}`)) - // Load the response as json + // Cargue la respuesta como json .then(response => response.json()) - // Show the avatar image (githubUser.avatar_url) for 3 seconds (maybe animate it) + // Mostrar la imagen de avatar (githubUser.avatar_url) durante 3 segundos (tal vez animarla) .then(githubUser => { let img = document.createElement('img'); img.src = githubUser.avatar_url; @@ -305,13 +287,13 @@ fetch('/article/promise-chaining/user.json') }); ``` -The code works, see comments about the details, but it should be quite self-descriptive. Although, there's a potential problem in it, a typical error of those who begin to use promises. +El código funciona; ver comentarios sobre los detalles. Sin embargo, hay un problema potencial, un error típico para aquellos que comienzan a usar promesas. -Look at the line `(*)`: how can we do something *after* the avatar has finished showing and gets removed? For instance, we'd like to show a form for editing that user or something else. As of now, there's no way. +Mire la línea `(*)`: ¿cómo podemos hacer algo *después de* que el avatar haya terminado de mostrarse y se elimine? Por ejemplo, nos gustaría mostrar un formulario para editar ese usuario u otra cosa. A partir de ahora, no hay manera. -To make the chain extendable, we need to return a promise that resolves when the avatar finishes showing. +Para que la cadena sea extensible, debemos devolver una promesa que se resuelva cuando el avatar termine de mostrarse. -Like this: +Como este: ```js run fetch('/article/promise-chaining/user.json') @@ -319,7 +301,7 @@ fetch('/article/promise-chaining/user.json') .then(user => fetch(`https://api.github.com/users/${user.name}`)) .then(response => response.json()) *!* - .then(githubUser => new Promise(function(resolve, reject) { + .then(githubUser => new Promise(function(resolve, reject) { // (*) */!* let img = document.createElement('img'); img.src = githubUser.avatar_url; @@ -329,21 +311,19 @@ fetch('/article/promise-chaining/user.json') setTimeout(() => { img.remove(); *!* - resolve(githubUser); + resolve(githubUser); // (**) */!* }, 3000); })) - // triggers after 3 seconds - .then(githubUser => alert(`Finished showing ${githubUser.name}`)); + // se dispara después de 3 segundos + .then(githubUser => alert(`Terminado de mostrar ${githubUser.name}`)); ``` -Now right after `setTimeout` runs `img.remove()`, it calls `resolve(githubUser)`, thus passing the control to the next `.then` in the chain and passing forward the user data. - -As a rule, an asynchronous action should always return a promise. +Es decir, el controlador `.then` en la línea `(*)` ahora devuelve `new Promise`, que se resuelve solo después de la llamada de `resolve(githubUser)` en `setTimeout` `(**)`. El siguiente '.then' en la cadena esperará eso. -That makes it possible to plan actions after it. Even if we don't plan to extend the chain now, we may need it later. +Como buena práctica, una acción asincrónica siempre debe devolver una promesa. Eso hace posible planificar acciones posteriores; incluso si no planeamos extender la cadena ahora, es posible que la necesitemos más adelante. -Finally, we can split the code into reusable functions: +Finalmente, podemos dividir el código en funciones reutilizables: ```js run function loadJson(url) { @@ -370,7 +350,7 @@ function showAvatar(githubUser) { }); } -// Use them: +// Úsalos: loadJson('/article/promise-chaining/user.json') .then(user => loadGithubUser(user.name)) .then(showAvatar) @@ -378,10 +358,10 @@ loadJson('/article/promise-chaining/user.json') // ... ``` -## Summary +## Resumen -If a `.then` (or `catch/finally`, doesn't matter) handler returns a promise, the rest of the chain waits until it settles. When it does, its result (or error) is passed further. +Si un controlador `.then` (o `catch/finally`, no importa) devuelve una promesa, el resto de la cadena espera hasta que se asiente. Cuando lo hace, su resultado (o error) se pasa más allá. -Here's a full picture: +Aquí hay una imagen completa: ![](promise-handler-variants.svg) diff --git a/1-js/11-async/03-promise-chaining/getMessage.js b/1-js/11-async/03-promise-chaining/getMessage.js index 6c5893433..3f9ae0a68 100644 --- a/1-js/11-async/03-promise-chaining/getMessage.js +++ b/1-js/11-async/03-promise-chaining/getMessage.js @@ -1,3 +1,3 @@ function getMessage() { - return "Hello, world!"; + return "Hola, mundo!"; } diff --git a/1-js/11-async/03-promise-chaining/head.html b/1-js/11-async/03-promise-chaining/head.html index 31c6b4271..2fbb57791 100644 --- a/1-js/11-async/03-promise-chaining/head.html +++ b/1-js/11-async/03-promise-chaining/head.html @@ -5,30 +5,11 @@ script.src = src; script.onload = () => resolve(script); - script.onerror = () => reject(new Error("Script load error: " + src)); + script.onerror = () => reject(new Error("Error de carga de script: " + src)); document.head.append(script); }); } - -class HttpError extends Error { - constructor(response) { - super(`${response.status} for ${response.url}`); - this.name = 'HttpError'; - this.response = response; - } -} - -function loadJson(url) { - return fetch(url) - .then(response => { - if (response.status == 200) { - return response.json(); - } else { - throw new HttpError(response); - } - }) -} return valuereturn promisethrow errorstate: "fulfilled" result: valuestate: "rejected" result: error...with the result of the new promise...state: "pending" result: undefinedthe call of .then(handler) always returns a promise:if handler ends with…that promise settles with: \ No newline at end of file diff --git a/1-js/11-async/03-promise-chaining/promise-then-chain.svg b/1-js/11-async/03-promise-chaining/promise-then-chain.svg index d0faae2b7..0a3ea6d37 100644 --- a/1-js/11-async/03-promise-chaining/promise-then-chain.svg +++ b/1-js/11-async/03-promise-chaining/promise-then-chain.svg @@ -1,38 +1 @@ - - - - promise-then-chain.svg - Created with sketchtool. - - - - - .then - - - - new Promise - - - resolve(1) - - - return 2 - - - - - .then - - - return 4 - - - - - .then - - - - - \ No newline at end of file +.thennew Promiseresolve(1)return 2.thenreturn 4.then \ No newline at end of file diff --git a/1-js/11-async/03-promise-chaining/promise-then-many.svg b/1-js/11-async/03-promise-chaining/promise-then-many.svg index d745dee5e..ce8dc1c0c 100644 --- a/1-js/11-async/03-promise-chaining/promise-then-many.svg +++ b/1-js/11-async/03-promise-chaining/promise-then-many.svg @@ -1,32 +1 @@ - - - - promise-then-many.svg - Created with sketchtool. - - - - - .then - - - - new Promise - - - resolve(1) - - - - - .then - - - - - .then - - - - - \ No newline at end of file +.thennew Promiseresolve(1).then.then \ No newline at end of file diff --git a/1-js/11-async/03-promise-chaining/user.json b/1-js/11-async/03-promise-chaining/user.json index 32f89971a..05f1db262 100644 --- a/1-js/11-async/03-promise-chaining/user.json +++ b/1-js/11-async/03-promise-chaining/user.json @@ -1,4 +1,4 @@ { - "name": "iliakan", + "nombre": "iliakan", "isAdmin": true } From 749127fbba36c386c9dde5579eedc57d5ebfdead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 09:53:23 -0600 Subject: [PATCH 2/8] Update 1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md --- 1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md b/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md index b8f65ffbc..cbb5b5320 100644 --- a/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md +++ b/1-js/11-async/03-promise-chaining/01-then-vs-catch/solution.md @@ -1,6 +1,6 @@ La respuesta corta es: **no, no son iguales**: -La diferencia es que si ocurre un error en `f1`, entonces es manejado por `.catch` aquí: +La diferencia es que si ocurre un error en `f1`, entonces aqui es manejado por `.catch`: ```js run promise From 78332ee4272e319e7844e880cbe57f6a8c68da51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 09:55:55 -0600 Subject: [PATCH 3/8] Update 1-js/11-async/03-promise-chaining/user.json --- 1-js/11-async/03-promise-chaining/user.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/user.json b/1-js/11-async/03-promise-chaining/user.json index 05f1db262..32f89971a 100644 --- a/1-js/11-async/03-promise-chaining/user.json +++ b/1-js/11-async/03-promise-chaining/user.json @@ -1,4 +1,4 @@ { - "nombre": "iliakan", + "name": "iliakan", "isAdmin": true } From a244a6cc893d083e2ee5a1ecd46ec4df78deee3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:05:35 -0600 Subject: [PATCH 4/8] Update 1-js/11-async/03-promise-chaining/article.md --- 1-js/11-async/03-promise-chaining/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/article.md b/1-js/11-async/03-promise-chaining/article.md index 19c6e94a3..1d2e2bdda 100644 --- a/1-js/11-async/03-promise-chaining/article.md +++ b/1-js/11-async/03-promise-chaining/article.md @@ -3,7 +3,7 @@ Volvamos al problema mencionado en el capítulo : tenemos una secuencia de tareas asincrónicas que se realizarán una tras otra, por ejemplo, cargar scripts. ¿Cómo podemos codificarlo bien? -Las promesas proporcionan un par de recetas para hacer eso. +Las promesas proporcionan un par de maneras para hacer eso. En este capítulo cubrimos el encadenamiento de promesas. From e76159872e442f127ed6f09665b533f8350df6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:05:44 -0600 Subject: [PATCH 5/8] Update 1-js/11-async/03-promise-chaining/article.md --- 1-js/11-async/03-promise-chaining/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/article.md b/1-js/11-async/03-promise-chaining/article.md index 1d2e2bdda..b4dc64564 100644 --- a/1-js/11-async/03-promise-chaining/article.md +++ b/1-js/11-async/03-promise-chaining/article.md @@ -44,7 +44,7 @@ A medida que el resultado se pasa a lo largo de la cadena de controladores, pode ![](promise-then-chain.svg) -Todo funciona, porque una llamada a `promise.then` devuelve una promesa, para que podamos llamar a la siguiente `.then`. +Todo funciona, porque una llamada a `promise.then` devuelve una promesa, para que podamos llamar al siguiente `.then`. Cuando un controlador devuelve un valor, se convierte en el resultado de esa promesa, por lo que se llama al siguiente `.then`. From ee80a684e06ca6c6a9d4c0bb99519e084dc27fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:05:57 -0600 Subject: [PATCH 6/8] Update 1-js/11-async/03-promise-chaining/article.md --- 1-js/11-async/03-promise-chaining/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/article.md b/1-js/11-async/03-promise-chaining/article.md index b4dc64564..759611521 100644 --- a/1-js/11-async/03-promise-chaining/article.md +++ b/1-js/11-async/03-promise-chaining/article.md @@ -248,7 +248,7 @@ fetch('/article/promise-chaining/user.json') }) .then(function(text) { // ...y aquí está el contenido del archivo remoto - alert(text); // {"nombre": "iliakan", isAdmin: true} + alert(text); // {"name": "iliakan", isAdmin: true} }); ``` From 1f04635ac3525973170d9bf073fca73e51fa6e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:06:12 -0600 Subject: [PATCH 7/8] Update 1-js/11-async/03-promise-chaining/article.md --- 1-js/11-async/03-promise-chaining/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/article.md b/1-js/11-async/03-promise-chaining/article.md index 759611521..b42f3f941 100644 --- a/1-js/11-async/03-promise-chaining/article.md +++ b/1-js/11-async/03-promise-chaining/article.md @@ -274,7 +274,7 @@ fetch('/article/promise-chaining/user.json') .then(response => response.json()) // Hacer una solicitud a GitHub .then(user => fetch(`https://api.github.com/users/${user.name}`)) - // Cargue la respuesta como json + // Carga la respuesta como json .then(response => response.json()) // Mostrar la imagen de avatar (githubUser.avatar_url) durante 3 segundos (tal vez animarla) .then(githubUser => { From 4d61e76a359456fe1f49ff7d67c886bff9026530 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ortiz=20Guti=C3=A9rrez?= <56600925+cortizg@users.noreply.github.com> Date: Tue, 9 Jun 2020 10:06:19 -0600 Subject: [PATCH 8/8] Update 1-js/11-async/03-promise-chaining/article.md --- 1-js/11-async/03-promise-chaining/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/11-async/03-promise-chaining/article.md b/1-js/11-async/03-promise-chaining/article.md index b42f3f941..686965d0a 100644 --- a/1-js/11-async/03-promise-chaining/article.md +++ b/1-js/11-async/03-promise-chaining/article.md @@ -74,7 +74,7 @@ promise.then(function(result) { Lo que hicimos aquí fue varios controladores para una sola promesa. No se pasan el resultado el uno al otro; en su lugar lo procesan de forma independiente. -Aquí está la imagen (compárela con el encadenamiento anterior): +Aquí está la imagen (compárala con el encadenamiento anterior): ![](promise-then-many.svg)