如何sampleOn信号并将采样值保存在Elm中?

时间:2015-11-04 10:50:13

标签: elm elm-signal

考虑一个模型:

model : Signal Model

以及以下2个信号:

clickPosition = Mouse.position
  |> Signal.sampleOn Mouse.clicks

dimensions = Window.dimensions

我想获得以下desiredSignal

            (0,0)       (30,20)               (60,70)
clickPosition +------------+---------------------+---------

              M0   M1                  M2     M3
        model +----+-------------------+------+------------

          (600,800)         (400,300)  (200,800)
   dimensions +-----------------+----------+---------------

              D1           D2                    D3
desiredSignal +------------+---------------------+---------


where:

  D1 = ((0,0), M0, (600,800))
  D2 = ((30,20), M1, (600,800))
  D3 = ((60,70), M3, (200,800))

即。我想样本clickPosition,但保留采样值。

我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

看起来你的desiredSignal是三个信号的最新值,tupled,但只是改变clickPosition信号的变化。您可以先组合它们,然后对clickPosition信号进行采样:

desiredSignal =
  Signal.map3 (,,) clickPosition model dimensions
  |> Signal.sampleOn clickPosition