I use the following to query a server-side list of transit stops which returns sorted based on proximity to the user’s position:
getMeteorData() {
var data = {}
var options = {}
options.limit = this.state.limit
var position = {}
if(Meteor.settings && Meteor.settings.public && Meteor.settings.public.defaultPosition)
position = Meteor.settings.public.defaultPosition
if(Meteor.isClient)
position = Geolocation.latLng()
options.position = position
data.handle = Meteor.subscribe("stops", options)
data.ready = data.handle.ready()
data.stops = Stops.find().fetch().map(function(stop) {
stop.id = stop._id
return stop
})
return data
},
This sets a default position so the map rendering starts out sensibly, then snaps to the user’s current position when or if it arrives. Unfortunately, the old subscription is still active, meaning the user gets their nearest stops along with those of the previous position.
What I’d like to do is stop the old subscription handle when the position changes. Unfortunately, when I do this in getMeteorData it triggers an infinite loop and nothing updates. Maybe this is because I’m storing the handle in data
, but I’ve also tried:
handle: null,
getMeteorData() {
this.handle = Meteor.subscribe(...)
},
And that, too, triggers an infinite loop where nothing renders. Interestingly enough, I do get one server-side render of the data. The problem seems to be on subsequent invalidations/rerenders, and I can’t think of how to accomplish this without triggering a loop.
Thanks.