You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 8-web-components/2-custom-elements/article.md
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,7 +219,7 @@ Quando il parser HTML costruisce il DOM, gli elementi vengono processati uno dop
219
219
220
220
Ciò porta ad importanti conseguenze per gli elementi personlizzati.
221
221
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é:
223
223
224
224
```html run height=40
225
225
<script>
@@ -239,15 +239,15 @@ customElements.define('user-info', class extends HTMLElement {
239
239
*/!*
240
240
```
241
241
242
-
If you run it, the `alert` is empty.
242
+
Eseguendolo, `alert` risulterebbe vuoto is empty.
243
243
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.
245
245
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.
247
247
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.
249
249
250
-
This works:
250
+
Così funziona:
251
251
252
252
```html run height=40
253
253
<script>
@@ -267,20 +267,20 @@ customElements.define('user-info', class extends HTMLElement {
267
267
*/!*
268
268
```
269
269
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.
271
271
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.
273
273
274
-
So the outer element finishes the initialization before the inner one.
274
+
E così l'elemento esterno terminerebbe prima di quello interno.
@@ -292,26 +292,26 @@ customElements.define('user-info', class extends HTMLElement {
292
292
*/!*
293
293
```
294
294
295
-
Output order:
295
+
Ordine di output:
296
296
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.
301
301
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)`.
303
303
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.
305
305
306
306
## Customized built-in elements
307
307
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.
309
309
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>`?
311
311
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.
313
313
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.
0 commit comments