
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
ember-stopwatch
Advanced tools
This addon provides some utilities and services that make it easier to control timing in your Ember applications.
ember install ember-stopwatch
A Stopwatch
is a utility that allows you to be notified when ticks
occur, making it easy for you
to asynchronously take action on time-based boundaries.
The Stopwatch
uses @tracked
properties so your application can react to changes in time, based
on the tick interval.
The stop
and reset
methods allow you to either stop on the next tick interval, or forcefully (
i.e. immediately).
The easiest and quickest way to start adding time utilities to your app is by using the
stopwatch-tick
modifier.
Your action handler will be passed the elapsed time and number of durations (ticks).
Note that the stopwatch will start as soon as your element is inserted and the modifier is instrumented.
<div {{stopwatch-tick 1000 (fn (mut this.finishedLoading) true)}}>
{{#if this.finishedLoading}}
Waited 1 second, loaded!
{{/if}}
</div>
You can also provide a number of ticks as an optional named parameter.
<div {{stopwatch-tick 1000 (fn (mut this.finishedLoading) true) ticks=10}}>
{{#if this.finishedLoading}}
Waited 10 seconds, loaded!
{{/if}}
</div>
There also exists an alias for stopwatch-tick
named call-after
which may be more intuitive for
your use-case.
<div {{call-after 1000 (fn (mut this.finishedLoading) true)}}>
...
</div>
This allows you to create multiple stopwatches anywhere in your application.
import Stopwatch from "ember-stopwatch/utils/stopwatch";
// ...
let stopwatch = new Stopwatch();
stopwatch.start();
stopwatch.stop();
stopwatch.reset();
stopwatch.on("tick", someHandler);
// ...
{{this.stopwatch.elapsedMillis}}
{{this.stopwatch.numTicks}}
A stopwatch
service can be used that is shared globally in your application.
export default class extends Component {
@service stopwatch;
@action
start() {
this.stopwatch.start();
}
@action
stop() {
this.stopwatch.stop();
}
}
A Timer
is a utility that extends the Stopwatch
behavior described above, except that the
use-case is to handle "countdown" eventing. This enables your application to react to a timeout
event.
Additionally, the Timer
can be paused and restarted and contains reactful state properties (
e.g. remainingMillis
and isExpired
).
import Timer from "ember-stopwatch/utils/timer";
// ...
let timer = new Timer(60000);
timer.on("expired", this, expirationHandler);
timer.start();
// ...
expirationHandler(){
console.log('Time is up!');
}
{{this.timer.remainingMillis}}
{{this.timer.isExpired}}
The clock-tick
modifier can be used to react to various time tick types, which includes second
,
minute
, hour
, and day
.
Your action handler will be passed the current time (from the clock service), when triggered.
Note that the ticks will be triggered on clock time thresholds, not elapsed time / durations (e.g. when the actual clock rolls over to a new second, minute, hour, etc.).
export default class extends Component {
@tracked time;
}
<div {{clock-tick "second" (fn (mut this.time))}}>
{{moment-format this.time}}
</div>
A Clock
is a utility that tracks time ticks for the current system time.
A Clock
triggers events on time ticks, including second
, minute
, hour
, and day
. A Clock
also provides reactful time
, date
, second
, minute
, hour
, and day
properties.
import Clock from "ember-stopwatch/utils/clock";
// ...
let clock = new Clock();
clock.on("second", myHandler.bind(this, "second"));
clock.on("minute", myHandler.bind(this, "minute"));
clock.start();
// ...
myHandler(type) {
console.log(`${type} ticked`);
}
{{this.clock.time}}
A clock
service automatically creates and starts a single instance of the Clock
utility and is a
proxy for properties and methods of a clock instance. A clock
service also has @tracked
versions
of the clock properties second
, minute
, hour
, and day
that can be used by the other
reactive getters in your application, including the @computed
macros.
export default class extends Component {
@service clock;
}
{{moment-format this.clock.time}}
export default class extends Component {
@service clock;
@computed("clock.minute")
get timeByTheMinute() {
return new Date().getTime();
}
@computed("clock.hour")
get timeByTheHour() {
return new Date().getTime();
}
@computed("clock.day")
get timeByTheDay() {
return new Date().getTime();
}
}
Refreshes every second:
{{moment-format this.clock.time}}
Refreshes every minute:
{{moment-format this.timeByTheMinute}}
Refreshes every hour:
{{moment-format this.timeByTheHour}}
Refreshes every day:
{{moment-format this.timeByTheDay}}
See the Contributing guide for details.
This project is licensed under the MIT License.
FAQs
Stopwatches, timers, clocks, oh my!
The npm package ember-stopwatch receives a total of 5 weekly downloads. As such, ember-stopwatch popularity was classified as not popular.
We found that ember-stopwatch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.