witoldsz
06/16/2017, 9:07 PMscott
06/16/2017, 9:19 PMroberto.guerra
06/16/2017, 9:30 PMwitoldsz
06/16/2017, 9:40 PMtype alias Model =
{ page : Page
, csrfToken : String
}
type Page
= NoPage
| AnnouncementListPage (WebData (List Announcement))
| AnnouncementItemPage (WebData AnnouncementForm)
| PayoutCancelledListPage PayoutCancelledListForm
| PayoutListPage PayoutListForm
WebData
comes from a library, it looks like this:
type RemoteData e a
= NotAsked
| Loading
| Failure e
| Success a
type alias WebData a =
RemoteData Http.Error a
reference: http://package.elm-lang.org/packages/ohanhi/remotedata-http/latestpniederw
06/16/2017, 9:55 PMscott
06/16/2017, 9:58 PMwitoldsz
06/16/2017, 9:59 PMWebData
could not be modeled with enum
, because enums are all singletons. NotAsked
and Loading
would work, but Failure …
and Success a
are tagged values.scott
06/16/2017, 10:04 PMwitoldsz
06/16/2017, 10:04 PMSuccess "Hello from Backend"
produces an instance of RemoteData
.Success
would be a constructor with one argument, but in the same time Loading
is… just a Loading
. Each Loading
is equal to any other one.scott
06/16/2017, 10:07 PMwitoldsz
06/16/2017, 10:09 PMWebData
alias (in Kotlin) represent a special version of RemoteData
sealed class…WebData e a
, e
stands for any error, a
stands for, well anything (successful response). The WebData
is a RemoteData with e
error of type Http.Error
and a
is left as-is.sealed class RemoteData<E,A>
object notAsked : RemoteData<Any,Any>()
object loading : RemoteData<Any,Any>()
data class Failure<Any>(val error: Any) : RemoteData<Any,Any>()
data class Success(val success: Any) : RemoteData<Any,Any>()
Does not looks OK thogh, the <E,A>
cannot be used in Failure
and Success
, compiler complains it does not know what E and A are.sealed class RemoteData<E,A>
object notAsked : RemoteData<Any,Any>()
object loading : RemoteData<Any,Any>()
data class Failure<E>(val error: E) : RemoteData<E,Any>()
data class Success<A>(val success: A) : RemoteData<Any,A>()
class HttpError {/*whatever*/}
typealias WebData<A> = RemoteData<HttpError, A>
I am not sure it it's working, it just compiles…pniederw
06/16/2017, 10:47 PMwitoldsz
06/16/2017, 11:08 PMobject notAsked : RemoteData<Any,Any>()
object loading : RemoteData<Any,Any>()
data class Failure<E>(val error: E) : RemoteData<E,Any>()
data class Success<A>(val success: A) : RemoteData<Any,A>()
Should be:
object notAsked : RemoteData<Nothing,Nothing>()
object loading : RemoteData<Nothing,Nothing>()
data class Failure<E>(val error: E) : RemoteData<E,Nothing>()
data class Success<A>(val success: A) : RemoteData<Nothing,A>()
It's even more to write, though 😕cedric
06/16/2017, 11:43 PMwitoldsz
06/17/2017, 1:26 AMraulraja
06/17/2017, 11:46 AMwitoldsz
06/17/2017, 12:29 PMdarkmoon_uk
06/17/2017, 1:56 PMroberto.guerra
06/18/2017, 7:54 PM