Skip to content

Commit 0452ff3

Browse files
committed
refactor input form
1 parent ed3fdce commit 0452ff3

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/__tests__/fantasy-test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,9 @@ describe('actions', () => {
197197
describe('combine', () => {
198198
let input1
199199
beforeEach(() => {
200-
let inputNumber = x => xinput<'number', rx.URI, Event, ViewProps>(x)
201-
let fantasyX1 = inputNumber('value0')
200+
let fantasyX1 = xinput<rx.URI, Event, ViewProps>('value0')
202201

203-
let fantasyX2 = inputNumber('value1')
202+
let fantasyX2 = xinput<rx.URI, Event, ViewProps>('value1')
204203

205204
let View: React.SFC<any> = props => (
206205
<div>

src/forms/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import { pure } from '../fantasy'
2-
import { Partial } from '../fantasy/interfaces'
31
import { HKTS, streamOps, HKT } from '../xs'
4-
import { Update } from '../interfaces'
2+
import { Update, pure } from '..'
53
import { FantasyX } from '../fantasy/fantasyx'
4+
import { Partial } from '../fantasy/interfaces'
5+
6+
export type AnyProps = {
7+
[name: string]: any
8+
}
69

710
export function xinput<
811
E extends HKTS,
912
I extends Event,
10-
S>(name: keyof S) {
13+
S extends AnyProps>(name: keyof S) {
1114
return pure<E, I, S>(intent$ => {
1215
return {
1316
update$:
1417
streamOps.map<string, Update<S>>(
15-
value => (state => ({ [name]: value }) as Partial<S>),
18+
value => (state => {
19+
let result = <S>{}
20+
result[name] = value
21+
return result as Partial<S>
22+
}),
1623
streamOps.map<Event, string>(
1724
e => (e.target as HTMLFormElement).value,
1825
streamOps.filter<I>(i => {

0 commit comments

Comments
 (0)