Opening the connection performs a synchronous handshake before returning.
$open_doc() then performs a synchronous initial sync, so the returned
handle's $doc has meaningful content immediately. After that, incoming
changes are received asynchronously via a self-chaining promise loop, and
local changes are flushed periodically via a later::later() timer.
Neither close() flushes pending local changes. Call $push() first if you
have unsynced edits — otherwise any changes made since the last
sync-interval tick may be lost.
Live editing. A handle's $edit() opens its text object in a live
CodeMirror editor (a React frontend rendered with shinyreact) that syncs
both ways: as you type, the minimal
diff is written to the live document and pushed (debounced); when the text
changes remotely, the editor updates to the merged result. There is no
Save button — every edit is applied live. It syncs whole-text snapshots,
not granular operations, so a remote edit arriving in the brief window
between a keystroke and its debounced push can be overwritten by that push;
a smaller debounce narrows the window. The original's trailing-newline
state is preserved.