File tree 2 files changed +22
-13
lines changed
react-server-dom-fb/src/__tests__
2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -31,21 +31,29 @@ let Suspense;
31
31
let registerClientReference ;
32
32
33
33
class Destination {
34
+ #buffer = '' ;
35
+ #controller = null ;
34
36
constructor ( ) {
35
37
const self = this ;
36
38
this . stream = new ReadableStream ( {
37
39
start ( controller ) {
38
- self . _controller = controller ;
40
+ self . #controller = controller ;
39
41
} ,
40
42
} ) ;
41
43
}
42
44
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 = '' ;
44
55
}
45
56
close ( ) { }
46
- flush ( ) { }
47
- onStart ( ) { }
48
- onComplete ( ) { }
49
57
onError ( ) { }
50
58
}
51
59
Original file line number Diff line number Diff line change @@ -16,23 +16,20 @@ import type {
16
16
} from '../ReactServerStreamConfigFB' ;
17
17
18
18
export interface Destination {
19
+ beginWriting ( ) : void ;
19
20
write ( chunk : Chunk | PrecomputedChunk | BinaryChunk ) : void ;
21
+ completeWriting ( ) : void ;
22
+ flushBuffered ( ) : void ;
20
23
close ( ) : void ;
21
- flush ( ) : void ;
22
- onStart ( ) : void ;
23
- onComplete ( ) : void ;
24
24
onError ( error : mixed ) : void ;
25
25
}
26
26
27
27
export function scheduleWork ( callback : ( ) = > void ) {
28
28
callback ( ) ;
29
29
}
30
30
31
- export function flushBuffered ( destination : Destination ) {
32
- destination . flush ( ) ;
33
- }
34
31
export function beginWriting ( destination : Destination ) {
35
- destination . onStart ( ) ;
32
+ destination . beginWriting ( ) ;
36
33
}
37
34
38
35
export function writeChunk (
@@ -51,7 +48,11 @@ export function writeChunkAndReturn(
51
48
}
52
49
53
50
export function completeWriting ( destination : Destination ) {
54
- destination . onComplete ( ) ;
51
+ destination . completeWriting ( ) ;
52
+ }
53
+
54
+ export function flushBuffered ( destination : Destination ) {
55
+ destination . flushBuffered ( ) ;
55
56
}
56
57
57
58
export function close ( destination : Destination ) {
You can’t perform that action at this time.
0 commit comments