-
Notifications
You must be signed in to change notification settings - Fork 51k
Expand file tree
/
Copy pathReactServerStreamConfigNext.js
More file actions
62 lines (50 loc) · 1.46 KB
/
ReactServerStreamConfigNext.js
File metadata and controls
62 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
export type Destination = {
write: (chunk: Uint8Array) => void,
buffer: (shouldBuffer: boolean) => void,
flush: () => void,
close: (error: mixed) => void,
schedule: (callback: () => void) => void,
ready: boolean,
};
export type PrecomputedChunk = Uint8Array;
export type Chunk = Uint8Array;
export function scheduleWork(destination: Destination, callback: () => void) {
destination.schedule(callback);
}
export function flushBuffered(destination: Destination) {
destination.flush();
}
export function beginWriting(destination: Destination) {
destination.buffer(true);
}
export function writeChunk(
destination: Destination,
chunk: PrecomputedChunk | Chunk,
): boolean {
destination.write(chunk);
return destination.ready;
}
export function completeWriting(destination: Destination) {
destination.buffer(false);
}
export function close(destination: Destination) {
destination.close();
}
const textEncoder = new TextEncoder();
export function stringToChunk(content: string): Chunk {
return textEncoder.encode(content);
}
export function stringToPrecomputedChunk(content: string): PrecomputedChunk {
return textEncoder.encode(content);
}
export function closeWithError(destination: Destination, error: mixed): void {
destination.close(error);
}