@markless/runtime 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -259,6 +259,7 @@ function createRuntimeGraph(input) {
259
259
  let flushing = false;
260
260
  let notifyingWrite = false;
261
261
  let activeFlush;
262
+ let flushHolds = 0;
262
263
  for (const cell of input.cells) {
263
264
  cells.set(cell.graphNodeId, cell.value);
264
265
  if (cell.readInitializer) readInitializers.set(cell.graphNodeId, cell.readInitializer);
@@ -335,9 +336,10 @@ function createRuntimeGraph(input) {
335
336
  const scheduleFlush = () => {
336
337
  if (flushScheduled || flushing) return;
337
338
  flushScheduled = true;
338
- scheduleMicrotask(() => {
339
- flush();
340
- });
339
+ scheduleMicrotask(runScheduledFlush);
340
+ };
341
+ const runScheduledFlush = () => {
342
+ if (!flushHolds) flush();
341
343
  };
342
344
  const plane = input.reconcile?.({
343
345
  cells,
@@ -386,12 +388,19 @@ function createRuntimeGraph(input) {
386
388
  plane?.recomputeSubscribed();
387
389
  const pending = dirtyPaths.splice(0);
388
390
  const ranSubscriptions = /* @__PURE__ */ new Set();
391
+ const commits = [];
389
392
  for (const subscription of subscriptions) {
390
393
  const subscriptionPath = subscription.path ?? [];
391
394
  if (!pending.some((path) => path.graphNodeId === subscription.graphNodeId && pathsIntersect(path.path, subscriptionPath)) || ranSubscriptions.has(subscription.id)) continue;
392
395
  ranSubscriptions.add(subscription.id);
393
396
  const entries = await subscription.run(readGraph(subscription.graphNodeId, subscriptionPath));
394
- appendJournalResult(journal, entries);
397
+ if (typeof entries === "function") commits.push(entries);
398
+ else appendJournalResult(journal, entries);
399
+ }
400
+ if (commits.length > 0) {
401
+ const landing = commits.map((commit) => commit());
402
+ await notifyJournalListeners();
403
+ await Promise.all(landing);
395
404
  }
396
405
  }
397
406
  } finally {
@@ -476,6 +485,12 @@ function createRuntimeGraph(input) {
476
485
  };
477
486
  },
478
487
  hasPendingFlush: () => flushScheduled || dirtyPaths.length > 0 || activeFlush !== void 0,
488
+ holdFlush() {
489
+ flushHolds++;
490
+ return () => {
491
+ if (!--flushHolds && flushScheduled) scheduleMicrotask(runScheduledFlush);
492
+ };
493
+ },
479
494
  settleWriteObservers() {
480
495
  let pending;
481
496
  for (const observer of writeObservers) {
@@ -126,11 +126,13 @@ type RuntimeGraphDelete = {
126
126
  readonly graphNodeId: string;
127
127
  readonly path: ReadonlyArray<string>;
128
128
  };
129
+ /** DOM work a subscription holds back until its whole pass has run, so it lands in one task with that pass's journal. */
130
+ type RuntimeGraphCommit = () => void | Promise<void>;
129
131
  type RuntimeGraphSubscription = {
130
132
  readonly id: string;
131
133
  readonly graphNodeId: string;
132
134
  readonly path?: ReadonlyArray<string>;
133
- readonly run: (value: unknown) => DomJournalResult | void | Promise<DomJournalResult | void>;
135
+ readonly run: (value: unknown) => DomJournalResult | RuntimeGraphCommit | void | Promise<DomJournalResult | RuntimeGraphCommit | void>;
134
136
  };
135
137
  /**
136
138
  * Told about a write the moment it lands, before the flush that write schedules.
@@ -190,6 +192,8 @@ type RuntimeGraph = {
190
192
  readonly settleWriteObservers?: () => Promise<void> | undefined;
191
193
  /** Whether a write is waiting on a flush that has not yet reached the journal. */
192
194
  readonly hasPendingFlush?: () => boolean;
195
+ /** Keeps the scheduled flush back until each returned release has run once; `flush()` itself still runs. */
196
+ readonly holdFlush?: () => () => void;
193
197
  readonly subscribeJournal: (listener: DomJournalListener) => () => void;
194
198
  readonly flush: () => Promise<void>;
195
199
  readonly takeJournal: () => DomJournalEntry[];
@@ -325,4 +329,4 @@ type DerivedReconcilePlane = {
325
329
  type DerivedReconcilePlaneFactory = (internals: DerivedReconcileInternals) => DerivedReconcilePlane;
326
330
  declare const createDerivedReconcilePlane: DerivedReconcilePlaneFactory;
327
331
  //#endregion
328
- export { RuntimeGraphUpdate as A, RuntimeGraphDelete as C, RuntimeGraphSharedPatchOperation as D, RuntimeGraphSharedPatch as E, RuntimeGraphWriteObserver as M, createRuntimeGraph as N, RuntimeGraphSharedWrite as O, RuntimeGraphComputedDependencyNode as S, RuntimeGraphRead as T, RuntimeGraphAsyncSnapshot as _, RuntimeGraphReconcileKey as a, RuntimeGraphComputed as b, createDerivedReconcilePlane as c, samePath as d, DomJournalEntry as f, RuntimeGraphAsyncComputed as g, RuntimeGraph as h, DiffDerivedValueInput as i, RuntimeGraphWrite as j, RuntimeGraphSubscription as k, diffDerivedValue as l, DomJournalResult as m, DerivedReconcilePlane as n, RuntimeGraphReconcileOptions as o, DomJournalListener as p, DerivedReconcilePlaneFactory as r, WriteTouchedRecord as s, DerivedReconcileInternals as t, isDiffableContainer as u, RuntimeGraphCall as v, RuntimeGraphInput as w, RuntimeGraphComputedDependency as x, RuntimeGraphCell as y };
332
+ export { RuntimeGraphSubscription as A, RuntimeGraphComputedDependencyNode as C, RuntimeGraphSharedPatch as D, RuntimeGraphRead as E, RuntimeGraphWrite as M, RuntimeGraphWriteObserver as N, RuntimeGraphSharedPatchOperation as O, createRuntimeGraph as P, RuntimeGraphComputedDependency as S, RuntimeGraphInput as T, RuntimeGraphAsyncSnapshot as _, RuntimeGraphReconcileKey as a, RuntimeGraphCommit as b, createDerivedReconcilePlane as c, samePath as d, DomJournalEntry as f, RuntimeGraphAsyncComputed as g, RuntimeGraph as h, DiffDerivedValueInput as i, RuntimeGraphUpdate as j, RuntimeGraphSharedWrite as k, diffDerivedValue as l, DomJournalResult as m, DerivedReconcilePlane as n, RuntimeGraphReconcileOptions as o, DomJournalListener as p, DerivedReconcilePlaneFactory as r, WriteTouchedRecord as s, DerivedReconcileInternals as t, isDiffableContainer as u, RuntimeGraphCall as v, RuntimeGraphDelete as w, RuntimeGraphComputed as x, RuntimeGraphCell as y };
@@ -1,2 +1,2 @@
1
- import { a as RuntimeGraphReconcileKey, c as createDerivedReconcilePlane, d as samePath, i as DiffDerivedValueInput, l as diffDerivedValue, n as DerivedReconcilePlane, o as RuntimeGraphReconcileOptions, r as DerivedReconcilePlaneFactory, s as WriteTouchedRecord, t as DerivedReconcileInternals, u as isDiffableContainer } from "./graph-reconcile-Cdf3iTu3.js";
1
+ import { a as RuntimeGraphReconcileKey, c as createDerivedReconcilePlane, d as samePath, i as DiffDerivedValueInput, l as diffDerivedValue, n as DerivedReconcilePlane, o as RuntimeGraphReconcileOptions, r as DerivedReconcilePlaneFactory, s as WriteTouchedRecord, t as DerivedReconcileInternals, u as isDiffableContainer } from "./graph-reconcile-lpU0ZJNo.js";
2
2
  export { DerivedReconcileInternals, DerivedReconcilePlane, DerivedReconcilePlaneFactory, DiffDerivedValueInput, RuntimeGraphReconcileKey, RuntimeGraphReconcileOptions, WriteTouchedRecord, createDerivedReconcilePlane, diffDerivedValue, isDiffableContainer, samePath };
package/dist/graph.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as RuntimeGraphUpdate, C as RuntimeGraphDelete, D as RuntimeGraphSharedPatchOperation, E as RuntimeGraphSharedPatch, M as RuntimeGraphWriteObserver, N as createRuntimeGraph, O as RuntimeGraphSharedWrite, S as RuntimeGraphComputedDependencyNode, T as RuntimeGraphRead, _ as RuntimeGraphAsyncSnapshot, a as RuntimeGraphReconcileKey, b as RuntimeGraphComputed, f as DomJournalEntry, g as RuntimeGraphAsyncComputed, h as RuntimeGraph, i as DiffDerivedValueInput, j as RuntimeGraphWrite, k as RuntimeGraphSubscription, m as DomJournalResult, n as DerivedReconcilePlane, o as RuntimeGraphReconcileOptions, p as DomJournalListener, r as DerivedReconcilePlaneFactory, s as WriteTouchedRecord, t as DerivedReconcileInternals, v as RuntimeGraphCall, w as RuntimeGraphInput, x as RuntimeGraphComputedDependency, y as RuntimeGraphCell } from "./graph-reconcile-Cdf3iTu3.js";
2
- export { type DerivedReconcileInternals, type DerivedReconcilePlane, type DerivedReconcilePlaneFactory, type DiffDerivedValueInput, DomJournalEntry, DomJournalListener, DomJournalResult, RuntimeGraph, RuntimeGraphAsyncComputed, RuntimeGraphAsyncSnapshot, RuntimeGraphCall, RuntimeGraphCell, RuntimeGraphComputed, RuntimeGraphComputedDependency, RuntimeGraphComputedDependencyNode, RuntimeGraphDelete, RuntimeGraphInput, RuntimeGraphRead, type RuntimeGraphReconcileKey, type RuntimeGraphReconcileOptions, RuntimeGraphSharedPatch, RuntimeGraphSharedPatchOperation, RuntimeGraphSharedWrite, RuntimeGraphSubscription, RuntimeGraphUpdate, RuntimeGraphWrite, RuntimeGraphWriteObserver, type WriteTouchedRecord, createRuntimeGraph };
1
+ import { A as RuntimeGraphSubscription, C as RuntimeGraphComputedDependencyNode, D as RuntimeGraphSharedPatch, E as RuntimeGraphRead, M as RuntimeGraphWrite, N as RuntimeGraphWriteObserver, O as RuntimeGraphSharedPatchOperation, P as createRuntimeGraph, S as RuntimeGraphComputedDependency, T as RuntimeGraphInput, _ as RuntimeGraphAsyncSnapshot, a as RuntimeGraphReconcileKey, b as RuntimeGraphCommit, f as DomJournalEntry, g as RuntimeGraphAsyncComputed, h as RuntimeGraph, i as DiffDerivedValueInput, j as RuntimeGraphUpdate, k as RuntimeGraphSharedWrite, m as DomJournalResult, n as DerivedReconcilePlane, o as RuntimeGraphReconcileOptions, p as DomJournalListener, r as DerivedReconcilePlaneFactory, s as WriteTouchedRecord, t as DerivedReconcileInternals, v as RuntimeGraphCall, w as RuntimeGraphDelete, x as RuntimeGraphComputed, y as RuntimeGraphCell } from "./graph-reconcile-lpU0ZJNo.js";
2
+ export { type DerivedReconcileInternals, type DerivedReconcilePlane, type DerivedReconcilePlaneFactory, type DiffDerivedValueInput, DomJournalEntry, DomJournalListener, DomJournalResult, RuntimeGraph, RuntimeGraphAsyncComputed, RuntimeGraphAsyncSnapshot, RuntimeGraphCall, RuntimeGraphCell, RuntimeGraphCommit, RuntimeGraphComputed, RuntimeGraphComputedDependency, RuntimeGraphComputedDependencyNode, RuntimeGraphDelete, RuntimeGraphInput, RuntimeGraphRead, type RuntimeGraphReconcileKey, type RuntimeGraphReconcileOptions, RuntimeGraphSharedPatch, RuntimeGraphSharedPatchOperation, RuntimeGraphSharedWrite, RuntimeGraphSubscription, RuntimeGraphUpdate, RuntimeGraphWrite, RuntimeGraphWriteObserver, type WriteTouchedRecord, createRuntimeGraph };
package/dist/graph.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createRuntimeGraph } from "./graph-rhGwAXyl.js";
1
+ import { t as createRuntimeGraph } from "./graph-B3y0SeX_.js";
2
2
  export { createRuntimeGraph };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as RuntimeGraphUpdate, C as RuntimeGraphDelete, D as RuntimeGraphSharedPatchOperation, E as RuntimeGraphSharedPatch, M as RuntimeGraphWriteObserver, N as createRuntimeGraph, O as RuntimeGraphSharedWrite, S as RuntimeGraphComputedDependencyNode, T as RuntimeGraphRead, _ as RuntimeGraphAsyncSnapshot, a as RuntimeGraphReconcileKey, b as RuntimeGraphComputed, f as DomJournalEntry, g as RuntimeGraphAsyncComputed, h as RuntimeGraph, i as DiffDerivedValueInput, j as RuntimeGraphWrite, k as RuntimeGraphSubscription, m as DomJournalResult, n as DerivedReconcilePlane, o as RuntimeGraphReconcileOptions, p as DomJournalListener, r as DerivedReconcilePlaneFactory, s as WriteTouchedRecord, t as DerivedReconcileInternals, v as RuntimeGraphCall, w as RuntimeGraphInput, x as RuntimeGraphComputedDependency, y as RuntimeGraphCell } from "./graph-reconcile-Cdf3iTu3.js";
2
- export { type DerivedReconcileInternals, type DerivedReconcilePlane, type DerivedReconcilePlaneFactory, type DiffDerivedValueInput, DomJournalEntry, DomJournalListener, DomJournalResult, RuntimeGraph, RuntimeGraphAsyncComputed, RuntimeGraphAsyncSnapshot, RuntimeGraphCall, RuntimeGraphCell, RuntimeGraphComputed, RuntimeGraphComputedDependency, RuntimeGraphComputedDependencyNode, RuntimeGraphDelete, RuntimeGraphInput, RuntimeGraphRead, type RuntimeGraphReconcileKey, type RuntimeGraphReconcileOptions, RuntimeGraphSharedPatch, RuntimeGraphSharedPatchOperation, RuntimeGraphSharedWrite, RuntimeGraphSubscription, RuntimeGraphUpdate, RuntimeGraphWrite, RuntimeGraphWriteObserver, type WriteTouchedRecord, createRuntimeGraph };
1
+ import { A as RuntimeGraphSubscription, C as RuntimeGraphComputedDependencyNode, D as RuntimeGraphSharedPatch, E as RuntimeGraphRead, M as RuntimeGraphWrite, N as RuntimeGraphWriteObserver, O as RuntimeGraphSharedPatchOperation, P as createRuntimeGraph, S as RuntimeGraphComputedDependency, T as RuntimeGraphInput, _ as RuntimeGraphAsyncSnapshot, a as RuntimeGraphReconcileKey, b as RuntimeGraphCommit, f as DomJournalEntry, g as RuntimeGraphAsyncComputed, h as RuntimeGraph, i as DiffDerivedValueInput, j as RuntimeGraphUpdate, k as RuntimeGraphSharedWrite, m as DomJournalResult, n as DerivedReconcilePlane, o as RuntimeGraphReconcileOptions, p as DomJournalListener, r as DerivedReconcilePlaneFactory, s as WriteTouchedRecord, t as DerivedReconcileInternals, v as RuntimeGraphCall, w as RuntimeGraphDelete, x as RuntimeGraphComputed, y as RuntimeGraphCell } from "./graph-reconcile-lpU0ZJNo.js";
2
+ export { type DerivedReconcileInternals, type DerivedReconcilePlane, type DerivedReconcilePlaneFactory, type DiffDerivedValueInput, DomJournalEntry, DomJournalListener, DomJournalResult, RuntimeGraph, RuntimeGraphAsyncComputed, RuntimeGraphAsyncSnapshot, RuntimeGraphCall, RuntimeGraphCell, RuntimeGraphCommit, RuntimeGraphComputed, RuntimeGraphComputedDependency, RuntimeGraphComputedDependencyNode, RuntimeGraphDelete, RuntimeGraphInput, RuntimeGraphRead, type RuntimeGraphReconcileKey, type RuntimeGraphReconcileOptions, RuntimeGraphSharedPatch, RuntimeGraphSharedPatchOperation, RuntimeGraphSharedWrite, RuntimeGraphSubscription, RuntimeGraphUpdate, RuntimeGraphWrite, RuntimeGraphWriteObserver, type WriteTouchedRecord, createRuntimeGraph };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createRuntimeGraph } from "./graph-rhGwAXyl.js";
1
+ import { t as createRuntimeGraph } from "./graph-B3y0SeX_.js";
2
2
  export { createRuntimeGraph };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markless/runtime",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Markless state graph runtime: reads, writes, computed invalidation, flush journal.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,7 +29,7 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@markless/serializer": "0.5.0"
32
+ "@markless/serializer": "0.6.0"
33
33
  },
34
34
  "files": [
35
35
  "dist"