Skip to content

Production Use Cases & Architectural Patterns ​

@tempo-kit/plugin-signals brings event-driven TC39 Signals (Signify) to UI components, dashboards, and scheduling workflows without adding background polling overhead to Core tempo-kit.


1. Battery-Friendly Activity Feeds (toRelativeSignal) ​

Chat messages, deployment logs, and audit trails often render hundreds of relative timestamps ("just now", "5 minutes ago", "2 hours ago"). Polling every row once per second wastes CPU and battery on stale entries.

toRelativeSignal schedules a single one-shot setTimeout at the exact next unit-bucket boundary (second → minute → hour → day → month → year), so a 3-hour-old item sleeps for up to an hour between updates:

typescript
import { toRelativeSignal } from '@tempo-kit/plugin-signals';

function mountTimestampBadge(createdAtIso: string) {
  const label = toRelativeSignal(createdAtIso, { style: 'narrow' });

  // Read current value synchronously in your UI render / effect
  console.log(label.get());

  // Call label.dispose() when the row/component unmounts
  return () => label.dispose();
}

2. Live Meeting & Booking Progress Bars (intervalSignal) ​

Calendar cards, maintenance windows, and SLA timers need to transition cleanly through upcoming (isFuture), active (isCurrent), and completed (isPast) states while tracking normalized completion progress (∈[0,1]).

typescript
import { Tempo } from 'tempo-kit';
import { intervalSignal } from '@tempo-kit/plugin-signals';

const start = new Tempo().add({ minutes: 10 });
const end = start.add({ minutes: 50 });
const meetingWindow = new Tempo.Interval(start, end);

using state = intervalSignal(meetingWindow, { progressInterval: 1_000 });

console.log({
  isFuture: state.isFuture.get(),
  isCurrent: state.isCurrent.get(),
  isPast: state.isPast.get(),
  progress: state.progress.get(),
});
  • While isFuture is true, no progress ticker runs—only a single boundary timer waits until start.
  • Once start is reached, isCurrent flips to true and optional progressInterval updates begin.
  • Once end is reached, isPast becomes true, progress locks at 1, and all timers stop automatically.

3. App-Wide Locale & Time Zone Switching (localeSignal / timeZoneSignal) ​

When a user switches language or time zone in application settings via Tempo.init(), localeSignal and timeZoneSignal propagate the change to reactive views automatically via tempo-kit/plugin/sdk's onConfigChange hook:

typescript
import { Tempo } from 'tempo-kit';
import { localeSignal, timeZoneSignal, disposeConfigSignals } from '@tempo-kit/plugin-signals';

const locale = localeSignal();
const timeZone = timeZoneSignal();

console.log(locale.get(), timeZone.get());

// Updating global Tempo configuration notifies active config signals
Tempo.init({ locale: 'fr-FR', timeZone: 'Europe/Paris' });
console.log(locale.get(), timeZone.get()); // "fr-FR", "Europe/Paris"

// Detach global config observer on app teardown
disposeConfigSignals();

4. Travel & Live OS Time-Zone Sync (watchSystemConfig) ​

For web apps, PWAs, or desktop apps where a user's device may cross time zones or change OS region settings while the app stays open, watchSystemConfig() (or Tempo.signals.watchSystem()) bridges host Intl changes into Tempo.init() without background polling:

typescript
import { Tempo } from 'tempo-kit';
import { SignalsPlugin, watchSystemConfig } from '@tempo-kit/plugin-signals';

Tempo.use(SignalsPlugin);
Tempo.init({ locale: 'en-AU', calendar: 'iso8601' });

// Keep the pinned app locale while syncing OS time-zone changes on focus/visibility
using watcher = watchSystemConfig({ locale: false });

// Hybrid/desktop apps (e.g. Electron) can also attach native wake events:
// using desktopWatcher = Tempo.signals.watchSystem({
//   subscribe: (trigger) => {
//     powerMonitor.on('resume', trigger);
//     return () => powerMonitor.off('resume', trigger);
//   },
// });

Released under the MIT License.