qiniu / formstate-x

Manage state of form with ease.
https://qiniu.github.io/formstate-x
MIT License
34 stars 10 forks source link

Adapter for v2 #64

Closed nighca closed 2 years ago

nighca commented 2 years ago

We need to provide adapters, which make these usage possible:

1. Use v3 state as one field of v2 form state

import * as v2 from 'formstate-x@v2'
import * as v3 from 'formstate-x@v3'

const foo = new v3.FieldState('')
const bar = new v3.FormState({ ... })

new v2.FormState({
  foo: v3.toV2(foo),
  bar: v3.toV2(bar)
})

2. Use v2 state as one field of v3 form state

import * as v2 from 'formstate-x@v2'
import * as v3 from 'formstate-x@v3'

const foo = new v2.FieldState('')
const bar = new v2.FormState({ ... })

new v3.FormState({
  foo: v3.fromV2(foo),
  bar: v3.fromV2(bar)
})

This makes it easy for project to migrate from v2 to v3 smoothly.