From 2eb2f1a4176c5322470b90c6fd9c81694b376199 Mon Sep 17 00:00:00 2001 From: 43081j <43081j@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:40:12 +0100 Subject: [PATCH] chore: rename buffered renderer properties to remove prefix Removes the `__` prefix of the private properties to match the conventions used elsewhere in the repo. --- .../astro/src/runtime/server/render/util.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/astro/src/runtime/server/render/util.ts b/packages/astro/src/runtime/server/render/util.ts index 4afa7c75ff6e..afece3f7b841 100644 --- a/packages/astro/src/runtime/server/render/util.ts +++ b/packages/astro/src/runtime/server/render/util.ts @@ -150,29 +150,34 @@ export function renderElement( } const noop = () => {}; + +/** + * Renders into a buffer until `renderToFinalDestination` is called (which + * flushes the buffer) + */ class BufferedRenderer implements RenderDestination { - private __chunks: RenderDestinationChunk[] = []; - private __renderPromise: Promise | void; - private __destination?: RenderDestination; + private chunks: RenderDestinationChunk[] = []; + private renderPromise: Promise | void; + private destination?: RenderDestination; public constructor(bufferRenderFunction: RenderFunction) { - this.__renderPromise = bufferRenderFunction(this); + this.renderPromise = bufferRenderFunction(this); // Catch here in case it throws before `renderToFinalDestination` is called, // to prevent an unhandled rejection. - Promise.resolve(this.__renderPromise).catch(noop); + Promise.resolve(this.renderPromise).catch(noop); } public write(chunk: RenderDestinationChunk): void { - if (this.__destination) { - this.__destination.write(chunk); + if (this.destination) { + this.destination.write(chunk); } else { - this.__chunks.push(chunk); + this.chunks.push(chunk); } } public async renderToFinalDestination(destination: RenderDestination) { // Write the buffered chunks to the real destination - for (const chunk of this.__chunks) { + for (const chunk of this.chunks) { destination.write(chunk); } @@ -182,10 +187,10 @@ class BufferedRenderer implements RenderDestination { // (Unsure how this affects on limited memory machines) // Re-assign the real destination so `instance.render` will continue and write to the new destination - this.__destination = destination; + this.destination = destination; // Wait for render to finish entirely - await this.__renderPromise; + await this.renderPromise; } }