Skip to content

Commit

Permalink
Merge pull request #249 from rescriptbr/feat/improve-stuff
Browse files Browse the repository at this point in the history
bring back reschema, move everything to packages/ and setup rewatch, upgrade to v11
  • Loading branch information
fakenickels authored Jan 22, 2024
2 parents 870c3e1 + 284ee39 commit a7c0dac
Show file tree
Hide file tree
Showing 105 changed files with 5,056 additions and 993 deletions.
20 changes: 20 additions & 0 deletions bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "reform-monorepo",
"sources": [
{
"dir": "src/",
"subdirs": true
}
],
"package-specs": [
{
"module": "commonjs",
"in-source": true
}
],
"warnings": {
"error": false
},
"suffix": ".bs.js",
"bs-dependencies": ["@rescriptbr/reform", "@rescriptbr/reschema"]
}
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
},
"pre-commit": "lint:staged",
"workspaces": [
"reform",
"website",
"demo"
"packages/reform",
"packages/website",
"packages/reschema"
],
"husky": {
"hooks": {
Expand All @@ -48,15 +48,17 @@
"scripts": {
"docs:watch": "yarn workspace website start",
"docs:build": "yarn workspace website build",
"res:watch": "yarn workspace @rescriptbr/reform res:watch",
"res:build": "yarn workspace @rescriptbr/reform res:build",
"res:watch": "rewatch watch",
"res:build": "rewatch build",
"res:clean": "rewatch clean",
"res:setup": "yarn workspace @rescriptbr/reform res:setup",
"test": "yarn workspace @rescriptbr/reform test",
"test:watch": "yarn workspace @rescriptbr/reform test:watch",
"lint:staged": "lint-staged",
"demo:build": "yarn workspace demo build"
},
"dependencies": {
"rescript": "9.1.4"
"@rolandpeelen/rewatch": "0.0.12-0c3740d.0",
"rescript": "^11.0.0"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions demo/package.json → 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
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.
4 changes: 1 addition & 3 deletions reform/bsconfig.json → packages/reform/bsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
"name": "@rescriptbr/reform",
"reason": { "react-jsx": 3 },
"refmt": 3,
"jsx": { "version": 4 },
"bs-dependencies": [
"@rescript/react",
"@rescriptbr/reschema",
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions reform/package.json → 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": "^9.1.1"
"@rescript/react": "^0.12.0",
"rescript": "^11.0.0"
},
"devDependencies": {
"@rescript/react": "^0.10.1",
"rescript": "^9.1.1"
"@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-react-update": "^3.0.1"
"rescript": "^11.0.0",
"rescript-react-update": "5.0.2"
}
}
60 changes: 24 additions & 36 deletions reform/src/ReForm.res → 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 @@ -141,11 +141,6 @@ module Make = (Config: Config) => {
}

module Provider = {
let makeProps = (~value, ~children, ()) =>
{
"value": Some(value),
"children": children,
}
let make = React.Context.provider(formContext)
}

Expand All @@ -159,17 +154,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 +176,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 All @@ -207,7 +195,7 @@ module Make = (Config: Config) => {
None
},
)
| SetFieldsState(fieldsState) => Update({...state, fieldsState: fieldsState})
| SetFieldsState(fieldsState) => Update({...state, fieldsState})
| ValidateField(field) =>
SideEffects(
self => {
Expand Down Expand Up @@ -353,6 +341,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 +358,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 Expand Up @@ -425,7 +413,7 @@ module Make = (Config: Config) => {
}

let interface: api = {
state: state,
state,
formState: state.formState,
fieldsState: state.fieldsState,
values: state.values,
Expand All @@ -437,9 +425,9 @@ module Make = (Config: Config) => {
setValues: fn => send(SetValues(fn)),
setFieldValue: (field, value, ~shouldValidate=true, ()) =>
shouldValidate ? send(FieldChangeValue(field, value)) : send(SetFieldValue(field, value)),
getFieldState: getFieldState,
getFieldError: getFieldError,
getNestedFieldError: getNestedFieldError,
getFieldState,
getFieldError,
getNestedFieldError,
handleChange: (field, value) => send(FieldChangeValue(field, value)),
handleChangeWithCallback: (field, updateFn) =>
send(FieldChangeValueWithCallback(field, updateFn)),
Expand All @@ -450,8 +438,8 @@ module Make = (Config: Config) => {
arrayRemoveByIndex: (field, index) => send(FieldArrayRemove(field, index)),
validateField: field => send(ValidateField(field)),
validateForm: () => send(ValidateForm(false)),
validateFields: validateFields,
raiseSubmitFailed: raiseSubmitFailed,
validateFields,
raiseSubmitFailed,
}

interface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
let handleChange = (handleChange, event) =>
handleChange(ReactEvent.Form.target(event)["value"])
let handleChange = (handleChange, event) => handleChange(ReactEvent.Form.target(event)["value"])

let handleSubmit = (handleSubmit, event) => {
ReactEvent.Synthetic.preventDefault(event)
handleSubmit()
}

15 changes: 15 additions & 0 deletions packages/reschema/.github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: 14

- run: npm i
- run: npm run rescript:build
39 changes: 39 additions & 0 deletions packages/reschema/.github/workflows/create-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Create version

on:
workflow_dispatch:
inputs:
versionType:
description: Version type
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
- premajor
- preminor
- prepatch
- prerelease


jobs:
create-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ssh-key: ${{ secrets.ADMIN_SSH_KEY }}
- uses: actions/setup-node@v1
with:
node-version: 15
- run: |
git config user.name rescriptbr-admin
git config user.email [email protected]
- name: Generate new version ${{ github.event.inputs.versionType }}
run: npm version ${{ github.event.inputs.versionType }}

- name: Push the tags
run: git push origin master --tags
29 changes: 29 additions & 0 deletions packages/reschema/.github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: publish package on npm

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm i
- run: npm run rescript:build

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
registry-url: https://registry.npmjs.org/
- run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{secrets.ADMIN_NPM_TOKEN}}
4 changes: 4 additions & 0 deletions packages/reschema/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lib/
*.bs.js
.merlin
node_modules
5 changes: 5 additions & 0 deletions packages/reschema/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib
*.bs.js
__tests__
.merlin
demo/
1 change: 1 addition & 0 deletions packages/reschema/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15.0.1
Loading

0 comments on commit a7c0dac

Please sign in to comment.