Components
← All components

Live Counter

stimeo--live-counter

A like/view counter that moves in every open tab — HTML plus one broadcast.

  • Core

The stimeo--live-counter controller binds a number (likes, views, seats left) to an Action Cable stream so it moves in every subscribed client at once. A local increment action bumps the display optimistically and performs increment on the channel; the server owns the number, persists it, and broadcasts the result. Two wire shapes are reconciled: the recommended absolute { count } (naturally idempotent — this catalog's LikesChannel demonstrates it) and the differential { delta, by }, where a by matching this client's id value is skipped as the own echo (the optimistic bump already applied it). The DOM text is the single source of truth — the initial value is server-rendered, so Turbo cache restores and Morphs need no reconciliation. The step per trigger comes from the data-stimeo--live-counter-delta-param action param (default 1). Number formatting and persistence stay out of scope (subscribe to change if you need locale formatting). Ships in the opt-in stimeo-ui/cable subpath; the core stays zero-dependency.

running

Open this page in a second tab and click Like in either: the server-owned count converges in both. Your own click bumps immediately (optimistic), the broadcast confirms it with the absolute count.

0 likes