我正在尝试修改此示例https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58(相关部分复制如下),而是偷看孙子我只想偷看孩子,或者在这种情况下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
我怎样才能在peekList
不丢失 slot 参数的情况下真正偷看?
我试过删除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
我收到错误“尝试将 ChildF ListSlot 类型与 Coproduct 类型(ChildF ListSlot ListQuery)匹配时无法将类型 ChildF 与 Coproduct 类型匹配”
如果我只是尝试使用peekList
o peek
,我会收到错误“在尝试将类型 ChildF ListSlot (Coproduct ListQuery (ChildF TickSlot TickQuery)) 与类型 ChildF ListSlot ListQuery 匹配时,无法将类型 Coproduct ListQuery (ChildF TickSlot TickQuery) 与类型 ListQuery 匹配”
任何帮助将不胜感激,谢谢!