Skip to content

Commit 6d659e5

Browse files
committed
requested changes
1 parent 6552fbc commit 6d659e5

File tree

6 files changed

+43
-50
lines changed

6 files changed

+43
-50
lines changed

pages/docs/react/latest/forwarding-refs.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ let make = () => {
5959
let input = React.useRef(Nullable.null)
6060
6161
let focusInput = () =>
62-
input.current
63-
->Nullable.toOption
64-
->Option.forEach(input => input->focus)
62+
input.current->Nullable.forEach(input => input->focus)
6563
6664
let onClick = _ => focusInput()
6765

pages/docs/react/latest/hooks-ref.mdx

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ let make = () => {
5959
let inputEl = React.useRef(Nullable.null)
6060
6161
let onClick = _ => {
62-
inputEl.current
63-
->Nullable.toOption
64-
->Option.forEach(input => input->focus)
62+
inputEl.current->Nullable.forEach(input => input->focus)
6563
}
6664
6765
<>
@@ -75,13 +73,12 @@ let make = () => {
7573
function TextInputWithFocusButton(Props) {
7674
var inputEl = React.useRef(null);
7775
var onClick = function (param) {
78-
return Belt_Option.forEach(Caml_option.nullable_to_opt(inputEl.current), (function (input) {
79-
input.focus();
80-
81-
}));
76+
Core__Nullable.forEach(inputEl.current, (function (input) {
77+
input.focus();
78+
}));
8279
};
83-
return React.createElement(React.Fragment, undefined, React.createElement("input", {
84-
ref: inputEl,
80+
return React.createElement(React.Fragment, {}, React.createElement("input", {
81+
ref: Caml_option.some(inputEl),
8582
type: "text"
8683
}), React.createElement("button", {
8784
onClick: onClick
@@ -110,9 +107,7 @@ let make = () => {
110107
}
111108
112109
let focusTextInput = _ => {
113-
textInput.current
114-
->Nullable.toOption
115-
->Option.forEach(input => input->focus)
110+
textInput.current->Nullable.forEach(input => input->focus)
116111
}
117112
118113
<div>
@@ -129,16 +124,14 @@ function CustomTextInput(Props) {
129124
var textInput = React.useRef(null);
130125
var setTextInputRef = function (element) {
131126
textInput.current = element;
132-
133127
};
134128
var focusTextInput = function (param) {
135-
return Belt_Option.forEach(Caml_option.nullable_to_opt(textInput.current), (function (input) {
136-
input.focus();
137-
138-
}));
129+
Core__Nullable.forEach(textInput.current, (function (input) {
130+
input.focus();
131+
}));
139132
};
140133
return React.createElement("div", undefined, React.createElement("input", {
141-
ref: setTextInputRef,
134+
ref: Caml_option.some(setTextInputRef),
142135
type: "text"
143136
}), React.createElement("input", {
144137
type: "button",

pages/docs/react/latest/refs-and-the-dom.mdx

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ let make = () => {
8686
let textInput = React.useRef(Nullable.null)
8787
8888
let focusInput = () =>
89-
switch textInput.current->Nullable.toOption {
90-
| Some(dom) => dom->focus
91-
| None => ()
89+
switch textInput.current {
90+
| Value(dom) => dom->focus
91+
| Null | Undefined => ()
9292
}
9393
9494
let onClick = _ => focusInput()
@@ -103,22 +103,29 @@ let make = () => {
103103
```js
104104
function CustomTextInput(Props) {
105105
var textInput = React.useRef(null);
106-
var onClick = function (param) {
106+
var focusInput = function () {
107107
var dom = textInput.current;
108-
if (!(dom == null)) {
109-
dom.focus();
108+
if (dom === null || dom === undefined) {
110109
return ;
111110
}
112-
111+
dom.focus();
113112
};
114-
return React.createElement("div", undefined, React.createElement("input", {
115-
ref: textInput,
116-
type: "text"
117-
}), React.createElement("input", {
118-
type: "button",
119-
value: "Focus the text input",
120-
onClick: onClick
121-
}));
113+
var onClick = function (param) {
114+
focusInput();
115+
};
116+
return JsxRuntime.jsxs("div", {
117+
children: [
118+
JsxRuntime.jsx("input", {
119+
ref: Caml_option.some(textInput),
120+
type: "text"
121+
}),
122+
JsxRuntime.jsx("input", {
123+
type: "button",
124+
value: "Focus the text input",
125+
onClick: onClick
126+
})
127+
]
128+
});
122129
}
123130
```
124131

@@ -199,9 +206,7 @@ let make = () => {
199206
}
200207
201208
let focusTextInput = _ => {
202-
textInput.current
203-
->Nullable.toOption
204-
->Option.forEach(input => input->focus)
209+
textInput.current->Nullable.forEach(input => input->focus)
205210
}
206211
207212
<div>
@@ -218,16 +223,14 @@ function CustomTextInput(Props) {
218223
var textInput = React.useRef(null);
219224
var setTextInputRef = function (element) {
220225
textInput.current = element;
221-
222226
};
223227
var focusTextInput = function (param) {
224-
return Belt_Option.forEach(Caml_option.nullable_to_opt(textInput.current), (function (input) {
225-
input.focus();
226-
227-
}));
228+
Core__Nullable.forEach(textInput.current, (function (input) {
229+
input.focus();
230+
}));
228231
};
229232
return React.createElement("div", undefined, React.createElement("input", {
230-
ref: setTextInputRef,
233+
ref: Caml_option.some(setTextInputRef),
231234
type: "text"
232235
}), React.createElement("input", {
233236
type: "button",

src/ApiDocs.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ module SidebarTree = {
223223
</div>
224224
<div className="hl-overline text-gray-80 mt-5 mb-2"> {"submodules"->React.string} </div>
225225
{node.children
226-
->Belt.SortArray.stableSortBy((v1, v2) => v1.name > v2.name ? 1 : -1)
226+
->Array.toSorted((v1, v2) => String.compare(v1.name, v2.name))
227227
->Array.map(renderNode)
228228
->React.array}
229229
</aside>

src/Packages.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module Resource = {
100100

101101
fuser
102102
->Fuse.search(pattern)
103-
->Belt.SortArray.stableSortBy((a, b) => a["item"].searchScore > b["item"].searchScore ? -1 : 1)
103+
->Array.toSorted((a, b) => Float.compare(a["item"].searchScore, b["item"].searchScore))
104104
}
105105

106106
let applyUrlResourceSearch = (urls: array<urlResource>, pattern: string): array<

src/components/SearchBox.res

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ let make = (
2929

3030
let onAreaFocus = evt => {
3131
let el = ReactEvent.Focus.target(evt)
32-
// TODO(aspeddro)
33-
// let isDiv = Js.Null_undefined.isNullable(el["type"])
34-
let isDiv = Nullable.toOption(el["type"])->Option.isSome
32+
// TODO(aspeddro): Replace with `Nullable.isNullable` when Core merge https://github.com/rescript-association/rescript-core/pull/227 and publish a new release
33+
let isDiv = Js.Null_undefined.isNullable(el["type"])
3534

3635
if isDiv && state === Inactive {
3736
focusInput()

0 commit comments

Comments
 (0)