File tree Expand file tree Collapse file tree 2 files changed +22
-13
lines changed
react-server-dom-fb/src/__tests__ Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -31,21 +31,29 @@ let Suspense;
3131let registerClientReference ;
3232
3333class Destination {
34+ #buffer = '' ;
35+ #controller = null ;
3436 constructor ( ) {
3537 const self = this ;
3638 this . stream = new ReadableStream ( {
3739 start ( controller ) {
38- self . _controller = controller ;
40+ self . #controller = controller ;
3941 } ,
4042 } ) ;
4143 }
4244 write ( chunk ) {
43- this . _controller . enqueue ( chunk ) ;
45+ this . #buffer += chunk ;
46+ }
47+ beginWriting ( ) { }
48+ completeWriting ( ) { }
49+ flushBuffered ( ) {
50+ if ( ! this . #controller) {
51+ throw new Error ( 'Expected a controller.' ) ;
52+ }
53+ this . #controller. enqueue ( this . #buffer) ;
54+ this . #buffer = '' ;
4455 }
4556 close ( ) { }
46- flush ( ) { }
47- onStart ( ) { }
48- onComplete ( ) { }
4957 onError ( ) { }
5058}
5159
Original file line number Diff line number Diff line change @@ -16,23 +16,20 @@ import type {
1616} from '../ReactServerStreamConfigFB' ;
1717
1818export interface Destination {
19+ beginWriting ( ) : void ;
1920 write ( chunk : Chunk | PrecomputedChunk | BinaryChunk ) : void ;
21+ completeWriting ( ) : void ;
22+ flushBuffered ( ) : void ;
2023 close ( ) : void ;
21- flush ( ) : void ;
22- onStart ( ) : void ;
23- onComplete ( ) : void ;
2424 onError ( error : mixed ) : void ;
2525}
2626
2727export function scheduleWork ( callback : ( ) = > void ) {
2828 callback ( ) ;
2929}
3030
31- export function flushBuffered ( destination : Destination ) {
32- destination . flush ( ) ;
33- }
3431export function beginWriting ( destination : Destination ) {
35- destination . onStart ( ) ;
32+ destination . beginWriting ( ) ;
3633}
3734
3835export function writeChunk (
@@ -51,7 +48,11 @@ export function writeChunkAndReturn(
5148}
5249
5350export function completeWriting ( destination : Destination ) {
54- destination . onComplete ( ) ;
51+ destination . completeWriting ( ) ;
52+ }
53+
54+ export function flushBuffered ( destination : Destination ) {
55+ destination . flushBuffered ( ) ;
5556}
5657
5758export function close ( destination : Destination ) {
You can’t perform that action at this time.
0 commit comments