2017-11-15 5 views
0

성분의 입력이 그 상태와 다른 할로겐 성분을 만들고 싶습니다. 할로겐 가이드 (https://github.com/slamdata/purescript-halogen/blob/master/docs/5%20-%20Parent%20and%20child%20components.md#input-values)에 따르면 이것이 가능해야합니다.Pulscript 할로겐 성분, 입력 대 상태

import Prelude 
import Data.Int (decimal, toStringAs) 
import Halogen as H 
import Halogen.HTML as HH 
import Halogen.HTML.Events as HHE 

type Input = Int 

type State = String 

data Query a = HandleInput Input a 

component :: forall m. H.Component HH.HTML Query Input Void m 
component = 
    H.component 
    { initialState: id 
    , render 
    , eval 
    , receiver: HHE.input HandleInput 
    } 
    where 

    render :: State -> H.ComponentHTML Query 
    render state = 
    HH.div_ 
     [ HH.text "My input value is:" 
     , HH.strong_ [ HH.text (show state) ] 
     ] 

    eval :: Query ~> H.ComponentDSL State Query Void m 
    eval = case _ of 
    HandleInput n next -> do 
     oldN <- H.get 
     when (oldN /= (toStringAs decimal n)) $ H.put $ toStringAs decimal n 
     pure next 

을 다음과 같이 나는 가이드에서 예를 변경하지만 , receiver: HHE.input HandleInput

Could not match type 

    String 

with type 

    Int 

내가 잘못 여기서 뭐하는 거지와 라인에서 컴파일 오류가 다음?

답변

0

입력 값을 사용하여 initialState이 계산되며 붙여 넣은 코드에서 id으로 구현되므로 입력 및 상태 유형을 강제로 일치 시키려고합니다.

0

변경된 라인 { initialState: const initialState{ initialState: idwhere 후에 첨가하고 다음 행

initialState :: State 
initialState = ""