From 9e1217e82890d03710d215e11a854670a74a3d0f Mon Sep 17 00:00:00 2001 From: Josh Derocher-Vlk Date: Mon, 5 May 2025 09:13:23 +0200 Subject: [PATCH] remove newcomer examples in v12 --- data/sidebar_manual_v1200.json | 1 - .../docs/manual/v12.0.0/newcomer-examples.mdx | 134 ------------------ 2 files changed, 135 deletions(-) delete mode 100644 pages/docs/manual/v12.0.0/newcomer-examples.mdx diff --git a/data/sidebar_manual_v1200.json b/data/sidebar_manual_v1200.json index ce301d35f..36c231ccb 100644 --- a/data/sidebar_manual_v1200.json +++ b/data/sidebar_manual_v1200.json @@ -9,7 +9,6 @@ "Guides": [ "converting-from-js", "editor-code-analysis", - "newcomer-examples", "project-structure" ], "JavaScript Interop": [ diff --git a/pages/docs/manual/v12.0.0/newcomer-examples.mdx b/pages/docs/manual/v12.0.0/newcomer-examples.mdx deleted file mode 100644 index 7ec9d05aa..000000000 --- a/pages/docs/manual/v12.0.0/newcomer-examples.mdx +++ /dev/null @@ -1,134 +0,0 @@ ---- -title: "Newcomer Examples" -description: "Quick examples for users new to ReScript" -canonical: "/docs/manual/v12.0.0/newcomer-examples" ---- - -# Newcomer Examples - - - -An example is worth a thousand words. - -This section is dedicated to newcomers trying to figure out general idioms & conventions. If you're a beginner who's got a good idea for an example, please suggest an edit! - -## Use the [`option` type](null-undefined-option.md) - - - -```res example -let possiblyNullValue1 = None -let possiblyNullValue2 = Some("Hello") - -switch possiblyNullValue2 { -| None => Console.log("Nothing to see here.") -| Some(message) => Console.log(message) -} -``` -```js -var possiblyNullValue1; -var possiblyNullValue2 = "Hello"; - -if (possiblyNullValue2 !== undefined) { - console.log(possiblyNullValue2); -} else { - console.log("Nothing to see here."); -} - -``` - - - -## Create a Parametrized Type - - - -```res example -type universityStudent = {gpa: float} - -type response<'studentType> = { - status: int, - student: 'studentType, -} -``` -```js -// Empty output -``` - - - -## Creating a JS Object - - - -```res example -let student1 = { - "name": "John", - "age": 30, -} -``` -```js -var student1 = { - name: "John", - age: 30, -}; -``` - - - -Or using [record](record.md): - - - -```res example -type payload = { - name: string, - age: int, -} - -let student1 = { - name: "John", - age: 30, -} -``` -```js -var student1 = { - name: "John", - age: 30, -}; -``` - - - -## Modeling a JS Module with Default Export - -See [here](import-from-export-to-js.md#import-a-javascript-module-itself-es6-module-format). - -## Checking for JS nullable types using the `option` type - -For a function whose argument is passed a JavaScript value that's potentially `null` or `undefined`, it's idiomatic to convert it to an `option`. The conversion is done through the helper functions in ReScript's [`Nullable`](api/core/nullable#value-toOption) module. In this case, `toOption`: - - - -```res example -let greetByName = (possiblyNullName) => { - let optionName = Nullable.toOption(possiblyNullName) - switch optionName { - | None => "Hi" - | Some(name) => "Hello " ++ name - } -} -``` -```js -function greetByName(possiblyNullName) { - if (possiblyNullName == null) { - return "Hi"; - } else { - return "Hello " + possiblyNullName; - } -} -``` - - - -This check compiles to `possiblyNullName == null` in JS, so checks for the presence of `null` or `undefined`.