Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 117be87

Browse files
committed
fix(markers-parent-model events): internal events are not getting unhooked; added saftey check
issue /#1448
1 parent cf178c8 commit 117be87

21 files changed

+121
-112
lines changed

dist/angular-google-maps-street-view.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-google-maps 2.1.5 2015-08-23
1+
/*! angular-google-maps 2.1.5 2015-08-24
22
* AngularJS directives for Google Maps
33
* git: https://github.com/angular-ui/angular-google-maps.git
44
*/
@@ -538,14 +538,16 @@ return UUID;
538538
}
539539
},
540540
removeEvents: function(listeners) {
541+
var key, l;
541542
if (!listeners) {
542543
return;
543544
}
544-
return listeners.forEach(function(l) {
545+
for (key in listeners) {
546+
l = listeners[key];
545547
if (l) {
546-
return google.maps.event.removeListener(l);
548+
google.maps.event.removeListener(l);
547549
}
548-
});
550+
}
549551
}
550552
};
551553
}

dist/angular-google-maps-street-view.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps-street-view_dev_mapped.js

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps-street-view_dev_mapped.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps-street-view_dev_mapped.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps-street-view_dev_mapped.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps.js

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-google-maps 2.1.5 2015-08-23
1+
/*! angular-google-maps 2.1.5 2015-08-24
22
* AngularJS directives for Google Maps
33
* git: https://github.com/angular-ui/angular-google-maps.git
44
*/
@@ -811,14 +811,16 @@ Nicholas McCready - https://twitter.com/nmccready
811811
}
812812
},
813813
removeEvents: function(listeners) {
814+
var key, l;
814815
if (!listeners) {
815816
return;
816817
}
817-
return listeners.forEach(function(l) {
818+
for (key in listeners) {
819+
l = listeners[key];
818820
if (l) {
819-
return google.maps.event.removeListener(l);
821+
google.maps.event.removeListener(l);
820822
}
821-
});
823+
}
822824
}
823825
};
824826
}
@@ -1847,7 +1849,7 @@ Nicholas McCready - https://twitter.com/nmccready
18471849
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
18481850

18491851
angular.module('uiGmapgoogle-maps.directives.api.managers').factory('uiGmapClustererMarkerManager', [
1850-
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', function($log, FitHelper, PropMap) {
1852+
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', 'uiGmapEventsHelper', function($log, FitHelper, PropMap, EventsHelper) {
18511853
var ClustererMarkerManager;
18521854
ClustererMarkerManager = (function() {
18531855
ClustererMarkerManager.type = 'ClustererMarkerManager';
@@ -1862,6 +1864,7 @@ Nicholas McCready - https://twitter.com/nmccready
18621864
this.getGMarkers = bind(this.getGMarkers, this);
18631865
this.fit = bind(this.fit, this);
18641866
this.destroy = bind(this.destroy, this);
1867+
this.attachEvents = bind(this.attachEvents, this);
18651868
this.clear = bind(this.clear, this);
18661869
this.draw = bind(this.draw, this);
18671870
this.removeMany = bind(this.removeMany, this);
@@ -1936,13 +1939,14 @@ Nicholas McCready - https://twitter.com/nmccready
19361939

19371940
ClustererMarkerManager.prototype.attachEvents = function(options, optionsName) {
19381941
var eventHandler, eventName, results;
1942+
this.listeners = [];
19391943
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
19401944
results = [];
19411945
for (eventName in options) {
19421946
eventHandler = options[eventName];
19431947
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
19441948
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
1945-
results.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName]));
1949+
results.push(this.listeners.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName])));
19461950
} else {
19471951
results.push(void 0);
19481952
}
@@ -1951,25 +1955,13 @@ Nicholas McCready - https://twitter.com/nmccready
19511955
}
19521956
};
19531957

