7
7
* @flow
8
8
*/
9
9
10
+ import type { RowEncoding , JSONValue } from './ReactFlightDOMRelayProtocol' ;
11
+
10
12
import type { Request , ReactModel } from 'react-server/src/ReactFlightServer' ;
11
13
12
14
import JSResourceReference from 'JSResourceReference' ;
@@ -22,9 +24,7 @@ import type {
22
24
import { resolveModelToJSON } from 'react-server/src/ReactFlightServer' ;
23
25
24
26
import {
25
- emitModel ,
26
- emitModule ,
27
- emitError ,
27
+ emitRow ,
28
28
resolveModuleMetaData as resolveModuleMetaDataImpl ,
29
29
} from 'ReactFlightDOMRelayServerIntegration' ;
30
30
@@ -45,49 +45,22 @@ export function resolveModuleMetaData<T>(
45
45
return resolveModuleMetaDataImpl ( config , resource ) ;
46
46
}
47
47
48
- type JSONValue =
49
- | string
50
- | number
51
- | boolean
52
- | null
53
- | { + [ key : string ] : JSONValue }
54
- | Array < JSONValue > ;
55
-
56
- export type Chunk =
57
- | {
58
- type : 'json' ,
59
- id : number ,
60
- json : JSONValue ,
61
- }
62
- | {
63
- type : 'module' ,
64
- id : number ,
65
- json : ModuleMetaData ,
66
- }
67
- | {
68
- type : 'error' ,
69
- id : number ,
70
- json : {
71
- message : string ,
72
- stack : string ,
73
- ...
74
- } ,
75
- } ;
48
+ export type Chunk = RowEncoding ;
76
49
77
50
export function processErrorChunk (
78
51
request : Request ,
79
52
id : number ,
80
53
message : string ,
81
54
stack : string ,
82
55
) : Chunk {
83
- return {
84
- type : 'error ',
85
- id : id ,
86
- json : {
56
+ return [
57
+ 'E ',
58
+ id ,
59
+ {
87
60
message,
88
61
stack,
89
62
} ,
90
- } ;
63
+ ] ;
91
64
}
92
65
93
66
function convertModelToJSON (
@@ -126,11 +99,7 @@ export function processModelChunk(
126
99
model : ReactModel ,
127
100
) : Chunk {
128
101
const json = convertModelToJSON ( request , { } , '' , model ) ;
129
- return {
130
- type : 'json' ,
131
- id : id ,
132
- json : json ,
133
- } ;
102
+ return [ 'J' , id , json ] ;
134
103
}
135
104
136
105
export function processModuleChunk (
@@ -139,11 +108,7 @@ export function processModuleChunk(
139
108
moduleMetaData : ModuleMetaData ,
140
109
) : Chunk {
141
110
// The moduleMetaData is already a JSON serializable value.
142
- return {
143
- type : 'module' ,
144
- id : id ,
145
- json : moduleMetaData ,
146
- } ;
111
+ return [ 'M' , id , moduleMetaData ] ;
147
112
}
148
113
149
114
export function scheduleWork ( callback : ( ) = > void ) {
@@ -155,13 +120,7 @@ export function flushBuffered(destination: Destination) {}
155
120
export function beginWriting ( destination : Destination ) { }
156
121
157
122
export function writeChunk ( destination : Destination , chunk : Chunk ) : boolean {
158
- if ( chunk . type === 'json' ) {
159
- emitModel ( destination , chunk . id , chunk . json ) ;
160
- } else if ( chunk . type === 'module' ) {
161
- emitModule ( destination , chunk . id , chunk . json ) ;
162
- } else {
163
- emitError ( destination , chunk . id , chunk . json . message , chunk . json . stack ) ;
164
- }
123
+ emitRow ( destination , chunk ) ;
165
124
return true ;
166
125
}
167
126
0 commit comments