Created
October 23, 2018 10:15
-
-
Save arsduo/c5d30af3b6f5afefe658d2f0513b2ebe to your computer and use it in GitHub Desktop.
Elm Batched Logging Example
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
type Msg | |
= SendBatchLogEvents | |
| BatchEventLogSuccessful Int | |
type alias EventData = | |
{ message : String | |
, data : Json.Encode.Value | |
} | |
type alias Model = | |
{ events : List EventData | |
} | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.batch | |
[ Time.every (30 * Time.second) SendBatchLogEvents | |
] | |
update : Msg -> Model -> Cmd Msg | |
update msg model = | |
-- Note: if a batch call took more than 30 seconds, events could be sent more than once -- | |
-- you'd want to account for that. | |
case msg of | |
SendBatchLogEvents -> | |
-- this would generate BatchEventLogSuccessful message with the number of events logged | |
( model, LoggingApi.logBatch model.events ) | |
BatchEventLogSuccessful numberOfEventsLogged -> | |
-- now that they're it's successfully logged, drop the events | |
( { model | events = List.drop numberOfEventsLogged model.events }, Cmd.none ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment