Skip to content

Commit

Permalink
renaming things for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
alunyov committed Nov 15, 2023
1 parent 3bcdc5a commit 45912d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@ 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;
}

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(
Expand All @@ -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) {
Expand Down

0 comments on commit 45912d2

Please sign in to comment.