Skip to content

feat: state-kind accessors attach eagerly at render by default - #412

Open
cpsievert wants to merge 4 commits into
mainfrom
feat/eager-state-accessors
Open

cpsievert wants to merge 4 commits into
mainfrom
feat/eager-state-accessors

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

Problem

Non-eager accessors attach on first read. If the first reader is gated — a chat handler, an LLM tool, any effect that runs late — an interaction made before that first read (a lasso, a pan) is silently lost.

Change

AccessorSpec.eager now defaults to True for kind="state" accessors (attach at render; attaching seeds the current value, so pre-first-read changes are not lost) and stays False for kind="event" accessors. eager is now Optional[bool] = None, resolved in __post_init__ — a frozen dataclass can't default one field from another, so the sentinel keeps explicit eager=False opt-outs possible.

All existing explicit eager=True declarations are on event-kind specs (rerun SELECTION, cytoscape NODE_CLICKED/EDGE_CLICKED, mols2grid clicked) and remain necessary; no eager=False existed in repo code.

For event-kind accessors whose first reader is gated, the docstring now documents the warm-up idiom: a @reactive.effect that reads the accessor once, unconditionally, at startup.

No state-replay machinery (explicitly out of scope).

Tests

  • 4 new unit tests: kind-based default resolution, eager state attach at render, lazy event attach, explicit eager=False opt-out.
  • make check: ruff + pyright (0 errors) + unit suite green (840 passed).

A state accessor's attach seeds the widget's current value, so attaching
at render (rather than on first read) means an interaction made before
the first read -- e.g. a lasso drawn before a chat handler or LLM tool
first reads the accessor -- is no longer lost. Event-kind accessors stay
lazy by default; eager=None resolves from kind in __post_init__, so both
directions remain overridable per spec. The AccessorSpec docstring now
documents the warm-up @reactive.effect read idiom for event accessors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant