Skip to content
Open
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 @@
Observe:

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.
1. Limpamos o timer `setInterval` quando o elemento é removido do documento. Isso é importante, caso contrário ele continua atualizando mesmo que não seja mais necessário. E o navegador não consegue limpar a memória deste elemento e referenciados por ele.
2. Podemos acessar a data atual como propriedade `elem.date`. Todos os métodos e propriedades da classe são naturalmente métodos e propriedades do 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 para deixar o elemento ser coletado como lixo
}

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

<!-- your code here: -->
<!-- seu código aqui: -->
<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 */
/* Seu código aqui */

}

Expand Down
16 changes: 8 additions & 8 deletions 8-web-components/2-custom-elements/1-live-timer/task.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Elemento timer ao vivo

# Live timer element
Já temos o elemento `<time-formatted>` para mostrar um tempo bem formatado.

We already have `<time-formatted>` element to show a nicely formatted time.
Crie o elemento `<live-timer>` para mostrar o tempo atual:

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>).
1. Ele deve usar `<time-formatted>` internamente, não duplicar sua funcionalidade.
2. Atualiza a cada segundo.
3. Para cada atualização, um evento customizado chamado `tick` deve ser gerado, com a data atual em `event.detail` (veja o capítulo <info:dispatch-events>).

Usage:
Uso:

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

<script>
elem.addEventListener('tick', event => console.log(event.detail));
elem.addEventListener("tick", (event) => console.log(event.detail));
</script>
```

Expand Down
Loading