jazz icon indicating copy to clipboard operation
jazz copied to clipboard

RFC: write an high-level API for trackDirtyCoValues

Open gdorsi opened this issue 4 months ago • 1 comments

When writing server code without using the Jazz HTTP wrapper, one of the pain points is to use waitForSync

We could give a better experience writing an higher level API to do this

const worker = await getJazzWorker();

const node = worker._raw.core.node;
const tracking = node.syncManager.trackDirtyCoValues();

// [...] business logic

// For each CoValue changed during this invocation, ensure it has been synced.
await Promise.all(
  Array.from(tracking.done(), (id) => node.syncManager.waitForSync(id)),
);

Proposal:

const changes = Account.trackChangedCoValues(worker);

// [...] business logic

await changes.stopTracking().waitForSync();

gdorsi avatar Aug 25 '25 08:08 gdorsi

can we not introduce async functions that sync covalues immediately on update/creation and then resolve the promise? Like any other DB? feels more natural to me

tobiaslins avatar Aug 25 '25 22:08 tobiaslins