Skip to content

Commit 0079361

Browse files
authored
Merge pull request #277 from pierangelomiceli/025_cust_ele
Custom elements
2 parents 2ce86d8 + 064a18d commit 0079361

File tree

6 files changed

+117
-118
lines changed

6 files changed

+117
-118
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

2-
Please note:
3-
1. We clear `setInterval` timer when the element is removed from the document. That's important, otherwise it continues ticking even if not needed any more. And the browser can't clear the memory from this element and referenced by it.
4-
2. We can access current date as `elem.date` property. All class methods and properties are naturally element methods and properties.
2+
Nota bene:
3+
1. Quando rimuoviamo l'elemento dal documento, eseguiamo il clear di `setInterval` per il timer. È importante, altrimenti continuerà a ticchettare anche se non più necessario. Inoltre il browser avendo ancora un riferimento ad esso, non sarà in grado di pulire la sua memoria.
4+
2. Deve essere possibile accedere alla data corrente tramite la proprietà `elem.date`. Tutti i metodi della classe e le relative proprietà devono anche essere metodi e proprietà dell'elemento.

8-web-components/2-custom-elements/1-live-timer/solution.view/live-timer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class LiveTimer extends HTMLElement {
2424
}
2525

2626
disconnectedCallback() {
27-
clearInterval(this.timer); // important to let the element be garbage-collected
27+
clearInterval(this.timer); // importante per permettere all'elemento di essere gestito dal garbage-collector
2828
}
2929

3030
}

8-web-components/2-custom-elements/1-live-timer/source.view/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!doctype html>
2-
<!-- don't modify this -->
2+
<!-- non modifcare -->
33
<script src="time-formatted.js"></script>
44

5-
<!-- your code here: -->
5+
<!-- inserite qui il vostro codice: -->
66
<script src="live-timer.js"></script>
77

88
<live-timer id="elem"></live-timer>

8-web-components/2-custom-elements/1-live-timer/source.view/live-timer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class LiveTimer extends HTMLElement {
22

3-
/* your code here */
3+
/* inserite qui il vostro codice */
44

55
}
66

8-web-components/2-custom-elements/1-live-timer/task.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
# Live timer element
2+
# Elemento live timer
33

4-
We already have `<time-formatted>` element to show a nicely formatted time.
4+
Abbiamo già un elemento `<time-formatted>` per mostrare un orario formattato.
55

6-
Create `<live-timer>` element to show the current time:
7-
1. It should use `<time-formatted>` internally, not duplicate its functionality.
8-
2. Ticks (updates) every second.
9-
3. For every tick, a custom event named `tick` should be generated, with the current date in `event.detail` (see chapter <info:dispatch-events>).
6+
Create un elemento `<live-timer>` per mostrare l'orario corrente con queste specifiche:
7+
1. Internamente dovrebbe usare `<time-formatted>`, senza duplicarne la funzionalità.
8+
2. Un tick (aggiornamento) ogni secondo.
9+
3. Per ogni tick, deve essere generato un evento personalizzato chiamato `tick`, con la data corrente dentro `event.detail` (guardare il capitolo <info:dispatch-events>).
1010

11-
Usage:
11+
Uso:
1212

1313
```html
1414
<live-timer id="elem"></live-timer>

0 commit comments

Comments
 (0)