Namespaced and TypeScript Enums

Summary:
Enums are currently exposed to the JS package as constants (e.g. `import {ERRATA_NONE} from 'yoga-layout'`).

This exports enums in the form of `import {Errata} from 'yoga-layout'` then `Errata.None`.

It would be more ergonomic for these to be string union based enums instead, but right now it is a pretty thin wrapper around the native API, we need ordinal values to do things with bit masks, and folks have wanted to serialize them before.

Differential Revision: https://internalfb.com/D45570417

fbshipit-source-id: c9c40f4b4dd6cb0c46bc05e558dded39dd299cf0
This commit is contained in:
Nick Gerleman
2023-05-09 21:36:00 -07:00
committed by Facebook GitHub Bot
parent aa812d0e48
commit aeffaf93a7
7 changed files with 265 additions and 548 deletions

View File

@@ -7,21 +7,21 @@ This package provides prebuilt JavaScript bindings for the Yoga layout engine. B
The default entrypoint provides an asynchronous loader function to return a Yoga instance.
```ts
import { loadYoga, ALIGN_CENTER } from "yoga-layout";
import {loadYoga, Align} from 'yoga-layout';
const Yoga = await loadYoga();
const node = Yoga.Node.create();
node.setAlignContent(ALIGN_CENTER);
node.setAlignContent(Align.Center);
```
An alternative synchronous API is provided for compatibility, but requires using asm.js in browsers instead of WebAssembly, leading to worse performance and larger assets.
```ts
import Yoga, { ALIGN_CENTER } from "yoga-layout/sync";
import Yoga, {Align} from 'yoga-layout/sync';
const node = Yoga.Node.create();
node.setAlignContent(ALIGN_CENTER);
node.setAlignContent(Align.Center);
```
Objects created by `Yoga.<>.create()` are not automatically garbage collected and should be freed once they are no longer in use.
@@ -44,7 +44,7 @@ For better performance and smaller packages, WebAssembly is preferred to asm.js
A specific entrypoint may be specified on platforms which do not understand export conditions.
```ts
import { loadYoga } from "yoga-layout/dist/entrypoint/wasm-async";
import {loadYoga} from 'yoga-layout/dist/entrypoint/wasm-async';
```