On this page:
get  Exports Guarantees
5.6.1 JavaScript

The Reach JavaScript backend produces a compilation output named "input.export.mjs" which exports an asynchronous function for each participant. This will normally be imported by writing:

import * as backend from './build/index.main.mjs';

Each function accepts two arguments: ctc and interact. These functions should be called by the frontend. For example, if a Reach program contains a participant named 'A' in the argument to Reach.App, then the JavaScript backend will include a function named A.

The ctc argument is the result of a call to the functions acc.deploy or acc.attach provided by the JavaScript frontend support library.

The interact argument is an object matching the participant interact interface for the corresponding participant. The types of values this object contains must match those specified on this list.

The JavaScript backend also provides an export named _version, which is a string representation of the Reach version used to compile the program. For example, the version of Reach used to produce this documentation would contain the string '0.1.2'.

The backend also provides a function, getExports, which exposes the exports of a Reach program. This function receives the standard library as an argument and returns an object with all the exports. For example, if a Reach program exported a variable x, i.e. export const x = 5, the frontend could access the value in the following manner:

const stdlib = await loadStdlib();
backend.getExports(stdlib).x; // 5

Finally, the backend will provide an export named _Connectors, which is an opaque object representing the connectors this app was compiled to. Guarantees

This backend does not guarantee that values in a positive position in a participant interact interface, that are later passed to a negative position in a participant interact interface, will be identical, in the sense of JavaScript’s === operator, to the original value. In other words, this backend does not ensure that Reach programs are parametric over JavaScript values that they interact with.

Positive and negative are best understood by example with a function type: a positive position is supplied by the function, such as the result; while a negative position is supplied by the caller, such as the arguments. These notions generalize, however, to higher (and lower) order contexts. In the case of Reach, this means that non-function values in a participant interact interface are positive.

For example, if the Reach program,

 [Participant("A", { get: Bytes(32), give: Fun([Bytes(32)], Bool) })],
 (A) => {
  A.only(() => {
   const x = interact.give(interact.get); });
  commit(); }); 

is given the interact object,

const x = "A string";
{ get: x,
  give: (str) => x === str } 

then it is not guaranteed that A will publish true, because the str given to give may not be identical to x. (However, they are bytesEq.)