Skip to content

Commit 0998a56

Browse files
author
rob
committed
chore: address PR feedback
1 parent 7b05602 commit 0998a56

File tree

2 files changed

+45
-26
lines changed

2 files changed

+45
-26
lines changed

misc_docs/syntax/operator_ref_assignment.mdx

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
id: "ref-value-assignment"
3+
keywords: ["ref", "assign"]
4+
name: ":="
5+
summary: "This is the `ref value assignment` operator."
6+
category: "operators"
7+
---
8+
9+
This operator assigns a new value to a `ref`.
10+
11+
<CodeTab labels={["ReScript", "JS Output"]}>
12+
13+
```res
14+
let total = ref(0)
15+
total := 1
16+
```
17+
18+
```js
19+
var total = {
20+
contents: 0
21+
};
22+
23+
total.contents = 1;
24+
```
25+
26+
</CodeTab>
27+
28+
A `ref` is a builtin record type with a `mutable contents` field. Therefore the `:=` operator is just a shorthand version for the following code:
29+
30+
<CodeTab labels={["ReScript", "JS Output"]}>
31+
32+
```res
33+
let total = ref(0)
34+
total.contents = 1
35+
```
36+
37+
```js
38+
var total = {
39+
contents: 0
40+
};
41+
42+
total.contents = 1;
43+
```
44+
45+
</CodeTab>

0 commit comments

Comments
 (0)