Repository: facebook/react
File: packages/react-noop-renderer/src/ReactNoopFlightClient.js (JavaScript)

Code before:
type Source = Array<Uint8Array>;

const decoderOptions = {stream: true};

const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
  ReactFlightClient({
    createStringDecoder() {
      return new TextDecoder();
    },
    readPartialStringChunk(decoder: TextDecoder, buffer: Uint8Array): string {
      return decoder.decode(buffer, decoderOptions);
    },
    readFinalStringChunk(decoder: TextDecoder, buffer: Uint8Array): string {
      return decoder.decode(buffer);
    },
    resolveClientReference(bundlerConfig: null, idx: string) {
      return idx;
    },
    prepareDestinationForModule(moduleLoading: null, metadata: string) {},
    preloadModule(idx: string) {},
    requireModule(idx: string) {
      return readModule(idx);
    },
    parseModel(response: Response, json) {
      const parsed = JSON.parse(json);
      return response._walkJSON(parsed, {'': parsed}, '');
    },
    bindToConsole(methodName, args, badgeName) {
      return Function.prototype.bind.apply(
        // eslint-disable-next-line react-internal/no-production-logging
        console[methodName],
        [console].concat(args),
      );
    },
    checkEvalAvailabilityOnceDev,
  });

type ReadOptions = {|
  findSourceMapURL?: FindSourceMapURLCallback,
  debugChannel?: {onMessage: (message: string) => void},
  close?: boolean,
|};

function read<T>(source: Source, options: ReadOptions): Thenable<T> {
  const response = createResponse(
    source,
    null,
    null,
    undefined,
    undefined,
    undefined,

Review comment (suggestion):
This method should be removed rather than updated. Once `_fromJSON`/`_walkJSON` is removed from `Response` in favor of a plain module-scope function, there's nothing for this to call. `ReactFlightClient.js` never imports `parseModel` from `ReactFlightClientConfig` either, and the tests that directly use this module never call it.

Code after:
type Source = Array<Uint8Array>;

const decoderOptions = {stream: true};

const {createResponse, createStreamState, processBinaryChunk, getRoot, close} =
  ReactFlightClient({
    createStringDecoder() {
      return new TextDecoder();
    },
    readPartialStringChunk(decoder: TextDecoder, buffer: Uint8Array): string {
      return decoder.decode(buffer, decoderOptions);
    },
    readFinalStringChunk(decoder: TextDecoder, buffer: Uint8Array): string {
      return decoder.decode(buffer);
    },
    resolveClientReference(bundlerConfig: null, idx: string) {
      return idx;
    },
    prepareDestinationForModule(moduleLoading: null, metadata: string) {},
    preloadModule(idx: string) {},
    requireModule(idx: string) {
      return readModule(idx);
    },
    bindToConsole(methodName, args, badgeName) {
      return Function.prototype.bind.apply(
        // eslint-disable-next-line react-internal/no-production-logging
        console[methodName],
        [console].concat(args),
      );
    },
    checkEvalAvailabilityOnceDev,
  });

type ReadOptions = {|
  findSourceMapURL?: FindSourceMapURLCallback,
  debugChannel?: {onMessage: (message: string) => void},
  close?: boolean,
|};

function read<T>(source: Source, options: ReadOptions): Thenable<T> {
  const response = createResponse(
    source,
    null,
    null,
    undefined,
    undefined,
    undefined,
    undefined,
    false,
    options !== undefined ? options.findSourceMapURL : undefined,
    true,