diff --git a/src/BackendTask.elm b/src/BackendTask.elm index e71103cda..67bb9821d 100644 --- a/src/BackendTask.elm +++ b/src/BackendTask.elm @@ -125,16 +125,19 @@ type alias BackendTask error value = {-| Transform a request into an arbitrary value. The same underlying task will be performed, but mapping allows you to change the resulting values by applying functions to the results. - import BackendTask + import BackendTask exposing (BackendTask) import BackendTask.Http - import Json.Decode as Decode exposing (Decoder) + import FatalError exposing (FatalError) + import Json.Decode as Decode + starsMessage : BackendTask FatalError String starsMessage = BackendTask.Http.getJson "https://api.github.com/repos/dillonkearns/elm-pages" (Decode.field "stargazers_count" Decode.int) |> BackendTask.map (\stars -> "⭐️ " ++ String.fromInt stars) + |> BackendTask.allowFatal -} map : (a -> b) -> BackendTask error a -> BackendTask error b @@ -282,9 +285,10 @@ resolve = {-| Turn a list of `BackendTask`s into a single one. - import BackendTask + import BackendTask exposing (BackendTask) + import BackendTask.Http import FatalError exposing (FatalError) - import Json.Decode as Decode exposing (Decoder) + import Json.Decode as Decode type alias Pokemon = { name : String @@ -452,9 +456,10 @@ map2 fn request1 request2 = {-| Build off of the response from a previous `BackendTask` request to build a follow-up request. You can use the data from the previous response to build up the URL, headers, etc. that you send to the subsequent request. - import BackendTask + import BackendTask exposing (BackendTask) + import BackendTask.Http import FatalError exposing (FatalError) - import Json.Decode as Decode exposing (Decoder) + import Json.Decode as Decode licenseData : BackendTask FatalError String licenseData = diff --git a/src/BackendTask/File.elm b/src/BackendTask/File.elm index 320f37084..4e9fc6e7e 100644 --- a/src/BackendTask/File.elm +++ b/src/BackendTask/File.elm @@ -66,12 +66,14 @@ frontmatter frontmatterDecoder = import BackendTask exposing (BackendTask) import BackendTask.File as File - import Decode exposing (Decoder) + import FatalError exposing (FatalError) + import Json.Decode as Decode exposing (Decoder) - blogPost : BackendTask BlogPostMetadata + blogPost : BackendTask FatalError BlogPostMetadata blogPost = File.bodyWithFrontmatter blogPostDecoder "blog/hello-world.md" + |> BackendTask.allowFatal type alias BlogPostMetadata = { body : String @@ -102,11 +104,13 @@ It's common to parse the body with a markdown parser or other format. import BackendTask exposing (BackendTask) import BackendTask.File as File - import Decode exposing (Decoder) + import FatalError exposing (FatalError) import Html exposing (Html) + import Json.Decode as Decode example : BackendTask + FatalError { title : String , body : List (Html msg) } @@ -126,6 +130,7 @@ It's common to parse the body with a markdown parser or other format. ) ) "foo.md" + |> BackendTask.allowFatal markdownToView : String @@ -191,13 +196,15 @@ just the metadata. import BackendTask exposing (BackendTask) import BackendTask.File as File - import Decode exposing (Decoder) + import FatalError exposing (FatalError) + import Json.Decode as Decode exposing (Decoder) - blogPost : BackendTask BlogPostMetadata + blogPost : BackendTask FatalError BlogPostMetadata blogPost = File.onlyFrontmatter blogPostDecoder "blog/hello-world.md" + |> BackendTask.allowFatal type alias BlogPostMetadata = { title : String @@ -281,10 +288,13 @@ Hey there! This is my first post :) ``` import BackendTask exposing (BackendTask) + import BackendTask.File as File + import FatalError exposing (FatalError) - data : BackendTask String + data : BackendTask FatalError String data = - bodyWithoutFrontmatter "blog/hello-world.md" + File.bodyWithoutFrontmatter "blog/hello-world.md" + |> BackendTask.allowFatal Then data will yield the value `"Hey there! This is my first post :)"`. @@ -314,10 +324,12 @@ You could read a file called `hello.txt` in your root project directory like thi import BackendTask exposing (BackendTask) import BackendTask.File as File + import FatalError exposing (FatalError) - elmJsonFile : BackendTask String + elmJsonFile : BackendTask FatalError String elmJsonFile = File.rawFile "hello.txt" + |> BackendTask.allowFatal -} rawFile : String -> BackendTask { fatal : FatalError, recoverable : FileReadError decoderError } String @@ -331,8 +343,10 @@ The Decode will strip off any unused JSON data. import BackendTask exposing (BackendTask) import BackendTask.File as File + import FatalError exposing (FatalError) + import Json.Decode as Decode - sourceDirectories : BackendTask (List String) + sourceDirectories : BackendTask FatalError (List String) sourceDirectories = File.jsonFile (Decode.field @@ -340,6 +354,7 @@ The Decode will strip off any unused JSON data. (Decode.list Decode.string) ) "elm.json" + |> BackendTask.allowFatal -} jsonFile :