- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我很想理解为什么这不起作用。我正在尝试消除抖动,但不是从 View 中消除用户事件。按照想法,这应该进入连续流,该流将发生一次,但每隔几秒发生一次。这种架构的主要思想是事件可能从不同的地方触发,但只会发生一次。我制作了一个简单的示例应用程序:
module Main exposing (main)
import Html exposing (Html)
import Html
import Process
import Task
import Debug
import Time
import Control exposing (Control)
import Control.Debounce as Debounce
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ counter : Int
, state : Control.State Msg
}
init : ( Model, Cmd Msg )
init =
{ counter = 0, state = Control.initialState }
! [ delay (Time.second * 3) <| ContinuousDebouncing ]
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
type Msg
= Deb (Control Msg)
| ContinuousDebouncing
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Deb debMsg ->
Control.update (\s -> { model | state = s }) model.state debMsg
ContinuousDebouncing ->
let
x = Debug.log "ContinuousDebouncing"
_ = debounce ContinuousDebouncing
in
( { model | counter = model.counter + 1 }, Cmd.none )
debounce : Msg -> Msg
debounce =
let
x = Debug.log "debounce"
in
Debounce.trailing Deb (3 * Time.second)
delay : Time.Time -> msg -> Cmd msg
delay time msg =
Process.sleep time
|> Task.andThen (always <| Task.succeed msg)
|> Task.perform identity
view : Model -> Html Msg
view model =
Html.text (toString model.counter)
最佳答案
在您的示例应用中,您仅在 init
函数中触发了一次 ContinouslyDebouncing
消息,因此正如预期的那样,计数器仅递增一次。您可能想在更新函数中再次触发 ContinouslyDebouncing
。
我认为这实现了您所追求的目标:
module Main exposing (main)
import Html exposing (Html)
import Html
import Process
import Task
import Debug
import Time
import Control exposing (Control)
import Control.Debounce as Debounce
main : Program Never Model Msg
main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
type alias Model =
{ counter : Int
, state : Control.State Msg
}
init : ( Model, Cmd Msg )
init =
{ counter = 0, state = Control.initialState }
! [ incrementCounter ]
incrementCounter : Cmd Msg
incrementCounter = Cmd.map debounce <| delay (Time.second * 3) <| ContinuousDebouncing
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
type Msg
= Deb (Control Msg)
| ContinuousDebouncing
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Deb debMsg ->
Control.update (\s -> { model | state = s }) model.state debMsg
ContinuousDebouncing ->
let
x = Debug.log "ContinuousDebouncing"
in
( { model | counter = model.counter + 1 }, incrementCounter )
debounce : Msg -> Msg
debounce =
let
x = Debug.log "debounce"
in
Debounce.trailing Deb (3 * Time.second)
delay : Time.Time -> msg -> Cmd msg
delay time msg =
Process.sleep time
|> Task.andThen (always <| Task.succeed msg)
|> Task.perform identity
view : Model -> Html Msg
view model =
Html.text (toString model.counter)
关于elm - 在 let 表达式中使用 elm 进行反跳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50806235/
基本上我想在悬停时使文本带有删除线。这并不容易使用 el [ mouseOver [Font.strike] ] (text "some text") 就像这样 el [ mouseOver [Bac
基本上我想在悬停时使文本带有删除线。这并不容易使用 el [ mouseOver [Font.strike] ] (text "some text") 就像这样 el [ mouseOver [Bac
以下模式匹配至少有两个元素的列表有什么问题pos1和 pos2 ? type Pos = (Float, Float) type Tail = [Pos] tail_cut : Float -> Ta
我想更新 Elm 类型的记录 type CubeData = {currDirection : Vec3, translation : Vec3, transform : Mat4} 我可以使用以下代
假设有两种数据类型: type alias Player = { name : String , team : Team } type alias Team = { name : St
Python 有它们,我发现它们非常有用: def awesome_fn(x, y): """" Calculates some awesome function of x and y
我正在尝试在 Elm 中设计一个功能,该功能解析来自 Json 的数据,然后将其呈现在一个可排序的表中。 当然,我使用解码器将 Json 数据存储在记录列表中;然后在 View 中,我将记录列表转换为
假设我正在尝试遵循 Elm 架构并将我的工作流程拆分为 User s 和 Invoice s 使用 StartApp . 用户有发票,但他们必须登录才能访问它们。 该模型可能看起来像这样: type
我喜欢 React/Redux 的智能和哑组件概念,其中哑组件不处理自己的状态(Dump 组件对外界一无所知,它所做的只是根据其输入触发事件并显示值) .这是微不足道的,因为所有状态都在一个地方处理(
如何在 elm-repl 中找出 Elm 表达式或子表达式的类型? Haskell 的 :type或 :t相当于 Elm REPL 吗? 最佳答案 Elm REPL 会自动打印您输入的任何类型。例如:
在 Elm 中是否可以通过一个事件处理程序触发多个输入句柄?例如,假设我有以下内容: button [ type' "button", on "click" getAnything go.ha
我正在尝试构建一个通用映射函数,该函数将从联合类型中提取可能的内部类型,对内部值应用转换并将其映射回外部类型。 问题是,我需要一种方法来区分外部类型的特定值是否具有内部类型。 如果下面的代码实际编译了
每隔一段时间,您就会遇到如下编译器错误: It looks like the keyword `port` is being used as a variable. 这很烦人。这些关键词有完整的官方列
我刚刚开始考虑使用 Elm 构建一个简单的 Web 应用程序。我的想法是需要在浏览器中保留一些用户数据。 有没有办法直接用 Elm 处理数据持久化?例如在浏览器 session 甚至本地存储中?或者我
我有这个功能 result = add 1 2 |> \a -> a % 2 == 0) 我收到了这个错误 Elm does not use (%) as the remainder operat
编写一个函数将一个列表分成两个列表。第一部分的长度由调用者指定。 我是 Elm 的新手,所以我不确定我的推理是否正确。我认为我需要转换数组中的输入列表,以便我能够按提供的输入数字对其进行切片。我也在语
我正在尝试创建一个简单的Elm项目,仅插入“hello world!”串成div。 这是我的代码: index.html: ELM Course
我正在编写elm程序,该程序应将其输出格式化为HTML列表。我要的功能 inputs = ["first", "second", "third"] 并输出本质上是某种Elm Element,
在 Elm 中,我无法弄清楚什么时候 type 是合适的关键字,什么时候 type 别名 才是合适的。文档似乎没有对此进行解释,我也无法在发行说明中找到这一解释。这是否记录在某处? 最佳答案 我的想法
我刚刚开始学习 Elm,并且在理解为什么将自定义类型传递到期望的方法时遇到类型不匹配的问题......好吧,我称之为部分类型注释. 这是我正在使用的代码: import Graphics.Elemen
我是一名优秀的程序员,十分优秀!