2022-12-28 01:27:12 -08:00
|
|
|
# yoga-layout
|
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
This package provides prebuilt WebAssembly bindings for the Yoga layout engine.
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2024-03-12 16:35:42 -07:00
|
|
|
See more at https://yogalayout.dev
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
```ts
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
import {Yoga, Align} from 'yoga-layout';
|
2022-12-28 01:27:12 -08:00
|
|
|
|
|
|
|
const node = Yoga.Node.create();
|
2023-05-09 22:21:01 -07:00
|
|
|
node.setAlignContent(Align.Center);
|
2022-12-28 01:27:12 -08:00
|
|
|
```
|
|
|
|
|
|
|
|
Objects created by `Yoga.<>.create()` are not automatically garbage collected and should be freed once they are no longer in use.
|
|
|
|
|
|
|
|
```ts
|
|
|
|
// Free a config
|
|
|
|
config.free();
|
|
|
|
|
|
|
|
// Free a tree of Nodes
|
|
|
|
node.freeRecursive();
|
|
|
|
|
|
|
|
// Free a single Node
|
|
|
|
node.free();
|
|
|
|
```
|
|
|
|
|
2024-03-12 16:35:42 -07:00
|
|
|
## Requirements
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2024-03-12 16:35:42 -07:00
|
|
|
`yoga-layout` requires a toolchain that supports ES Modules and top-level await.
|