Skip to content

Commit 886634d

Browse files
authored
add adapter for formstate (#28)
* add adapter for formstate * eliminate duplicated code * property origin for xified state * update README * use state.hasError instead of state.error * v1.2.0 * remove nouse comment
1 parent 0fb4603 commit 886634d

File tree

5 files changed

+641
-2
lines changed

5 files changed

+641
-2
lines changed

package-lock.json

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "formstate-x",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Extended alternative for formstate",
55
"repository": {
66
"type": "git",
@@ -33,6 +33,7 @@
3333
"devDependencies": {
3434
"@types/jest": "^25.2.1",
3535
"@types/node": "^12.7.12",
36+
"formstate": "^1.0.0",
3637
"jest": "^25.2.7",
3738
"mobx": "^5.15.4",
3839
"ts-jest": "^25.3.1",

src/adapter/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# formstate adapter
2+
3+
This module provides a [formstate](https://github.com/formstate/formstate) adapter, with which you can use formstate state in formstate-x `FormState` like this:
4+
5+
```ts
6+
import * as fs from 'formstate'
7+
import { FormState } from 'formstate-x'
8+
9+
// the adapt method
10+
import { xify } from 'formstate-x/esm/adapter'
11+
12+
// formstate FieldState or FormState
13+
const stateA = new fs.FieldState(1)
14+
const stateB = new fs.FormState({ ... })
15+
16+
// formstate-x FormState
17+
const formState = new FormState({
18+
a: xify(state),
19+
b: xify(stateB)
20+
})
21+
22+
// you can use the form state as usual
23+
console.log(formState.value)
24+
const result = await formState.validate()
25+
```
26+
27+
It is helpful when migrating your project from formstate to formstate-x. Instead of rewriting all your input / field components at once, you can do it one by one. The adapter makes it possible to use formstate-based input / field component in a formstate-x-based form / page component.
28+
29+
**NOTE: [`FormStateLazy`](https://formstate.github.io/#/?id=formstatelazy) is not supported yet.**

0 commit comments

Comments
 (0)