1954-
ClustererMarkerManager.prototype.clearEvents = function(options, optionsName) {
1955-
var eventHandler, eventName, results;
1956-
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
1957-
results = [];
1958-
for (eventName in options) {
1959-
eventHandler = options[eventName];
1960-
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
1961-
$log.info(optionsName + ": Clearing event: " + eventName + " to clusterer");
1962-
results.push(google.maps.event.clearListeners(this.clusterer, eventName));
1963-
} else {
1964-
results.push(void 0);
1965-
}
1966-
}
1967-
return results;
1968-
}
1958+
ClustererMarkerManager.prototype.clearEvents = function() {
1959+
EventsHelper.removeEvents(this.listeners);
1960+
return this.listeners = [];
19691961
};
19701962

19711963
ClustererMarkerManager.prototype.destroy = function() {
1972-
this.clearEvents(this.opt_events, 'opt_events');
1964+
this.clearEvents();
19731965
return this.clear();
19741966
};
19751967

@@ -2242,19 +2234,15 @@ Nicholas McCready - https://twitter.com/nmccready
22422234
};
22432235

22442236
SpiderfierMarkerManager.prototype.clearEvents = function(options, optionsName) {
2245-
var eventHandler, eventName, results;
2237+
var eventHandler, eventName;
22462238
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
2247-
results = [];
22482239
for (eventName in options) {
22492240
eventHandler = options[eventName];
22502241
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
22512242
$log.info(optionsName + ": Clearing event: " + eventName + " to markerSpiderfier");
2252-
results.push(this.markerSpiderfier.clearListeners(eventName));
2253-
} else {
2254-
results.push(void 0);
2243+
this.markerSpiderfier.clearListeners(eventName);
22552244
}
22562245
}
2257-
return results;
22582246
}
22592247
};
22602248

@@ -4720,6 +4708,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
47204708
MarkersParentModel.include(ModelsWatcher);
47214709

