Three places your code runs
Your code runs in the JS app, crosses the boundary, and runs natively. Values are copied across; class instances, functions and promises keep what they are.
export type Point = { x: number; y: number };
export function nudge(p: Point): Point { p.x += 1; return p;}
export class Counter { count = 0; increment(): number { return ++this.count; }}import { Counter, nudge } from "./src/shapes.lucent";
const p = { x: 0, y: 0 };const q = nudge(p);p.x; // 0: p was copied inq === p; // false: q is a new object
const counter = new Counter();counter.increment();counter.count; // 1: the same native objectWhat crosses the boundary
Section titled “What crosses the boundary”| Value | Crosses as | So |
|---|---|---|
number, string, boolean | a copy | the same value on the other side |
arrays, object types, Record, Map, Set, Uint8Array, Date | a copy | changes on one side don't reach the other |
| class instances | a reference | the same object each time, with its identity |
| functions | a callback | Lucent can call JavaScript back |
| promises | a promise | await works in both directions |
| errors | an Error | with its message and code |
Copying is what makes the boundary safe: no JavaScript object is shared with native code. It is also what costs time, so large data should cross rarely.
SDK objects, such as a CLLocationManager, stay in native code. JavaScript never sees them.