From 45912d2bdb2a65da5484e3e316d0263f465cff0d Mon Sep 17 00:00:00 2001 From: Andrey Lunyov Date: Tue, 14 Nov 2023 23:24:23 -0500 Subject: [PATCH] renaming things for consistency --- .../ReactFlightDOMServerFB-test.internal.js | 18 +++++++++++++----- ...ctServerStreamConfig.dom-fb-experimental.js | 17 +++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/react-server-dom-fb/src/__tests__/ReactFlightDOMServerFB-test.internal.js b/packages/react-server-dom-fb/src/__tests__/ReactFlightDOMServerFB-test.internal.js index a7859a2204cae..3b6338741d2a5 100644 --- a/packages/react-server-dom-fb/src/__tests__/ReactFlightDOMServerFB-test.internal.js +++ b/packages/react-server-dom-fb/src/__tests__/ReactFlightDOMServerFB-test.internal.js @@ -31,21 +31,29 @@ let Suspense; let registerClientReference; class Destination { + #buffer = ''; + #controller = null; constructor() { const self = this; this.stream = new ReadableStream({ start(controller) { - self._controller = controller; + self.#controller = controller; }, }); } write(chunk) { - this._controller.enqueue(chunk); + this.#buffer += chunk; + } + beginWriting() {} + completeWriting() {} + flushBuffered() { + if (!this.#controller) { + throw new Error('Expected a controller.'); + } + this.#controller.enqueue(this.#buffer); + this.#buffer = ''; } close() {} - flush() {} - onStart() {} - onComplete() {} onError() {} } diff --git a/packages/react-server/src/forks/ReactServerStreamConfig.dom-fb-experimental.js b/packages/react-server/src/forks/ReactServerStreamConfig.dom-fb-experimental.js index d9f611a3c58d8..7ca2bd1fc9963 100644 --- a/packages/react-server/src/forks/ReactServerStreamConfig.dom-fb-experimental.js +++ b/packages/react-server/src/forks/ReactServerStreamConfig.dom-fb-experimental.js @@ -16,11 +16,11 @@ import type { } from '../ReactServerStreamConfigFB'; export interface Destination { + beginWriting(): void; write(chunk: Chunk | PrecomputedChunk | BinaryChunk): void; + completeWriting(): void; + flushBuffered(): void; close(): void; - flush(): void; - onStart(): void; - onComplete(): void; onError(error: mixed): void; } @@ -28,11 +28,8 @@ export function scheduleWork(callback: () => void) { callback(); } -export function flushBuffered(destination: Destination) { - destination.flush(); -} export function beginWriting(destination: Destination) { - destination.onStart(); + destination.beginWriting(); } export function writeChunk( @@ -51,7 +48,11 @@ export function writeChunkAndReturn( } export function completeWriting(destination: Destination) { - destination.onComplete(); + destination.completeWriting(); +} + +export function flushBuffered(destination: Destination) { + destination.flushBuffered(); } export function close(destination: Destination) {