-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from MikePors/master
Improving support for polymorphic data types
- Loading branch information
Showing
5 changed files
with
90 additions
and
4 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
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
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,15 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
|
||
module PolymorphicData where | ||
|
||
import Servant.Elm | ||
|
||
|
||
data PolymorphicData a b = PolymorphicData a b deriving (Show, Eq) | ||
data SomeRecord = SomeRecord | ||
{ recordId :: Int | ||
, recordName :: String | ||
} deriving (Show, Eq) | ||
|
||
deriveBoth defaultOptions ''PolymorphicData | ||
deriveBoth defaultOptions ''SomeRecord |
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,43 @@ | ||
module GetPolymorphicData exposing (..) | ||
|
||
import Http | ||
import Json.Decode exposing (..) | ||
import Url.Builder | ||
|
||
type PolymorphicData a b = PolymorphicData a b | ||
type SomeRecord = SomeRecord { recordId : Int, recordname : String } | ||
|
||
jsonDecPolymorphicData : Json.Decode.Decoder a -> Json.Decode.Decoder b -> Json.Decode.Decoder (PolymorphicData a b) | ||
jsonDecPolymorphicData _ _ = Debug.todo "finish" | ||
|
||
jsonDecSomeRecord : Json.Decode.Decoder SomeRecord | ||
jsonDecSomeRecord = Debug.todo "finish" | ||
|
||
|
||
getPolymorphicData : (Result Http.Error ((PolymorphicData (List String) SomeRecord)) -> msg) -> Cmd msg | ||
getPolymorphicData toMsg = | ||
let | ||
params = | ||
List.filterMap identity | ||
(List.concat | ||
[]) | ||
in | ||
Http.request | ||
{ method = | ||
"GET" | ||
, headers = | ||
[] | ||
, url = | ||
Url.Builder.crossOrigin "" | ||
[ "polymorphicData" | ||
] | ||
params | ||
, body = | ||
Http.emptyBody | ||
, expect = | ||
Http.expectJson toMsg ((jsonDecPolymorphicData (Json.Decode.list (Json.Decode.string))) jsonDecSomeRecord) | ||
, timeout = | ||
Nothing | ||
, tracker = | ||
Nothing | ||
} |