Skip to content

Custom elements #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 8-web-components/2-custom-elements/1-live-timer/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

Please note:
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.
2. We can access current date as `elem.date` property. All class methods and properties are naturally element methods and properties.
Nota bene:
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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class LiveTimer extends HTMLElement {
}

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

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!doctype html>
<!-- don't modify this -->
<!-- non modifcare -->
<script src="time-formatted.js"></script>

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

<live-timer id="elem"></live-timer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class LiveTimer extends HTMLElement {

/* your code here */
/* inserite qui il vostro codice */

}

Expand Down
14 changes: 7 additions & 7 deletions 8-web-components/2-custom-elements/1-live-timer/task.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@

# Live timer element
# Elemento live timer

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

Create `<live-timer>` element to show the current time:
1. It should use `<time-formatted>` internally, not duplicate its functionality.
2. Ticks (updates) every second.
3. For every tick, a custom event named `tick` should be generated, with the current date in `event.detail` (see chapter <info:dispatch-events>).
Create un elemento `<live-timer>` per mostrare l'orario corrente con queste specifiche:
1. Internamente dovrebbe usare `<time-formatted>`, senza duplicarne la funzionalità.
2. Un tick (aggiornamento) ogni secondo.
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>).

Usage:
Uso:

```html
<live-timer id="elem"></live-timer>
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy