File tree Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Expand file tree Collapse file tree 2 files changed +22
-14
lines changed Original file line number Diff line number Diff line change @@ -48,12 +48,19 @@ styles.replaceSync(`
48
48
49
49
// Define the StopWatch element Class
50
50
class StopWatchElement extends HTMLElement {
51
- // Private state
51
+ static define (tag = " stop-watch" ) {
52
+ customElements .define (tag, this )
53
+ }
54
+
55
+ // Give this element its own encapsulated DOM
56
+ shadowRoot = this .attachShadow ({ mode: " open" })
57
+
58
+ // Initialize private state
52
59
#start = Date .now ()
53
60
54
61
connectedCallback () {
55
62
// Add the shared styles
56
- this .attachShadow ({ mode : " open " }) .adoptedStyleSheets = [styles]
63
+ this .shadowRoot .adoptedStyleSheets = [styles]
57
64
58
65
// Start the timer
59
66
this .#tick ()
@@ -64,15 +71,12 @@ class StopWatchElement extends HTMLElement {
64
71
const minutes = String (Math .floor (milliseconds / (1000 * 60 ))).padStart (2 , " 0" )
65
72
const seconds = String (Math .floor ((milliseconds / 1000 ) % 60 )).padStart (2 , " 0" )
66
73
const hundredths = String (Math .floor ((milliseconds % 1000 ) / 10 )).padStart (2 , " 0" )
67
- this .shadowRoot .innerHTML = ` ${ minutes} :${ seconds} :${ hundredths} `
74
+
75
+ this .shadowRoot .replaceChildren (` ${ minutes} :${ seconds} :${ hundredths} ` )
68
76
69
77
// Schedule next update
70
78
requestAnimationFrame (() => this .#tick ())
71
79
}
72
-
73
- static define (tag = " stop-watch" ) {
74
- customElements .define (tag, this )
75
- }
76
80
}
77
81
78
82
// Register the element with the Custom Element Registry
Original file line number Diff line number Diff line change @@ -39,12 +39,19 @@ styles.replaceSync(`
39
39
40
40
// Define the StopWatch element Class
41
41
class StopWatchElement extends HTMLElement {
42
- // Private state
42
+ static define (tag = " stop-watch" ) {
43
+ customElements .define (tag, this )
44
+ }
45
+
46
+ // Give this element its own encapsulated DOM
47
+ shadowRoot = this .attachShadow ({ mode: " open" })
48
+
49
+ // Initialize private state
43
50
#start = Date .now ()
44
51
45
52
connectedCallback () {
46
53
// Add the shared styles
47
- this .attachShadow ({ mode : " open " }) .adoptedStyleSheets = [styles]
54
+ this .shadowRoot .adoptedStyleSheets = [styles]
48
55
49
56
// Start the timer
50
57
this .#tick ()
@@ -55,15 +62,12 @@ class StopWatchElement extends HTMLElement {
55
62
const minutes = String (Math .floor (milliseconds / (1000 * 60 ))).padStart (2 , " 0" )
56
63
const seconds = String (Math .floor ((milliseconds / 1000 ) % 60 )).padStart (2 , " 0" )
57
64
const hundredths = String (Math .floor ((milliseconds % 1000 ) / 10 )).padStart (2 , " 0" )
58
- this .shadowRoot .innerHTML = ` ${ minutes} :${ seconds} :${ hundredths} `
65
+
66
+ this .shadowRoot .replaceChildren (` ${ minutes} :${ seconds} :${ hundredths} ` )
59
67
60
68
// Schedule next update
61
69
requestAnimationFrame (() => this .#tick ())
62
70
}
63
-
64
- static define (tag = " stop-watch" ) {
65
- customElements .define (tag, this )
66
- }
67
71
}
68
72
69
73
// Register the element with the Custom Element Registry
You can’t perform that action at this time.
0 commit comments