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 PayoutListFormwitoldsz
06/16/2017, 9:42 PMWebData 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/latestwitoldsz
06/16/2017, 9:44 PMpniederw
06/16/2017, 9:55 PMscott
06/16/2017, 9:58 PMwitoldsz
06/16/2017, 9:59 PMwitoldsz
06/16/2017, 10:03 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.witoldsz
06/16/2017, 10:06 PMSuccess 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 PMscott
06/16/2017, 10:08 PMwitoldsz
06/16/2017, 10:09 PMwitoldsz
06/16/2017, 10:14 PMwitoldsz
06/16/2017, 10:15 PMwitoldsz
06/16/2017, 10:17 PMWebData alias (in Kotlin) represent a special version of RemoteData sealed class…witoldsz
06/16/2017, 10:21 PMWebData 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.witoldsz
06/16/2017, 10:39 PMsealed 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.witoldsz
06/16/2017, 10:42 PMsealed 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 AMwitoldsz
06/17/2017, 1:39 AMraulraja
06/17/2017, 11:46 AMraulraja
06/17/2017, 11:47 AMwitoldsz
06/17/2017, 12:29 PMwitoldsz
06/17/2017, 12:30 PMdarkmoon_uk
06/17/2017, 1:56 PMdarkmoon_uk
06/17/2017, 1:58 PMroberto.guerra
06/18/2017, 7:54 PM