Purescript Halogen DeepPeek Child 而不是 Grandchild

Purescript Halogen DeepPeek Child Instead of Grandchild

我正在尝试改编此示例 https://github.com/slamdata/purescript-halogen/blob/v0.12.0/examples/deep-peek/src/Main.purs#L58(相关部分复制在下面),但我不想查看 grandchild 我只想查看 child,或者在这种情况 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))

然后将插槽参数添加回 peekList:

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

但是在 peek 我得到了错误 "Could not match type ChildF with type Coproduct while trying to match type ChildF ListSlot with type Coproduct (ChildF ListSlot ListQuery)"

如果我只是尝试使用 peekList 而不是 peek,我会得到错误 "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 的第二个参数是一个包含 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