Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4852105
commit c02b6b9
Showing
3 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Database.Sync.Status exposing (Status(..), decoder) | ||
|
||
import Json.Decode as Decode exposing (Decoder) | ||
|
||
|
||
type Status | ||
= Active | ||
| Idle | ||
| Error String | ||
|
||
|
||
decoder : Decoder Status | ||
decoder = | ||
Decode.andThen | ||
(\event -> | ||
case event of | ||
"active" -> | ||
Decode.succeed Active | ||
|
||
"paused" -> | ||
Decode.succeed Idle | ||
|
||
"error" -> | ||
Decode.map Error (Decode.field "message" Decode.string) | ||
|
||
"complete" -> | ||
Decode.succeed Idle | ||
|
||
_ -> | ||
Decode.fail ("I don't know how to deal with a '" ++ event ++ "' event") | ||
) | ||
(Decode.field "event" Decode.string) |
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
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