Files
react/packages/react-server/src/ReactServerHostConfigBrowser.js
Sebastian Markbåge dee03049f5 [Flight] Basic Streaming Suspense Support (#17285)
* Return whether to keep flowing in Host config

* Emit basic chunk based streaming in the Flight server

When something suspends a new chunk is created.

* Add reentrancy check

The WHATWG API is designed to be pulled recursively.

We should refactor to favor that approach.

* Basic streaming Suspense support on the client

* Add basic suspense in example

* Add comment describing the protocol that the server generates
2019-11-06 09:48:34 -08:00

42 lines
1.0 KiB
JavaScript

/**
* 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 = ReadableStreamController;
export function scheduleWork(callback: () => void) {
callback();
}
export function flushBuffered(destination: Destination) {
// WHATWG Streams do not yet have a way to flush the underlying
// transform streams. https://github.com/whatwg/streams/issues/960
}
export function beginWriting(destination: Destination) {}
export function writeChunk(
destination: Destination,
buffer: Uint8Array,
): boolean {
destination.enqueue(buffer);
return destination.desiredSize > 0;
}
export function completeWriting(destination: Destination) {}
export function close(destination: Destination) {
destination.close();
}
const textEncoder = new TextEncoder();
export function convertStringToBuffer(content: string): Uint8Array {
return textEncoder.encode(content);
}