Skip to content

Commit a7c0dac

Browse files
authored
Merge pull request #249 from rescriptbr/feat/improve-stuff
bring back reschema, move everything to packages/ and setup rewatch, upgrade to v11
2 parents 870c3e1 + 284ee39 commit a7c0dac

File tree

105 files changed

+5056
-993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+5056
-993
lines changed

bsconfig.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "reform-monorepo",
3+
"sources": [
4+
{
5+
"dir": "src/",
6+
"subdirs": true
7+
}
8+
],
9+
"package-specs": [
10+
{
11+
"module": "commonjs",
12+
"in-source": true
13+
}
14+
],
15+
"warnings": {
16+
"error": false
17+
},
18+
"suffix": ".bs.js",
19+
"bs-dependencies": ["@rescriptbr/reform", "@rescriptbr/reschema"]
20+
}

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
},
3636
"pre-commit": "lint:staged",
3737
"workspaces": [
38-
"reform",
39-
"website",
40-
"demo"
38+
"packages/reform",
39+
"packages/website",
40+
"packages/reschema"
4141
],
4242
"husky": {
4343
"hooks": {
@@ -48,15 +48,17 @@
4848
"scripts": {
4949
"docs:watch": "yarn workspace website start",
5050
"docs:build": "yarn workspace website build",
51-
"res:watch": "yarn workspace @rescriptbr/reform res:watch",
52-
"res:build": "yarn workspace @rescriptbr/reform res:build",
51+
"res:watch": "rewatch watch",
52+
"res:build": "rewatch build",
53+
"res:clean": "rewatch clean",
5354
"res:setup": "yarn workspace @rescriptbr/reform res:setup",
5455
"test": "yarn workspace @rescriptbr/reform test",
5556
"test:watch": "yarn workspace @rescriptbr/reform test:watch",
5657
"lint:staged": "lint-staged",
5758
"demo:build": "yarn workspace demo build"
5859
},
5960
"dependencies": {
60-
"rescript": "9.1.4"
61+
"@rolandpeelen/rewatch": "0.0.12-0c3740d.0",
62+
"rescript": "^11.0.0"
6163
}
6264
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

demo/package.json packages/demo/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
"private": true,
55
"dependencies": {
66
"@emotion/css": "11.7.1",
7-
"@rescript/react": "0.10.3",
7+
"@rescript/react": "^0.12.0",
88
"@rescriptbr/ancestor": "0.5.0",
99
"@rescriptbr/reform": "12.0.1",
1010
"@vitejs/plugin-react": "1.0.0",
1111
"lenses-ppx": "6.1.10",
12-
"react": "17.0.2",
13-
"react-dom": "17.0.2",
12+
"react": "^18.0.0",
13+
"react-dom": "^18.0.0",
1414
"@rescriptbr/reschema": "3.0.1",
15-
"rescript": "9.1.1",
15+
"rescript": "^11.0.0",
1616
"vite": "2.6.4"
1717
},
1818
"scripts": {
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

reform/bsconfig.json packages/reform/bsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
32
"name": "@rescriptbr/reform",
4-
"reason": { "react-jsx": 3 },
5-
"refmt": 3,
3+
"jsx": { "version": 4 },
64
"bs-dependencies": [
75
"@rescript/react",
86
"@rescriptbr/reschema",
File renamed without changes.

reform/package.json packages/reform/package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
"author": "Gabriel Rubens <fakenickels.dev>",
2121
"license": "MIT",
2222
"peerDependencies": {
23-
"@rescript/react": "^0.10.3",
24-
"rescript": "^9.1.1"
23+
"@rescript/react": "^0.12.0",
24+
"rescript": "^11.0.0"
2525
},
2626
"devDependencies": {
27-
"@rescript/react": "^0.10.1",
28-
"rescript": "^9.1.1"
27+
"@rescript/react": "^0.12.0",
28+
"rescript": "^11.0.0"
2929
},
3030
"scripts": {
3131
"start": "yarn res:watch",
@@ -36,6 +36,7 @@
3636
},
3737
"dependencies": {
3838
"@rescriptbr/reschema": "^3.0.3",
39-
"rescript-react-update": "^3.0.1"
39+
"rescript": "^11.0.0",
40+
"rescript-react-update": "5.0.2"
4041
}
4142
}

reform/src/ReForm.res packages/reform/src/ReForm.res

+24-36
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ module Make = (Config: Config) => {
132132
validateField,
133133
state,
134134
}) => {
135-
handleChange: handleChange(field),
135+
handleChange: value => handleChange(field, value),
136136
error: getFieldError(Field(field)),
137137
state: getFieldState(Field(field)),
138138
validate: () => validateField(Field(field)),
@@ -141,11 +141,6 @@ module Make = (Config: Config) => {
141141
}
142142

143143
module Provider = {
144-
let makeProps = (~value, ~children, ()) =>
145-
{
146-
"value": Some(value),
147-
"children": children,
148-
}
149144
let make = React.Context.provider(formContext)
150145
}
151146

@@ -159,17 +154,15 @@ module Make = (Config: Config) => {
159154
) => {
160155
let fieldInterface = useField(field)
161156

162-
React.useMemo3(
163-
() =>
164-
fieldInterface
165-
->Belt.Option.map(render)
166-
->Belt.Option.getWithDefault(renderOnMissingContext),
167-
(
168-
fieldInterface->Belt.Option.map(({error}) => error),
169-
fieldInterface->Belt.Option.map(({value}) => value),
170-
fieldInterface->Belt.Option.map(({state}) => state),
171-
),
172-
)
157+
React.useMemo(() =>
158+
fieldInterface
159+
->Belt.Option.map(render)
160+
->Belt.Option.getWithDefault(renderOnMissingContext)
161+
, (
162+
fieldInterface->Belt.Option.map(({error}) => error),
163+
fieldInterface->Belt.Option.map(({value}) => value),
164+
fieldInterface->Belt.Option.map(({state}) => state),
165+
))
173166
}
174167
}
175168

@@ -183,12 +176,7 @@ module Make = (Config: Config) => {
183176
(),
184177
) => {
185178
let (state, send) = ReactUpdate.useReducer(
186-
{
187-
fieldsState: getInitialFieldsState(schema),
188-
values: initialState,
189-
formState: Pristine,
190-
},
191-
(action, state) =>
179+
(state: state, action) =>
192180
switch action {
193181
| Submit =>
194182
UpdateWithSideEffects(
@@ -207,7 +195,7 @@ module Make = (Config: Config) => {
207195
None
208196
},
209197
)
210-
| SetFieldsState(fieldsState) => Update({...state, fieldsState: fieldsState})
198+
| SetFieldsState(fieldsState) => Update({...state, fieldsState})
211199
| ValidateField(field) =>
212200
SideEffects(
213201
self => {
@@ -353,6 +341,11 @@ module Make = (Config: Config) => {
353341
Update({...state, values: Config.set(state.values, field, value)})
354342
| RaiseSubmitFailed(err) => Update({...state, formState: SubmitFailed(err)})
355343
},
344+
{
345+
fieldsState: getInitialFieldsState(schema),
346+
values: initialState,
347+
formState: Pristine,
348+
},
356349
)
357350

358351
let getFieldState = field =>
@@ -365,12 +358,7 @@ module Make = (Config: Config) => {
365358
let getFieldError = field =>
366359
switch getFieldState(field) {
367360
| Error(error) => Some(error)
368-
| NestedErrors(_errors) =>
369-
Js.log2(
370-
"The following field has nested errors, access these with `getNestedFieldError` instead of `getFieldError`",
371-
field,
372-
)
373-
None
361+
| NestedErrors(_errors) => None
374362
| Pristine
375363
| Valid =>
376364
None
@@ -425,7 +413,7 @@ module Make = (Config: Config) => {
425413
}
426414

427415
let interface: api = {
428-
state: state,
416+
state,
429417
formState: state.formState,
430418
fieldsState: state.fieldsState,
431419
values: state.values,
@@ -437,9 +425,9 @@ module Make = (Config: Config) => {
437425
setValues: fn => send(SetValues(fn)),
438426
setFieldValue: (field, value, ~shouldValidate=true, ()) =>
439427
shouldValidate ? send(FieldChangeValue(field, value)) : send(SetFieldValue(field, value)),
440-
getFieldState: getFieldState,
441-
getFieldError: getFieldError,
442-
getNestedFieldError: getNestedFieldError,
428+
getFieldState,
429+
getFieldError,
430+
getNestedFieldError,
443431
handleChange: (field, value) => send(FieldChangeValue(field, value)),
444432
handleChangeWithCallback: (field, updateFn) =>
445433
send(FieldChangeValueWithCallback(field, updateFn)),
@@ -450,8 +438,8 @@ module Make = (Config: Config) => {
450438
arrayRemoveByIndex: (field, index) => send(FieldArrayRemove(field, index)),
451439
validateField: field => send(ValidateField(field)),
452440
validateForm: () => send(ValidateForm(false)),
453-
validateFields: validateFields,
454-
raiseSubmitFailed: raiseSubmitFailed,
441+
validateFields,
442+
raiseSubmitFailed,
455443
}
456444

457445
interface
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
let handleChange = (handleChange, event) =>
2-
handleChange(ReactEvent.Form.target(event)["value"])
1+
let handleChange = (handleChange, event) => handleChange(ReactEvent.Form.target(event)["value"])
32

43
let handleSubmit = (handleSubmit, event) => {
54
ReactEvent.Synthetic.preventDefault(event)
65
handleSubmit()
76
}
8-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: build
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-node@v2-beta
11+
with:
12+
node-version: 14
13+
14+
- run: npm i
15+
- run: npm run rescript:build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Create version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionType:
7+
description: Version type
8+
required: true
9+
default: 'patch'
10+
type: choice
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- premajor
16+
- preminor
17+
- prepatch
18+
- prerelease
19+
20+
21+
jobs:
22+
create-version:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
with:
27+
ssh-key: ${{ secrets.ADMIN_SSH_KEY }}
28+
- uses: actions/setup-node@v1
29+
with:
30+
node-version: 15
31+
- run: |
32+
git config user.name rescriptbr-admin
33+
git config user.email [email protected]
34+
35+
- name: Generate new version ${{ github.event.inputs.versionType }}
36+
run: npm version ${{ github.event.inputs.versionType }}
37+
38+
- name: Push the tags
39+
run: git push origin master --tags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: publish package on npm
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-node@v1
13+
with:
14+
node-version: 14
15+
- run: npm i
16+
- run: npm run rescript:build
17+
18+
publish-npm:
19+
needs: build
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- uses: actions/setup-node@v2
24+
with:
25+
node-version: 14
26+
registry-url: https://registry.npmjs.org/
27+
- run: npm publish --access=public
28+
env:
29+
NODE_AUTH_TOKEN: ${{secrets.ADMIN_NPM_TOKEN}}

packages/reschema/.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lib/
2+
*.bs.js
3+
.merlin
4+
node_modules

packages/reschema/.npmignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib
2+
*.bs.js
3+
__tests__
4+
.merlin
5+
demo/

packages/reschema/.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
15.0.1

0 commit comments

Comments
 (0)