All good - phew.  Thanks Peter!  

So it turns out the urlParser you hand to Navigation.program gets invoked 
on the initial URL before the call to init happens, and the output of 
urlParser feed into init.  This was not obvious to me from the 
documentation nor the examples I found, which are more about setting the 
URL or responding to URL monkeying.

Here is the skeleton of how to do it, for anyone interested.

--bill

import Navigation

-- Test program to extract the deal value from a URL like:
--    deepfinesse.com/demo.html?deal=AQ752.KJ.843.T96

-- Model will hold the deal (eg) "AQ752.KJ.843.T96"
type alias Model = String

-- Our urlUpdate is a NO-OP as we don't care to change the URL nor respond 
to URL monkeying
main =
  Navigation.program urlParser
    { init = init
    , view = view
    , update = update
    , urlUpdate = (\_ model -> (model, Cmd.none))
    , subscriptions = subscriptions
    }

-- locRec is provided by the system and locRec.search looks like 
"?deal=AQ752.KJ.843.T96"
urlParser : Navigation.Parser String
urlParser =
  let
    -- define our parsing function
    extractDealFromUrl locRec =
      String.dropLeft 6 locRec.search
  in
    Navigation.makeParser extractDealFromUrl

-- The system calls urlParser on the initial URL and passes the result to 
init
init : String -> (Model, Cmd Msg)
init dealFromUrl =
   (dealFromUrl, Cmd.none)

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to