From 96f7d6323a1ef1f3deb253f59fe0898734951e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 5 Sep 2014 12:24:05 +0200 Subject: [PATCH] Change signature of ol.layer.Group#getLayers This commit changes the signature of ol.layer.Group#getLayers from {ol.Collection.|undefined} to {!ol.Collection.}. In this way the caller is guaranteed that getLayers returns a dereferencable object. --- src/ol/layer/layergroup.js | 8 ++++---- src/ol/map.js | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ol/layer/layergroup.js b/src/ol/layer/layergroup.js index c685a6ec2c..7338704c3e 100644 --- a/src/ol/layer/layergroup.js +++ b/src/ol/layer/layergroup.js @@ -56,7 +56,7 @@ ol.layer.Group = function(opt_options) { ol.Object.getChangeEventType(ol.layer.GroupProperty.LAYERS), this.handleLayersChanged_, false, this); - if (goog.isDef(layers)) { + if (goog.isDefAndNotNull(layers)) { if (goog.isArray(layers)) { layers = new ol.Collection(goog.array.clone(layers)); } else { @@ -145,13 +145,13 @@ ol.layer.Group.prototype.handleLayersRemove_ = function(collectionEvent) { /** - * @return {ol.Collection.|undefined} Collection of + * @return {!ol.Collection.} Collection of * {@link ol.layer.Layer layers} that are part of this group. * @observable * @api stable */ ol.layer.Group.prototype.getLayers = function() { - return /** @type {ol.Collection.|undefined} */ (this.get( + return /** @type {!ol.Collection.} */ (this.get( ol.layer.GroupProperty.LAYERS)); }; goog.exportProperty( @@ -161,7 +161,7 @@ goog.exportProperty( /** - * @param {ol.Collection.|undefined} layers Collection of + * @param {!ol.Collection.} layers Collection of * {@link ol.layer.Layer layers} that are part of this group. * @observable * @api stable diff --git a/src/ol/map.js b/src/ol/map.js index 245d40991a..8dfb3a678c 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -495,7 +495,6 @@ ol.Map.prototype.addInteraction = function(interaction) { */ ol.Map.prototype.addLayer = function(layer) { var layers = this.getLayerGroup().getLayers(); - goog.asserts.assert(goog.isDef(layers)); layers.push(layer); }; @@ -703,7 +702,7 @@ goog.exportProperty( /** * Get the collection of layers associated with this map. - * @return {ol.Collection.|undefined} Layers. + * @return {!ol.Collection.|undefined} Layers. * @api stable */ ol.Map.prototype.getLayers = function() { @@ -1147,7 +1146,6 @@ ol.Map.prototype.removeInteraction = function(interaction) { */ ol.Map.prototype.removeLayer = function(layer) { var layers = this.getLayerGroup().getLayers(); - goog.asserts.assert(goog.isDef(layers)); return layers.remove(layer); };