From 75aabc982fb1f2b80c424d2d9bd10a123ffbc612 Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Tue, 2 Jun 2015 19:51:29 +0100 Subject: [PATCH] Use reactive-var for mapBounds object storing. --- .meteor/packages | 1 + client/templates/locations/locations_page.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index 5b53df4..166426a 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -17,3 +17,4 @@ aldeed:autoform alanning:roles accounts-admin-ui-bootstrap-3 jeremy:geocomplete +reactive-var diff --git a/client/templates/locations/locations_page.js b/client/templates/locations/locations_page.js index 3d29cfe..106b1f8 100644 --- a/client/templates/locations/locations_page.js +++ b/client/templates/locations/locations_page.js @@ -5,12 +5,12 @@ Template.locationsPage.helpers({ }); Template.locationsPage.onRendered(function() { - var self = this; + var instance = this; this.autorun(function(c) { if (GoogleMaps.loaded()) { - var searchLocationInput = self.$('.search-locations-input'); + var searchLocationInput = instance.$('.search-locations-input'); var mapProperties = { - map: self.$('.map-container'), + map: instance.$('.map-container'), mapOptions: { zoom: 12, scrollwheel: true, @@ -31,7 +31,7 @@ Template.locationsPage.onRendered(function() { var ne = bounds.getNorthEast(); var sw = bounds.getSouthWest(); var boundsObject = {ne: {lng: ne.lng(), lat: ne.lat()}, sw: {lng: sw.lng(), lat: sw.lat()}}; - Session.set('mapBounds', boundsObject); + instance.mapBounds.set(boundsObject); } }); c.stop(); @@ -40,14 +40,19 @@ Template.locationsPage.onRendered(function() { }); Template.locationsPage.onCreated(function() { + // Init Googlemaps. GoogleMaps.load({ libraries: 'places' }); var instance = this; + + // Init reactive var. + instance.mapBounds = new ReactiveVar({}); + instance.autorun(function () { // Subscribe to the locations publication. - var subscription = instance.subscribe('locations', Session.get('mapBounds')); + var subscription = instance.subscribe('locations', instance.mapBounds.get()); }); // Locations cursor. instance.locations = function() {