Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noredink/elm-sweet-poll
https://github.com/noredink/elm-sweet-poll
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/noredink/elm-sweet-poll
- Owner: NoRedInk
- License: bsd-3-clause
- Created: 2016-04-28T23:40:30.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-16T21:56:02.000Z (over 5 years ago)
- Last Synced: 2024-05-08T23:24:52.531Z (8 months ago)
- Language: Elm
- Size: 39.1 KB
- Stars: 4
- Watchers: 6
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm Sweet Poll
A library for HTTP polling, which automatically backs off when the server
response doesn't change.Follows the Elm architecture.
## Example
```
import Html
import Json.Decode as Decode
import SweetPolltype alias Model =
{ data : Maybe String
, error : Maybe String
, sweetPoll : SweetPoll.PollingState String
}main : Program Never Model (SweetPoll.Msg String)
main =
let
config =
SweetPoll.defaultConfig
(Decode.field "fulldate" Decode.string)
-- From http://tiny.cc/currenttime
"https://script.google.com/macros/s/AKfycbyd5AcbAnWi2Yn0xhFRbyzS4qMq1VucMVgVvhul5XqS9HkAyJY/exec"( initialPollingState, initialCmd ) =
SweetPoll.init config
in
Html.program
{ init =
( { data = Nothing
, error = Nothing
, sweetPoll = initialPollingState
}
, initialCmd
)
, update =
\action model ->
case SweetPoll.update config action model.sweetPoll of
{ newState, newData, error, cmd } ->
( { sweetPoll = newState
, data = newData
, error = error |> Maybe.map toString
}
, cmd
)
, view =
\model ->
Html.div []
[ Html.text ("new data: " ++ toString model.data)
, Html.hr [] []
, Html.text ("error: " ++ toString model.error)
]
, subscriptions = \_ -> Sub.none
}
```This example is also included in the examples folder in the source code. Build with:
```
> cd elm-sweet-poll
> ./build_all.sh
> open examples/index.html```