Skip to content

Instantly share code, notes, and snippets.

@toretore
Created November 2, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toretore/548010be57a8fd246b46e8fea0d474b4 to your computer and use it in GitHub Desktop.
Save toretore/548010be57a8fd246b46e8fea0d474b4 to your computer and use it in GitHub Desktop.
module Location
type Location
= None
| SelectCountry (List Country)
| CountrySelected Country
| SelectRegion Country (List Region)
| RegionSelected Country Region
| SelectCity Country Region (List City)
| Complete Country Region City
type Msg
= CountriesLoaded (List Country)
| CountrySelected Country
| RegionsLoaded Country (List Region)
| RegionSelected Country Region
| CitiesLoaded Country Region (List City)
| CitySelected Country Region City
init : (None, getCountries)
forward : Msg -> Location -> (Location, Cmd Msg)
forward msg location =
case msg of
CountriesLoaded cs -> (SelectCountry cs, Cmd.none)
CountrySelected c -> (CountrySelected c, getRegions c)
RegionsLoaded c rs -> (SelectRegion c rs, Cmd.none)
RegionSelected c r -> (RegionSelected c r, getCities c r)
CitiesLoaded c r cs -> (SelectCity c r cs, Cmd.none)
CitySelected co r ci -> (Complete co r ci)
getCountries : Cmd (CountriesLoaded (List Country))
getRegions : Country -> Cmd (RegionsLoaded Country (List Region))
getCities : Country -> Region -> Cmd (CitiesLoaded Country Region (List City))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment