Note that there are some explanatory texts on larger screens.

plurals
  1. POHandeling an async call before transitioning to a new route
    text
    copied!<p>I want to get the users Geolocation. Once I get the coordinates, I want to load Records based on that Geolocation. If there is more than 1 result, show an index page, </p> <pre><code>LHW.Store = DS.Store.extend revision: 11 adapter: DS.RESTAdapter DS.RESTAdapter.reopen namespace: 'api' LHW.Company = DS.Model.extend name: DS.attr 'string' address: DS.attr 'string' city: DS.attr 'string' LHW.IndexRoute = Ember.Route.extend setupController: (controller, route) -&gt; # get Geolocation _route = @ navigator.geolocation.getCurrentPosition ((location) -&gt; #success _route.geoLocation(location) ), (error) -&gt; #error switch(error.code) when error.PERMISSION_DENIED then console.log "User denied the request for Geolocation." when error.POSITION_UNAVAILABLE then console.log "Location information is unavailable." when error.TIMEOUT then console.log "The request to get user location timed out." when error.UNKNOWN_ERROR then console.log "An unknown error occurred." geoLocation: (location) -&gt; _route = @ @get('store').findQuery('company',{longitude: location.coords.longitude, latitude: location.coords.latitude}).then ((data) =&gt; _route.controllerFor('companies').set('content', data) if data.get('length') &gt; 1 _route.transitionTo('companies'); ), (error) -&gt; console.log "error" LHW.CompaniesRoute = Ember.Route.extend() LHW.IndexController = Ember.ArrayController.extend beforeModel: -&gt; console.log 'before' </code></pre> <p>So this is what I got now. But this has a few problems</p> <ol> <li>If you go to /companies instead of / It skips the geolocation check. But if I move the geolocation to the companies route, then what is the page the users sees while geolocation is getting fetched? </li> <li>Creating a switch and checking the length in a route, feels a bit dirty, imo the Companyroute should respond to that</li> </ol> <p>So this is mostly a flow issue I can't wrap my head around and the async geolocation isn't making things easier...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload