Skip to content

Commit d495db3

Browse files
ovflowdavivkeller
andauthored
refactor: read jsx-ast's input as it comes, and add createSignal with the channel
jsx-ast's batches hold whole modules, as metadata's and section-pages' do, so it reads them with toBatches instead of regrouping them. The replay no longer waits on a signal, so createSignal comes with the channel, its only caller. Co-authored-by: Aviv Keller <me@aviv.sh> Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4ce3912 commit d495db3

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎packages/core/src/utils/misc.mjs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,29 @@ export const deepMerge = (...objects) => {
7070
return result;
7171
}, {});
7272
};
73+
74+
/**
75+
* Creates a signal: waiting on it resolves the next time it is notified.
76+
*
77+
* @returns {{ wait: () => Promise<void>, notify: () => void }}
78+
*/
79+
export const createSignal = () => {
80+
let next = Promise.withResolvers();
81+
82+
return {
83+
/**
84+
* Waits for the next notification.
85+
*
86+
* @returns {Promise<void>}
87+
*/
88+
wait: () => next.promise,
89+
90+
/**
91+
* Wakes what waits.
92+
*/
93+
notify: () => {
94+
next.resolve();
95+
next = Promise.withResolvers();
96+
},
97+
};
98+
};

‎packages/react/src/jsx-ast/__tests__/generate.test.mjs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ describe('jsx-ast generate', () => {
295295

296296
const output = generate(input(), worker);
297297

298-
// Each module's page is built once the next module arrives, and read as
299-
// `html` reads it, letting go of it once it has it. The last one read may
300-
// still be in a register: the first one must not be held.
298+
// Each module's page is built as its batch arrives, and read as `html`
299+
// reads it, letting go of it once it has it. The last one read may still
300+
// be in a register: the first one must not be held.
301301
await output.next();
302302
await output.next();
303303

‎packages/react/src/jsx-ast/generate.mjs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { isMainThread } from 'node:worker_threads';
33
import getConfig from '@doc-kit/core/utils/configuration/index.mjs';
44
import {
55
groupNodesByModule,
6-
groupWholeModules,
76
merge,
7+
toBatches,
88
} from '@doc-kit/core/utils/generators.mjs';
99
import { jsx, toJs } from 'estree-util-to-js';
1010

@@ -78,8 +78,9 @@ export async function* generate(input, worker) {
7878
async function* describe() {
7979
const heads = [];
8080

81-
// A page needs all of its module's entries
82-
for await (const entries of groupWholeModules(input)) {
81+
// A page needs all of its module's entries, which arrive together, as
82+
// `metadata` and `section-pages` give them
83+
for await (const entries of toBatches(input)) {
8384
const groupedModules = groupNodesByModule(entries);
8485
const descriptors = entries
8586
.filter(node => node.heading.depth === 1)

0 commit comments

Comments
 (0)