47224710
function MarkersParentModel(scope, element, attrs, map) {
4711+
this.maybeExecMappedEvent = bind(this.maybeExecMappedEvent, this);
47234712
this.onDestroy = bind(this.onDestroy, this);
47244713
this.newChildMarker = bind(this.newChildMarker, this);
47254714
this.pieceMeal = bind(this.pieceMeal, this);
@@ -4991,7 +4980,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
49914980
}
49924981
}, _async.chunkSizeFrom(_this.scope.cleanchunk, false)).then(function() {
49934982
if (_this.gManager != null) {
4994-
_this.gManager.clear();
4983+
_this.gManager.destroy();
49954984
}
49964985
_this.plurals.removeAll();
49974986
if (_this.plurals !== _this.scope.plurals) {
@@ -5005,6 +4994,9 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
50054994

50064995
MarkersParentModel.prototype.maybeExecMappedEvent = function(group, fnName) {
50074996
var pair, typeEvents;
4997+
if (this.scope.$$destroyed) {
4998+
return;
4999+
}
50085000
typeEvents = this.scope.typeEvents || this.scope.clusterEvents;
50095001
if (_.isFunction(typeEvents != null ? typeEvents[fnName] : void 0)) {
50105002
pair = this.mapTypeToPlurals(group);
@@ -5015,7 +5007,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
50155007
};
50165008

50175009
MarkersParentModel.prototype.mapTypeToPlurals = function(group) {
5018-
var arrayToMap, mapped;
5010+
var arrayToMap, mapped, ref;
50195011
if (_.isArray(group)) {
50205012
arrayToMap = group;
50215013
} else if (_.isFunction(group.getMarkers)) {
@@ -5025,11 +5017,15 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
50255017
$log.error("Unable to map event as we cannot find the array group to map");
50265018
return;
50275019
}
5028-
mapped = arrayToMap.map((function(_this) {
5029-
return function(g) {
5030-
return _this.scope.plurals.get(g.key).model;
5031-
};
5032-
})(this));
5020+
if ((ref = this.scope.plurals.values()) != null ? ref.length : void 0) {
5021+
mapped = arrayToMap.map((function(_this) {
5022+
return function(g) {
5023+
return _this.scope.plurals.get(g.key).model;
5024+
};
5025+
})(this));
5026+
} else {
5027+
mapped = [];
5028+
}
50335029
return {
50345030
cluster: group,
50355031
mapped: mapped,

dist/angular-google-maps.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/angular-google-maps_dev_mapped.js

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! angular-google-maps 2.1.5 2015-08-23
1+
/*! angular-google-maps 2.1.5 2015-08-24
22
* AngularJS directives for Google Maps
33
* git: https://github.com/angular-ui/angular-google-maps.git
44
*/
@@ -811,14 +811,16 @@ Nicholas McCready - https://twitter.com/nmccready
811811
}
812812
},
813813
removeEvents: function(listeners) {
814+
var key, l;
814815
if (!listeners) {
815816
return;
816817
}
817-
return listeners.forEach(function(l) {
818+
for (key in listeners) {
819+
l = listeners[key];
818820
if (l) {
819-
return google.maps.event.removeListener(l);
821+
google.maps.event.removeListener(l);
820822
}
821-
});
823+
}
822824
}
823825
};
824826
}
@@ -1847,7 +1849,7 @@ Nicholas McCready - https://twitter.com/nmccready
18471849
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
18481850

18491851
angular.module('uiGmapgoogle-maps.directives.api.managers').factory('uiGmapClustererMarkerManager', [
1850-
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', function($log, FitHelper, PropMap) {
1852+
'uiGmapLogger', 'uiGmapFitHelper', 'uiGmapPropMap', 'uiGmapEventsHelper', function($log, FitHelper, PropMap, EventsHelper) {
18511853
var ClustererMarkerManager;
18521854
ClustererMarkerManager = (function() {
18531855
ClustererMarkerManager.type = 'ClustererMarkerManager';
@@ -1862,6 +1864,7 @@ Nicholas McCready - https://twitter.com/nmccready
18621864
this.getGMarkers = bind(this.getGMarkers, this);
18631865
this.fit = bind(this.fit, this);
18641866
this.destroy = bind(this.destroy, this);
1867+
this.attachEvents = bind(this.attachEvents, this);
18651868
this.clear = bind(this.clear, this);
18661869
this.draw = bind(this.draw, this);
18671870
this.removeMany = bind(this.removeMany, this);
@@ -1936,13 +1939,14 @@ Nicholas McCready - https://twitter.com/nmccready
19361939

19371940
ClustererMarkerManager.prototype.attachEvents = function(options, optionsName) {
19381941
var eventHandler, eventName, results;
1942+
this.listeners = [];
19391943
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
19401944
results = [];
19411945
for (eventName in options) {
19421946
eventHandler = options[eventName];
19431947
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
19441948
$log.info(optionsName + ": Attaching event: " + eventName + " to clusterer");
1945-
results.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName]));
1949+
results.push(this.listeners.push(google.maps.event.addListener(this.clusterer, eventName, options[eventName])));
19461950
} else {
19471951
results.push(void 0);
19481952
}
@@ -1951,25 +1955,13 @@ Nicholas McCready - https://twitter.com/nmccready
19511955
}
19521956
};
19531957

1954-
ClustererMarkerManager.prototype.clearEvents = function(options, optionsName) {
1955-
var eventHandler, eventName, results;
1956-
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
1957-
results = [];
1958-
for (eventName in options) {
1959-
eventHandler = options[eventName];
1960-
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
1961-
$log.info(optionsName + ": Clearing event: " + eventName + " to clusterer");
1962-
results.push(google.maps.event.clearListeners(this.clusterer, eventName));
1963-
} else {
1964-
results.push(void 0);
1965-
}
1966-
}
1967-
return results;
1968-
}
1958+
ClustererMarkerManager.prototype.clearEvents = function() {
1959+
EventsHelper.removeEvents(this.listeners);
1960+
return this.listeners = [];
19691961
};
19701962

19711963
ClustererMarkerManager.prototype.destroy = function() {
1972-
this.clearEvents(this.opt_events, 'opt_events');
1964+
this.clearEvents();
19731965
return this.clear();
19741966
};
19751967

@@ -2242,19 +2234,15 @@ Nicholas McCready - https://twitter.com/nmccready
22422234
};
22432235

22442236
SpiderfierMarkerManager.prototype.clearEvents = function(options, optionsName) {
2245-
var eventHandler, eventName, results;
2237+
var eventHandler, eventName;
22462238
if (angular.isDefined(options) && (options != null) && angular.isObject(options)) {
2247-
results = [];
22482239
for (eventName in options) {
22492240
eventHandler = options[eventName];
22502241
if (options.hasOwnProperty(eventName) && angular.isFunction(options[eventName])) {
22512242
$log.info(optionsName + ": Clearing event: " + eventName + " to markerSpiderfier");
2252-
results.push(this.markerSpiderfier.clearListeners(eventName));
2253-
} else {
2254-
results.push(void 0);
2243+
this.markerSpiderfier.clearListeners(eventName);
22552244
}
22562245
}
2257-
return results;
22582246
}
22592247
};
22602248

@@ -4720,6 +4708,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
47204708
MarkersParentModel.include(ModelsWatcher);
47214709

47224710
function MarkersParentModel(scope, element, attrs, map) {
4711+
this.maybeExecMappedEvent = bind(this.maybeExecMappedEvent, this);
47234712
this.onDestroy = bind(this.onDestroy, this);
47244713
this.newChildMarker = bind(this.newChildMarker, this);
47254714
this.pieceMeal = bind(this.pieceMeal, this);
@@ -4991,7 +4980,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
49914980
}
49924981
}, _async.chunkSizeFrom(_this.scope.cleanchunk, false)).then(function() {
49934982
if (_this.gManager != null) {
4994-
_this.gManager.clear();
4983+
_this.gManager.destroy();
49954984
}
49964985
_this.plurals.removeAll();
49974986
if (_this.plurals !== _this.scope.plurals) {
@@ -5005,6 +4994,9 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
50054994

50064995
MarkersParentModel.prototype.maybeExecMappedEvent = function(group, fnName) {
50074996
var pair, typeEvents;
4997+
if (this.scope.$$destroyed) {
4998+
return;
4999+
}
50085000
typeEvents = this.scope.typeEvents || this.scope.clusterEvents;
50095001
if (_.isFunction(typeEvents != null ? typeEvents[fnName] : void 0)) {
50105002
pair = this.mapTypeToPlurals(group);
@@ -5015,7 +5007,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
50155007
};
50165008

50175009
MarkersParentModel.prototype.mapTypeToPlurals = function(group) {
5018-
var arrayToMap, mapped;
5010+
var arrayToMap, mapped, ref;
50195011
if (_.isArray(group)) {
50205012
arrayToMap = group;
50215013
} else if (_.isFunction(group.getMarkers)) {
@@ -5025,11 +5017,15 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
50255017
$log.error("Unable to map event as we cannot find the array group to map");
50265018
return;
50275019
}
5028-
mapped = arrayToMap.map((function(_this) {
5029-
return function(g) {
5030-
return _this.scope.plurals.get(g.key).model;
5031-
};
5032-
})(this));
5020+
if ((ref = this.scope.plurals.values()) != null ? ref.length : void 0) {
5021+
mapped = arrayToMap.map((function(_this) {
5022+
return function(g) {
5023+
return _this.scope.plurals.get(g.key).model;
5024+
};
5025+
})(this));
5026+
} else {
5027+
mapped = [];
5028+
}
50335029
return {
50345030
cluster: group,
50355031
mapped: mapped,

dist/angular-google-maps_dev_mapped.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)