LuxelEspañol

Luxel v0.1 · Guide

Polling

Some views show data that changes on the server while the page is open: a dashboard, a queue, a status board. Luxel refreshes them by polling: the page asks the server, at a fixed interval, whether anything changed. There is no push (no SSE, no WebSocket).

Declare the refresh

In the view, one hidden action marked poll:

‹Action id="refresh" event="dashboard.refresh" poll> Refresh ‹/Action>

In luxel.config.ts, the interval:

views: { dashboard: { loginView: 'login', pollMs: 5000 }, },

In the contract, the event, as a read:

events: { 'dashboard.refresh': allow(['customer'], { effect: 'read' }), },

Rules the compiler enforces:

  • pollMs is an integer from 1000 to 600000 (LUXEL-E011 otherwise).
  • An ‹Action poll> needs views.‹id>.pollMs (LUXEL-E011).
  • A polling action has no status and is not part of a form.
  • At most one polling action per view.

The compiler renders it as a hidden button. The poll runtime module (about 100 bytes) presses it every pollMs. The module holds no state, reads no data and computes nothing: it only clicks. The core sends the event like any other, with the page's version, view token and CSRF token.

The server answers only what is newer

Every page holds the version of what it shows. The version comes from your defineLoad:

export const dashboardLoad = defineLoad(views.dashboard, async (ctx) => { const d = await ledgerOps.dashboard(ctx.tx as Db, ctx.session.userId as string); return ctx.snapshot(d.version, { 'dashboard.income': d.kpis.incomeCents, 'dashboard.spend': d.kpis.spendCents, 'dashboard.recent': recentValue(d), }); });

ctx.snapshot(version, values) returns the state together with the version it was read at, from one read. A view's version is derived from the resources it shows (a version column per row, or a shared sequence), never from a counter per view and user.

On each poll the handler gets that version as ctx.seen. It reads again, compares, and returns only the paths whose data is newer, plus the new version:

export const dashboardRefresh = defineEvent(events.dashboardRefresh, async (_input, ctx) => { const d = await ledgerOps.dashboard(ctx.tx as Db, ctx.session.userId as string, { seen: ctx.seen }); let changes = ctx.version(d.version); if (d.kpis.incomeVersion > ctx.seen) changes = changes.set('dashboard.income', d.kpis.incomeCents); if (d.kpis.spendVersion > ctx.seen) changes = changes.set('dashboard.spend', d.kpis.spendCents); if (d.recent.version > ctx.seen) { changes = changes.sync('dashboard.recent', d.recent.before, d.recent.rows.map(versioned), ctx.seen); } return changes; });

(ledgerOps, recentValue, versioned and Db are the app's own; the full version is in examples/03-luxel/server/events.ts.)

  • When nothing changed, the answer carries no change: only the version. The page stays as it is.
  • ctx.version(v) sets the version the page holds after this answer. Without it, a read keeps the version the page sent.
  • For a list that can lose or change rows, ctx.sync brings it from what the page showed at seen to what it is now (see Collections).

The framework sends what your handler returns. Deciding what is newer is the handler's job, from the versions it reads.

What it costs

  • A request per interval, per open page, whether or not anything changed. In the project's measurements an empty answer cost about 1 KB on HTTP/1.1 and about 340 bytes behind HTTP/2.
  • Latency up to one interval. A change waits until the next poll.
  • Server work per poll: one read per open page per interval. Size pollMs for the number of pages you expect to be open.
  • Background tabs keep polling. The module uses a timer and does not pause on hidden tabs (browsers may throttle background timers).
  • A press while another event is in flight is dropped, like a double click; the next interval tries again.

When something did change, only the changed values travel. In the project's dashboard measurement this cost fewer bytes than the baselines' ETag-based refreshes.

No push

Luxel has no server push. Operations are HTTP request and response; there is no persistent connection to keep. If a view needs changes faster than a poll can give at a cost you accept, Luxel does not cover it today.

Edit this page on GitHub

This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app.

Measured when the site is built: the runtime files this page loads, compressed as they are sent.

Made by IntiOps. Luxel 0.1.0-beta.1 is a beta: no external security review yet.