-
-
Save zwilias/a3fafe728fffad8951847de282b29028 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sendDelayedRequest : Time.Time -> Http.Request a -> (WebData a -> msg) -> Cmd msg | |
sendDelayedRequest delay request tagger = | |
Process.sleep delay | |
-- Docs: http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Process#sleep | |
-- Signature: Process.sleep : Time -> Task x () | |
-- Here: Process.sleep : Time -> Task x () | |
-- | |
-- Given Time, this will return a task that can never fail and will result | |
-- in a successful value of `()` after a delay when executed by the runtime. | |
|> Task.andThen (\_ -> Http.toTask request) | |
-- Docs: http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Task#andThen | |
-- Signature: Task.andThen : (a -> Task x b) -> Task x a -> Task x b | |
-- Here: Task.andThen : (() -> Task Http.Error a) -> Task x () -> Task Http.Error a | |
-- | |
-- Allows chaining task-producing functions. In this case, the value | |
-- with which the previous task succeeds - `()` - is discarded by the | |
-- hockeystick. | |
-- | |
-- Docs: http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http#toTask | |
-- Signature: Http.toTask : Http.Request a -> Task Http.Error a | |
-- Here: Http.toTask : Http.Request a -> Task Http.Error a | |
-- | |
-- Turns an HTTP request into a Task that may fail with an Http Error. | |
|> RemoteData.fromTask | |
-- Docs: http://package.elm-lang.org/packages/krisajenkins/remotedata/4.3.0/RemoteData#fromTask | |
-- Signature: RemoteData.fromTask : Task e a -> Task x (RemoteData e a) | |
-- Here: RemoteData.fromTask : Task Http.Error a -> Task x (RemoteData Http.Error a) | |
-- Note that type alias WebData a = RemoteData Http.Error a | |
-- | |
-- Given a task with failure type `e` and successtype `a`, returns a Task | |
-- with failure type `x` and success-type `RemoteData e a`. | |
-- | |
-- Note that `x` is a free type variable. This means two things: | |
-- 1. this task can never fail. | |
-- 2. you can give this to any function that expects a certain type for | |
-- the error, like a function that expects a `Task Never a`. | |
|> Task.perform tagger | |
-- Docs: http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Task#perform | |
-- Signature: Task.perform : (a -> msg) -> Task Never a -> Cmd msg | |
-- Here: Task.perform (WebData a -> msg) -> Task Never (WebData a) -> Cmd msg | |
-- Note that the `x` from the previous section was unified with `Never`. | |
-- | |
-- Given a tagger and a task that can never fail, return a Cmd that, when | |
-- interpreted by the runtime, will eventually result in your update being | |
-- called with the resulting message. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment