11import * as React from 'react' ;
22import { render } from 'react-dom' ;
3- import * as RX from '../../src/xs/rx'
4- import X from '../../src/x'
5- import { pure , lift2 } from '../../src/fantasy'
6- import { Actions } from '../../src/interfaces'
7- interface Change extends Event {
8- type : string
9- target : HTMLInputElement
10- }
11- type Intent = Change
3+ import * as RX from '../../lib/xs/rx'
4+ import { X , xinput , lift2 , Actions } from '../..'
5+
6+ // Types
7+ interface Intent extends Event { }
8+
129interface BMIState {
1310 value : number
11+ weight : number
12+ height : number
1413 bmi : string
1514 health : string
1615}
16+
1717interface BMIProps < I > extends BMIState {
1818 actions : Actions < I > ;
1919}
20+
21+ // View
2022const View : React . SFC < BMIProps < Intent > > = props => (
2123 < div >
2224 < label >
@@ -34,24 +36,17 @@ const View: React.SFC<BMIProps<Intent>> = props => (
3436
3537View . defaultProps = { bmi : '' , health : '' }
3638
39+ // Plan
40+ const weightx = xinput < 'number' , RX . URI , Intent , BMIState > ( 'weight' )
3741
38- const planx = ( name : string ) => ( intent$ ) => {
39- return {
40- update$ : intent$ . filter ( i => i . type == 'change' && i . target . name == name )
41- . map ( i => parseFloat ( i . target . value ) )
42- . map ( value => state => ( { value } ) )
43- }
44- }
45- const weightx = pure < RX . URI , Intent , BMIState > ( planx ( 'weight' ) )
46-
47- const heightx = pure < RX . URI , Intent , BMIState > ( planx ( 'height' ) )
42+ const heightx = xinput < 'number' , RX . URI , Intent , BMIState > ( 'height' )
4843
4944const BMIx = lift2 < RX . URI , Intent , BMIState > (
5045 ( s1 , s2 ) => {
5146 let bmi = 0
5247 let health = '...'
53- if ( s1 . value && s2 . value ) {
54- bmi = s1 . value / ( s2 . value * s2 . value )
48+ if ( s1 . weight && s2 . height ) {
49+ bmi = s1 . weight / ( s2 . height * s2 . height )
5550 }
5651 if ( bmi < 18.5 ) health = 'underweight'
5752 else if ( bmi < 24.9 ) health = 'normal'
@@ -66,8 +61,8 @@ const BMI = BMIx.apply(View)
6661// BMIx is compose from weightx and heightx
6762
6863// while weightx and heightx can be still use to create another component
69- const Weight = weightx . apply ( props => props . value ? < p > where height is { props . value } kg</ p > : null )
70- const Height = heightx . apply ( props => props . value ? < p > and { props . value } m height</ p > : null )
64+ const Weight = weightx . apply ( props => props . weight ? < p > where weight is { props . weight } kg</ p > : null )
65+ const Height = heightx . apply ( props => props . height ? < p > and { props . height } m height</ p > : null )
7166render (
7267 < X x = { RX } >
7368 < form >
0 commit comments