小编Jol*_*nda的帖子

在 Elm 中测试去抖动

我正在尝试在我的 Elm 应用程序中测试去抖动功能,但不知道如何进行。

去抖动应用于模糊搜索的文本字段以避免发出过多的http请求,它以这个示例https://ellie-app.com/jNmstCdv3va1为蓝本并遵循相同的逻辑。

type alias Model =
    { search : Maybe String 
    , searchResult : List User
    , debouncingCounter : Int
    }

init : Model
init = 
    { search = Nothing
    , searchResult = [] 
    , debouncingCounter = 0
    }

debounceTime : Time
debounceTime = 350 * Time.millisecond

update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
    case msg of 

        (...)

        SearchInput search ->
            let 
                newCounter = model.debouncingCounter + 1
            in
            case search …
Run Code Online (Sandbox Code Playgroud)

testing elm debounce elm-test

5
推荐指数
1
解决办法
274
查看次数

标签 统计

debounce ×1

elm ×1

elm-test ×1

testing ×1