Skip to content

Commit 2654a2e

Browse files
GearsDatapackslpil
authored andcommitted
Changelog
1 parent 028b30a commit 2654a2e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,40 @@
226226

227227
([sobolevn](https://github.com/sobolevn))
228228

229+
- Generated code for the JavaScript target now includes a public API which can
230+
be used for FFI interacting with Gleam custom types. For example, if you have
231+
this Gleam code:
232+
233+
```gleam
234+
pub type Person {
235+
Teacher(name: String, subject: String)
236+
Student(name: String, age: Int)
237+
}
238+
```
239+
240+
You can use the new API to use the `Person` type in FFI code:
241+
242+
```javascript
243+
import * from "./person.mjs";
244+
245+
// Constructing custom types
246+
let teacher = Person$Teacher("Joe Armstrong", "Computer Science");
247+
let student = Person$Student("Louis Pilfold", 17);
248+
249+
let randomPerson = Math.random() > 0.5 ? teacher : student;
250+
251+
// Checking variants
252+
let randomIsTeacher = Person$isTeacher(randomPerson);
253+
254+
// Getting fields
255+
let studentAge = Person$Student$age(student);
256+
257+
// The `name` field is shared so can be accessed from either variant
258+
let personNAme = Person$name(randomPerson);
259+
```
260+
261+
([Surya Rose](https://github.com/GearsDatapacks))
262+
229263
### Build tool
230264

231265
- New projects are generated using OTP28 on GitHub Actions.

0 commit comments

Comments
 (0)