Closed nighca closed 2 years ago
Validatable
IState
StateUtils
State
src/adapter
src/testUtils
FieldState
value: NaN
Check proposal detail here. Examples:
ProxyState
interface Host { hostname: string port: number } type HostInput = string function parseHost(input: HostInput): Host { const [hostname, portStr] = input.split(':') const port = parseInt(portStr, 10) return { hostname, port } } function stringifyHost(host: Host) { return [host.hostname, host.port].join(':') } function createHostState() { const rawState = new FieldState('') return new ProxyState(rawState, parseHost, stringifyHost) } const hostState = createHostState() assertType<Host>(hostState.value) assertType<HostInput>(hostState.$.value)
FormState
interface HostInput { hostname: string port: number } type Host = string function parseHost(host: string): HostInput { const [hostname, portStr] = host.split(':') const port = parseInt(portStr, 10) return { hostname, port } } function stringifyHost(input: HostInput) { const suffix = Number.isNaN(input.port) ? '' : `:${input.port}` return input.hostname + suffix } function createHostState(host: string = '127.0.0.1:80') { const hostInput = parseHost(host) const rawState = new FormState({ hostname: new FieldState(hostInput.hostname), port: new FieldState(hostInput.port) }) return new ProxyState(rawState, stringifyHost, parseHost) } const hostState = createHostState() assertType<Host>(hostState.value) assertType<HostInput>(hostState.$.value) assertType<string>(hostState.$.$.hostnamae.value)
同 https://github.com/qiniu/formstate-x/pull/54#issuecomment-972761697 这里先 merge
Overview
Validatable
->IState
with some fields adjustmentStateUtils
& classState
src/adapter
src/testUtils
FieldState
issue withvalue: NaN
Value transform inside of state
Check proposal detail here. Examples:
ProxyState
forFieldState
:ProxyState
forFormState
: