Skip to content

Commit

Permalink
breaking: upgrade rescript v11 and react v18
Browse files Browse the repository at this point in the history
  • Loading branch information
fakenickels committed Jan 17, 2024
1 parent fa82583 commit 90cd75c
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 353 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"workspaces": [
"packages/reform",
"packages/website",
"packages/reschema",
"packages/demo"
"packages/reschema"
],
"husky": {
"hooks": {
Expand All @@ -60,6 +59,6 @@
},
"dependencies": {
"@rolandpeelen/rewatch": "0.0.12-0c3740d.0",
"rescript": "^10.1.4"
"rescript": "^11.0.0"
}
}
8 changes: 4 additions & 4 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"private": true,
"dependencies": {
"@emotion/css": "11.7.1",
"@rescript/react": "0.10.3",
"@rescript/react": "^0.12.0",
"@rescriptbr/ancestor": "0.5.0",
"@rescriptbr/reform": "12.0.1",
"@vitejs/plugin-react": "1.0.0",
"lenses-ppx": "6.1.10",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"@rescriptbr/reschema": "3.0.1",
"rescript": "9.1.1",
"rescript": "^11.0.0",
"vite": "2.6.4"
},
"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions packages/reform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
"author": "Gabriel Rubens <fakenickels.dev>",
"license": "MIT",
"peerDependencies": {
"@rescript/react": "^0.10.3",
"rescript": "^10.1.4"
"@rescript/react": "^0.12.0",
"rescript": "^11.0.0"
},
"devDependencies": {
"@rescript/react": "^0.10.1",
"rescript": "^10.1.4"
"@rescript/react": "^0.12.0",
"rescript": "^11.0.0"
},
"scripts": {
"start": "yarn res:watch",
Expand All @@ -36,6 +36,7 @@
},
"dependencies": {
"@rescriptbr/reschema": "^3.0.3",
"rescript": "^10.1.4"
"rescript": "^11.0.0",
"rescript-react-update": "5.0.2"
}
}
41 changes: 17 additions & 24 deletions packages/reform/src/ReForm.res
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module Make = (Config: Config) => {
validateField,
state,
}) => {
handleChange: handleChange(field),
handleChange: value => handleChange(field, value),
error: getFieldError(Field(field)),
state: getFieldState(Field(field)),
validate: () => validateField(Field(field)),
Expand All @@ -159,17 +159,15 @@ module Make = (Config: Config) => {
) => {
let fieldInterface = useField(field)

React.useMemo3(
() =>
fieldInterface
->Belt.Option.map(render)
->Belt.Option.getWithDefault(renderOnMissingContext),
(
fieldInterface->Belt.Option.map(({error}) => error),
fieldInterface->Belt.Option.map(({value}) => value),
fieldInterface->Belt.Option.map(({state}) => state),
),
)
React.useMemo(() =>
fieldInterface
->Belt.Option.map(render)
->Belt.Option.getWithDefault(renderOnMissingContext)
, (
fieldInterface->Belt.Option.map(({error}) => error),
fieldInterface->Belt.Option.map(({value}) => value),
fieldInterface->Belt.Option.map(({state}) => state),
))
}
}

Expand All @@ -183,12 +181,7 @@ module Make = (Config: Config) => {
(),
) => {
let (state, send) = ReactUpdate.useReducer(
{
fieldsState: getInitialFieldsState(schema),
values: initialState,
formState: Pristine,
},
(action, state) =>
(state: state, action) =>
switch action {
| Submit =>
UpdateWithSideEffects(
Expand Down Expand Up @@ -353,6 +346,11 @@ module Make = (Config: Config) => {
Update({...state, values: Config.set(state.values, field, value)})
| RaiseSubmitFailed(err) => Update({...state, formState: SubmitFailed(err)})
},
{
fieldsState: getInitialFieldsState(schema),
values: initialState,
formState: Pristine,
},
)

let getFieldState = field =>
Expand All @@ -365,12 +363,7 @@ module Make = (Config: Config) => {
let getFieldError = field =>
switch getFieldState(field) {
| Error(error) => Some(error)
| NestedErrors(_errors) =>
Js.log2(
"The following field has nested errors, access these with `getNestedFieldError` instead of `getFieldError`",
field,
)
None
| NestedErrors(_errors) => None
| Pristine
| Valid =>
None
Expand Down
4 changes: 2 additions & 2 deletions packages/reschema/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@rescript/react": "0.10.3",
"@rescript/react": "^0.12.0",
"@rescriptbr/reform": "12.0.0-0",
"lenses-ppx": "6.1.10",
"rescript": "9.1.4"
"rescript": "^11.0.0"
},
"scripts": {
"rescript:start": "npx rescript build -w",
Expand Down
2 changes: 1 addition & 1 deletion packages/reschema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"jest": "28.1.3"
},
"dependencies": {
"rescript": "^9.0.2"
"rescript": "^11.0.0"
}
}
6 changes: 3 additions & 3 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"@docusaurus/core": "2.0.0-beta.18",
"@docusaurus/preset-classic": "2.0.0-beta.18",
"@mdx-js/react": "^1.6.21",
"@rescript/react": "0.10.3",
"@rescript/react": "^0.12.0",
"@rescriptbr/ancestor": "0.5.0",
"@rescriptbr/reform": "12.0.1",
"clsx": "^1.1.1",
"lenses-ppx": "6.1.10",
"prism-react-renderer": "^1.2.1",
"prismjs": "1.28.0",
"raw-loader": "4.0.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"@rescriptbr/reschema": "3.0.1"
},
"browserslist": {
Expand Down
Loading

0 comments on commit 90cd75c

Please sign in to comment.