You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _blogposts/2020-08-28-new-rescript-logo.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ description: |
7
7
Today, our resident designer Bettina is unveiling to us the fresh new ReScript branding we've been long waiting for. We hope you're as excited about the result as us!
Copy file name to clipboardExpand all lines: _blogposts/2023-04-17-improving-interop.mdx
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ This is represented as:
31
31
var user = {
32
32
TAG:/* User */0,
33
33
name:"Hello",
34
-
}
34
+
};
35
35
```
36
36
37
37
However, this has been problematic when binding to external data because there has been no way to customize the discriminator (the `TAG` property) or how its value is represented for each variant case (`0` representing `User` here). This means that unless your external data is modeled the exact same way as above, which is unlikely, you'd be forced to convert to the structure ReScript expects at runtime.
@@ -42,7 +42,7 @@ To illustrate this, let's imagine we're binding to an external union that looks
42
42
typeLoadingState=
43
43
| { state:"loading"; ready:boolean }
44
44
| { state:"error"; message:string }
45
-
| { state:"done"; data:Data }
45
+
| { state:"done"; data:Data };
46
46
```
47
47
48
48
Currently, there's no good way to use a ReScript variant to represent this type without resorting to manual and error-prone runtime conversion. However, with the new functionality, binding to the above with no additional runtime cost is easy:
@@ -60,7 +60,7 @@ This will compile to:
60
60
var state = {
61
61
state:"error",
62
62
message:"Something went wrong!",
63
-
}
63
+
};
64
64
```
65
65
66
66
Let's break down what we've done to make this work:
@@ -91,7 +91,7 @@ enum Direction {
91
91
Right="RIGHT",
92
92
}
93
93
94
-
exportconst myDirection =Direction.Up
94
+
exportconst myDirection =Direction.Up;
95
95
```
96
96
97
97
Previously, you'd be forced to use a polymorphic variant for this if you wanted clean, zero-cost interop:
@@ -138,7 +138,7 @@ The same logic is easily applied to string literals from TypeScript, only here t
138
138
139
139
```typescript
140
140
// direction.ts
141
-
typedirection="UP"|"DOWN"|"LEFT"|"RIGHT"
141
+
typedirection="UP"|"DOWN"|"LEFT"|"RIGHT";
142
142
```
143
143
144
144
There's no way to attach documentation strings to string literals in TypeScript, and you only get the actual value to interact with.
@@ -162,7 +162,7 @@ Here, each value will be _unboxed_ at runtime. That means that the variant paylo
162
162
It, therefore, compiles to this JS:
163
163
164
164
```javascript
165
-
var myArray = ["hello", true, false, 13.37]
165
+
var myArray = ["hello", true, false, 13.37];
166
166
```
167
167
168
168
This was previously possible to do, leveraging a few tricks, when you didn't need to potentially read the values from the array again in ReScript. But, if you wanted to read back the values, you'd have to do a number of manual steps.
0 commit comments