Skip to content

Commit 6a07ec9

Browse files
modifiche
1 parent 5a019cb commit 6a07ec9

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

8-web-components/2-custom-elements/article.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Quando il parser HTML costruisce il DOM, gli elementi vengono processati uno dop
219219

220220
Ciò porta ad importanti conseguenze per gli elementi personlizzati.
221221

222-
For example, if a custom element tries to access `innerHTML` in `connectedCallback`, it gets nothing:
222+
Per esempio, se un elemento custom provasse ad accedere all'`innerHTML` al `connectedCallback`, non otterbbe alcunché:
223223

224224
```html run height=40
225225
<script>
@@ -239,15 +239,15 @@ customElements.define('user-info', class extends HTMLElement {
239239
*/!*
240240
```
241241

242-
If you run it, the `alert` is empty.
242+
Eseguendolo, `alert` risulterebbe vuoto is empty.
243243

244-
That's exactly because there are no children on that stage, the DOM is unfinished. HTML parser connected the custom element `<user-info>`, and is going to proceed to its children, but just didn't yet.
244+
Questo è proprio perché non ci sono figli in questa fase ed il DOM è incompleto. Il parser ha collegato l'elemento custom `<user-info>`, e sta procedendo verso i suoi figli, ma nient'altro.
245245

246-
If we'd like to pass information to custom element, we can use attributes. They are available immediately.
246+
Se volessimo inviare delle informazioni all'elemnto, potremmo usare gli attributi, che sono subito disponibili.
247247

248-
Or, if we really need the children, we can defer access to them with zero-delay `setTimeout`.
248+
Oppure, se davvero abbiamo necessità di avere a che fare con i figli, possiamo ritardarne al''accesso, con un `setTimeout` a ritardo zero.
249249

250-
This works:
250+
Così funziona:
251251

252252
```html run height=40
253253
<script>
@@ -267,20 +267,20 @@ customElements.define('user-info', class extends HTMLElement {
267267
*/!*
268268
```
269269

270-
Now the `alert` in line `(*)` shows "John", as we run it asynchronously, after the HTML parsing is complete. We can process children if needed and finish the initialization.
270+
Ora l'alert `alert` alla riga `(*)` mostrerà "John", come se lo eseguissimo in modo asincrono, a parsing HTML completato. Possiamo processare i figli se necesssario e terminare l'iniziolizzazione.
271271

272-
On the other hand, this solution is also not perfect. If nested custom elements also use `setTimeout` to initialize themselves, then they queue up: the outer `setTimeout` triggers first, and then the inner one.
272+
D'altra parte la soluzione non è perfetta, perchè se anche i figli utilizzassero `setTimeout` per inzializzare sè stessi a loro volta, si metterebbero in coda: a quel punto prima verrebbe eseguito il `setTimeout` esterno, e poi quello interno.
273273

274-
So the outer element finishes the initialization before the inner one.
274+
E così l'elemento esterno terminerebbe prima di quello interno.
275275

276-
Let's demonstrate that on example:
276+
Vediamolo con un esempio:
277277

278278
```html run height=0
279279
<script>
280280
customElements.define('user-info', class extends HTMLElement {
281281
connectedCallback() {
282-
alert(`${this.id} connected.`);
283-
setTimeout(() => alert(`${this.id} initialized.`));
282+
alert(`${this.id} connesso.`);
283+
setTimeout(() => alert(`${this.id} inizializzato.`));
284284
}
285285
});
286286
</script>
@@ -292,26 +292,26 @@ customElements.define('user-info', class extends HTMLElement {
292292
*/!*
293293
```
294294

295-
Output order:
295+
Ordine di output:
296296

297-
1. outer connected.
298-
2. inner connected.
299-
3. outer initialized.
300-
4. inner initialized.
297+
1. esterno connesso.
298+
2. interno connesso.
299+
3. esterno inzializzato.
300+
4. interno inizializzato.
301301

302-
We can clearly see that the outer element finishes initialization `(3)` before the inner one `(4)`.
302+
Possiamo chiaramente verificar che l'elemento esterno conclude la sua inizializzazione `(3)` prima di quello interno `(4)`.
303303

304-
There's no built-in callback that triggers after nested elements are ready. If needed, we can implement such thing on our own. For instance, inner elements can dispatch events like `initialized`, and outer ones can listen and react on them.
304+
Non c'è una una callback che si attiva dopo che gli elmenti annidati sono pronti. Se necessario, possiamo implementare queste genere di cose da noi. per esempio, gli elementi interni possono eseguire eventi come `initialized`, e quelli esterni possono mettersi in ascolto e reagire di conseguenza.
305305

306306
## Customized built-in elements
307307

308-
New elements that we create, such as `<time-formatted>`, don't have any associated semantics. They are unknown to search engines, and accessibility devices can't handle them.
308+
I nuovi elementi che creiamo, come `<time-formatted>`, non hanno nessuna semantica associata. Sono del tutto sconosciuti a motori di ricerca, e i dispositivi di accessiblità non possono gestirli.
309309

310-
But such things can be important. E.g, a search engine would be interested to know that we actually show a time. And if we're making a special kind of button, why not reuse the existing `<button>` functionality?
310+
Ma anche queste cose possono essere rilevanti. Ad esempio al motore di ricerca potrebbe importare di conoscere che mostriamo l'orario. E ese stiamo un particolare tipo di pulsante, perché non riutilizzare la funzionalità esistente di `<button>`?
311311

312-
We can extend and customize built-in HTML elements by inheriting from their classes.
312+
Possiamo estedere e personalizzare gli elementi HTML built-in ereditando dalle lor classi.
313313

314-
For example, buttons are instances of `HTMLButtonElement`, let's build upon it.
314+
Per esempio, i pulsanti sono una istanza di `HTMLButtonElement`, lo quello andiamo a costruirci sopra.
315315

316316
1. Extend `HTMLButtonElement` with our class:
317317

0 commit comments

Comments
 (0)