title: In Elm, how do I fire a Cmd once a page has been routed to?
body: <p>I have an Elm SPA that has a page that includes a chart. I'm using a JS port to activate a chart.js chart. When the page is loaded, I'd like to send the chart data via the port. I'm able to wire the commands up fine on events (like a select change, for example), but am at a loss for how to get the command to fire when the page is loaded.</p>
  
  <p>I tried wiring up the command in my app's init, but of course this fires before I've retrieved my app data.</p>
  
  <p>Thanks much!</p>
  
  <p>Some sample code:
  (I'm creating the Cmd with "chart", with is the name of my port, which takes along with it chart data based on my model.)</p>
  
  <p>Main.elm</p>
  
  <pre><code>init : Result String Route -&gt; ( Model, Cmd Msg )
  init result =
      let
          currentRoute =
              Routing.routeFromResult result
      in
          ( initialModel currentRoute, Cmd.map VendorsMsg fetchAll )
  
  
  subscriptions : Model -&gt; Sub Msg
  subscriptions model =
      Sub.none
  
  
  urlUpdate : Result String Route -&gt; Model -&gt; ( Model, Cmd Msg )
  urlUpdate result model =
      let
          currentRoute =
              Routing.routeFromResult result
      in
          ( { model | route = currentRoute }, chart (computeChartData model) )
  
  
  main : Program Never
  main =
      Navigation.program Routing.parser
          { init = init
          , view = view
          , update = update
          , urlUpdate = urlUpdate
          , subscriptions = subscriptions
          }
  </code></pre>
  
  <p>Routing.elm</p>
  
  <pre><code>type Route
      = HomeRoute
      | AdminRoute
      | EditVendorRoute VendorId
      | NotFoundRoute
  
  
  matchers : Parser (Route -&gt; a) a
  matchers =
      oneOf
          [ format HomeRoute (s "")
          , format EditVendorRoute (s "admin" &lt;/&gt; int)
          , format AdminRoute (s "admin")
          ]
  
  
  hashParser : Navigation.Location -&gt; Result String Route
  hashParser location =
      location.hash
          |&gt; String.dropLeft 1
          |&gt; parse identity matchers
  
  
  parser : Navigation.Parser (Result String Route)
  parser =
      Navigation.makeParser hashParser
  
  
  routeFromResult : Result String Route -&gt; Route
  routeFromResult result =
      case result of
          Ok route -&gt;
              route
  
          Err string -&gt;
              NotFoundRoute
  </code></pre>