[英]Purescript Halogen DeepPeek Child Instead of Grandchild
I'm trying to adapt this example https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58 (relevant part copied below), but instead of peeking the grandchild I just want to peek the child, or in this case peekList
. 我正在尝试改编此示例https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58 (相关部分复制如下),但是偷看孙子,我只想偷看孩子,在本例中是
peekList
。 I also want to keep the slot type as a parameter in the peek function for peekList
. 我还想将插槽类型保留为
peekList
的peek函数中的peekList
。
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
How can I actually peek peekList
without losing the slot parameter? 我如何实际上可以在不丢失slot参数的情况下窥视
peekList
?
I've tried removing the H.runChildF
: 我试着删除
H.runChildF
:
peek = coproduct peekList (const (pure unit))
and then adding back in the slot parameter to peekList
: 然后将slot参数重新添加到
peekList
:
peekList :: forall a. H.ChildF ListSlot ListQuery a -> H.ParentDSL State (ListStateP g) Query ListQueryP g ListSlot Unit
But then in peek
I get the error "Could not match type ChildF with type Coproduct while trying to match type ChildF ListSlot with type Coproduct (ChildF ListSlot ListQuery)" 但是然后在
peek
我收到错误消息“尝试将类型为Coproduct的ChildF ListSlot与(ChildF ListSlot ListQuery)类型匹配时,无法将类型为CoF的ChildF与类型F匹配”。
If I just try to use peekList
instead o peek
, i get the error "Could not match type Coproduct ListQuery (ChildF TickSlot TickQuery) with type ListQuery while trying to match type ChildF ListSlot (Coproduct ListQuery (ChildF TickSlot TickQuery)) with type ChildF ListSlot ListQuery" 如果我只是尝试使用
peekList
而不是peek
, peekList
收到错误消息“尝试将类型为ChildF ListSlot的类型ChildF ListSlot(类型为CoFed ListQuery(ChildF TickSlot TickQuery))与类型为ListFlot的Coproduct ListQuery(ChildF TickSlot TickQuery)不匹配” ListQuery”
Any help would be really appreciated, thanks! 任何帮助将不胜感激,谢谢!
I looked at the types closer and saw that the second argument to peekList is a Coproduct wrapping an Either
where the Left
value is the list query that I want to peek. 我仔细查看了这些类型,发现peekList的第二个参数是包装了
Either
的共同产品,其中Left
值是我要窥视的列表查询。 So just pattern match on those and add peekList
to the component's peek
parameter. 因此,只需对它们进行模式匹配,然后将
peekList
添加到组件的peek
参数。 Also I had to change the type signature to use ListQueryP
instead of ListQuery
. 另外,我还必须更改类型签名以使用
ListQueryP
而不是ListQuery
。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.