File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 226
226
227
227
([ sobolevn] ( https://github.com/sobolevn ) )
228
228
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
+
229
263
### Build tool
230
264
231
265
- New projects are generated using OTP28 on GitHub Actions.
You can’t perform that action at this time.
0 commit comments