Skip to content

Syntax lookup: add ref value assignment documentation #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions misc_docs/syntax/operator_ref_assignment.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
id: "ref-assignment"
keywords: ["ref", "assign"]
name: ":="
summary: "This is the `ref assignment` operator."
category: "operators"
---

This operator is syntactic sugar for assigning to the `contents` value of a `ref`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no sugar provided for ref, both ref and := are functions in pervasives module

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I was essentially quoting from pages/docs/manual/latest/mutation.mdx:

Assign a new value to `myValue` like so:

<CodeTab labels={["ReScript", "JS Output"]}>

\```res example
myValue.contents = 6
\```
\```js
myValue.contents = 6;
\```

</CodeTab>

We provide a syntax sugar for this:

<CodeTab labels={["ReScript", "JS Output"]}>

\```res example
myValue := 6
\```
\```js
myValue.contents = 6;
\```

</CodeTab>

Should I re-work this language as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments. I think it's not important how this is implemented, we should just describe what it does and how it is useful.

<CodeTab labels={["ReScript", "JS Output"]}>

```res
let total = ref(0)
total := 1
```

```js
var total = {
contents: 0
};

total.contents = 1;
```

</CodeTab>