Skip to content

Commit

Permalink
Update for Elm 0.16.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgrempel committed Nov 19, 2015
1 parent f2c693f commit 4d42fb6
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 5 deletions.
8 changes: 4 additions & 4 deletions elm-package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.1",
"summary": "Additional functions for use with elm-http",
"repository": "https://github.com/rgrempel/elm-http-decorators.git",
"license": "BSD3",
Expand All @@ -10,9 +10,9 @@
"Http.Decorators"
],
"dependencies": {
"elm-lang/core": "2.0.0 <= v < 3.0.0",
"evancz/elm-http": "1.0.0 <= v < 2.0.0",
"elm-lang/core": "3.0.0 <= v < 4.0.0",
"evancz/elm-http": "3.0.0 <= v < 4.0.0",
"evancz/task-tutorial": "1.0.0 <= v < 2.0.0"
},
"elm-version": "0.15.0 <= v < 0.16.0"
"elm-version": "0.16.0 <= v < 0.17.0"
}
168 changes: 168 additions & 0 deletions examples/Example.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
module Example where

import Effects exposing (Effects, Never)
import StartApp exposing (App)
import Task exposing (Task, toResult)
import Html exposing (Html, h4, div, text, button, input)
import Html.Attributes exposing (id, type')
import Html.Events exposing (onClick, targetValue, on)
import Signal exposing (Signal, Address)

import Http.Decorators exposing (addCacheBuster, promoteError, interpretStatus)
import Http exposing (..)


oneTask : Task RawError Response
oneTask =
addCacheBuster Http.send Http.defaultSettings
{ verb = "GET"
, headers = []
, url = Http.url "http://www.elm-lang.org/" []
, body = Http.empty
}


specialSend : Settings -> Request -> Task RawError Response
specialSend = addCacheBuster Http.send


useSpecialSend : Task RawError Response
useSpecialSend =
specialSend defaultSettings
{ verb = "GET"
, headers = []
, url = Http.url "http://github.com/" []
, body = Http.empty
}


verySpecialSend : Request -> Task Error Response
verySpecialSend = interpretStatus << addCacheBuster Http.send Http.defaultSettings


useVerySpecialSend : Task Error Response
useVerySpecialSend =
verySpecialSend
{ verb = "GET"
, headers = []
, url = Http.url "http://www.apple.com/" []
, body = Http.empty
}


lessSpecialSend : Settings -> Request -> Task Error Response
lessSpecialSend settings = interpretStatus << addCacheBuster Http.send settings


useLessSpecialSend : Task Error Response
useLessSpecialSend =
lessSpecialSend defaultSettings
{ verb = "GET"
, headers = []
, url = Http.url "http://package.elm-lang.org/" []
, body = Http.empty
}


app : App Model
app =
StartApp.start
{ init = init
, update = update
, view = view
, inputs = []
}


main : Signal Html
main = app.html


port tasks : Signal (Task.Task Never ())
port tasks = app.tasks


type alias Model =
{ message : String
}


init : (Model, Effects Action)
init = (Model "Initial state", Effects.none)


type Action
= OneTask
| SpecialSend
| VerySpecialSend
| LessSpecialSend
| HandleRawResponse (Result RawError Response)
| HandleResponse (Result Error Response)


update : Action -> Model -> (Model, Effects Action)
update action model =
case action of
OneTask ->
( { model | message = "Sending with addCacheBuster" }
, oneTask
|> toResult
|> Task.map HandleRawResponse
|> Effects.task
)

SpecialSend ->
( { model | message = "Sending with specialSend" }
, useSpecialSend
|> toResult
|> Task.map HandleRawResponse
|> Effects.task
)

VerySpecialSend ->
( { model | message = "Sending with verySpecialSend" }
, useVerySpecialSend
|> toResult
|> Task.map HandleResponse
|> Effects.task
)

LessSpecialSend ->
( { model | message = "Sending with lessSpecialSend" }
, useLessSpecialSend
|> toResult
|> Task.map HandleResponse
|> Effects.task
)

HandleRawResponse result ->
( { model | message = toString result }
, Effects.none
)

HandleResponse result ->
( { model | message = toString result }
, Effects.none
)


view : Address Action -> Model -> Html
view address model =
div []
[ button
[ onClick address OneTask ]
[ text "addCacheBuster" ]
, button
[ onClick address SpecialSend ]
[ text "specialSend" ]
, button
[ onClick address VerySpecialSend ]
[ text "verySpecialSend" ]
, button
[ onClick address LessSpecialSend ]
[ text "lessSpecialSend" ]

, h4 [] [ text "Message" ]
, div [ id "message" ] [ text model.message ]
]

20 changes: 20 additions & 0 deletions examples/elm-package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "1.0.0",
"summary": "Examples for the Http.Decorators module",
"repository": "https://github.com/rgrempel/elm-http-decoarators.git",
"license": "BSD3",
"source-directories": [
".",
"../src"
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "3.0.0 <= v < 4.0.0",
"evancz/elm-effects": "2.0.1 <= v < 3.0.0",
"evancz/elm-html": "4.0.2 <= v < 5.0.0",
"evancz/elm-http": "3.0.0 <= v < 4.0.0",
"evancz/start-app": "2.0.2 <= v < 3.0.0",
"evancz/task-tutorial": "1.0.3 <= v < 2.0.0"
},
"elm-version": "0.16.0 <= v < 0.17.0"
}
2 changes: 1 addition & 1 deletion src/Http/Decorators.elm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ addCacheBuster func settings request =
let
sendWithTime time =
func settings
{ request | url <- urlWithTime time }
{ request | url = urlWithTime time }

urlWithTime time =
-- essentially, we want to add ?cacheBuster=123482
Expand Down

0 comments on commit 4d42fb6

Please sign in to comment.