-
@property -
shouldRun
:- This is a public reactive property that can be passed in as an attribute from outside the component (e.g.,
<my-timer should-run></my-timer>
). - When it toggles, based on whether it's
true
orfalse
, it controls whether the timer increments.
- This is a public reactive property that can be passed in as an attribute from outside the component (e.g.,
-
@state -
_count
:- This is an internal reactive state that holds the number of intervals passed (the count). It is not exposed outside the component and is intended for internal component reactivity.
constructor
:- Called first, used to bind functions or initialize non-reactive properties.
connectedCallback
:- Runs when the component is added to the DOM. Used here to start the interval based on an initial value of
shouldRun
.
- Runs when the component is added to the DOM. Used here to start the interval based on an initial value of
disconnectedCallback
:- Runs when the component is removed from the DOM. Used to clean up by clearing the interval.
firstUpdated
:- Runs after the first render. You can do any additional logic after the initial DOM structure is created.
willUpdate
:- Runs before each reactive update. Logs the changes for demonstration purposes.
updated
:- Runs after properties or state have changed and the component re-renders. Used here to handle logic when
shouldRun
changes.
- Runs after properties or state have changed and the component re-renders. Used here to handle logic when
- When
<my-timer>
gets the propertyshould-run
, it starts incrementing the_count
. - When
should-run
is omitted, the interval stops, and the count freezes.