2017-03-28 6 views
0

나는이 예제를 https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58 (아래의 관련 부분을 복사)으로 변경하려고하지만, 단지 아이를 들여다보고 싶거나이 경우 peekList 인 손자를 엿보는 대신에. 또한 슬롯 유형을 peekList에 대한 peek 함수의 매개 변수로 유지하려고합니다.Purescript Halogen DeepPeek Child of Grandchild

peek :: forall a. H.ChildF ListSlot ListQueryP a -> H.ParentDSL State (ListStateP g) Query ListQueryP g ListSlot Unit 
peek = coproduct peekList peekTicker <<< H.runChildF 

peekList :: forall a. ListQuery a -> H.ParentDSL State (ListStateP g) Query ListQueryP g ListSlot Unit 
peekList _ = 
    -- we're not actually interested in peeking on the list. 
    -- instead of defining a function like this, an alternative would be to use 
    -- `(const (pure unit))` in place of `peekList` in the `coproduct` function 
    pure unit 

peekTicker :: forall a. H.ChildF TickSlot TickQuery a -> H.ParentDSL State (ListStateP g) Query ListQueryP g ListSlot Unit 
peekTicker (H.ChildF _ (Tick _)) = H.modify (\st -> { count: st.count + 1 }) 
peekTicker _ = pure unit 

실제로 슬롯 매개 변수를 잃지 않고 peekList을 (를) 들여다 볼 수 있습니까?

나는 H.runChildF 제거 시도했다 :

peek = coproduct peekList (const (pure unit)) 

을 다음 peekList 다시 슬롯 매개 변수 추가 :

peekList :: forall a. H.ChildF ListSlot ListQuery a -> H.ParentDSL State (ListStateP g) Query ListQueryP g ListSlot Unit 

그러나 peek에서 나는 오류를 "형식과 일치 할 수 없습니다 유형 Coproduct (ChildF ListSlot ListQuery)로 유형 ChildF ListSlot을 일치 시키려고 시도하는 동안 유형 Coproduct가있는 ChildF "

peek 대신 peekList을 사용하려고하면 유형 ChildF ListSlot (Coproduct ListQuery (ChildF TickSlot TickQuery))과 유형이 일치하는 동안 ListQuery 유형의 유형 Coproduct ListQuery (ChildF TickSlot TickQuery)과 일치하는 오류가 발생합니다. ListSlot ListQuery "

감사합니다. 감사합니다.

답변

0

peekList에 대한 두 번째 인수는를 얻었습니다. Left 값은 내가 엿보고 싶은 목록 쿼리입니다. 따라서 패턴을 일치 시켜서 peekList을 구성 요소의 peek 매개 변수에 추가하십시오. 또한 ListQuery 대신 ListQueryP을 사용하도록 형식 서명을 변경해야했습니다.

peekList :: forall a. H.ChildF ListSlot ListQueryP a -> H.ParentDSL State (ListStateP g) Query ListQueryP g ListSlot Unit 
    peekList (H.ChildF _ (Coproduct queryEi)) = 
    case queryEi of 
     Left (AddTicker a) -> pure unit 
     _ -> pure unit 
+0

이 답변이 맞지만, 할로겐에 'peek' 메커니즘이 더 이상 존재하지 않는다는 사실에 주목할 가치가 있습니다! (v1.0.0 이상) –

+0

@gb. 예, 2 주 전에 업데이트 된 할로겐/purescript-routing 예제가 없었기 때문에 0.12.0을 사용하기로 결정했습니다. 지금은 있지만 너무 멀어요. – sportanova