我正在尝试调整这个例子https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58(下面复制的相关部分),但不是偷看孙子,而是想偷看孩子,或者在这种情况下peekList
。我还想将插槽类型保留为peekList
的peek函数中的参数。
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))
然后将slot参数添加回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”
如果我只是尝试使用peekList
代替o peek
,我会在尝试匹配类型ChildF ListSlot(Coproduct)时遇到类型为ListQuery的错误“无法匹配类型Coproduct ListQuery(ChildF TickSlot TickQuery)” ListQuery(ChildF TickSlot TickQuery))类型为ChildF ListSlot ListQuery“
非常感谢任何帮助,谢谢!
答案 0 :(得分:0)
我仔细查看了类型,看到peekList的第二个参数是一个包裹Either
的Coproduct,其中Left
值是我要查看的列表查询。因此,只需对这些模式进行匹配,然后将peekList
添加到组件的peek
参数中。此外,我必须更改类型签名以使用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