From dc70c4376d9e4b60a6a06d61d73cd253c262afe4 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 18 Dec 2017 16:14:50 +0100 Subject: [PATCH] Named export for ol/style --- src/ol/renderer/Map.js | 5 +- src/ol/style.js | 4 +- src/ol/style/IconImage.js | 3 +- test/spec/ol/style/icon.test.js | 5 +- test/spec/ol/style/iconimagecache.test.js | 58 ++++++++++------------- 5 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/ol/renderer/Map.js b/src/ol/renderer/Map.js index 1735315d5c..e8f3c64aa2 100644 --- a/src/ol/renderer/Map.js +++ b/src/ol/renderer/Map.js @@ -9,7 +9,7 @@ import {getWidth} from '../extent.js'; import {TRUE} from '../functions.js'; import _ol_layer_Layer_ from '../layer/Layer.js'; import _ol_plugins_ from '../plugins.js'; -import _ol_style_ from '../style.js'; +import {iconImageCache} from '../style.js'; import _ol_transform_ from '../transform.js'; /** @@ -84,8 +84,7 @@ _ol_renderer_Map_.prototype.removeLayerRenderers = function() { * @private */ _ol_renderer_Map_.expireIconCache_ = function(map, frameState) { - var cache = _ol_style_.iconImageCache; - cache.expire(); + iconImageCache.expire(); }; diff --git a/src/ol/style.js b/src/ol/style.js index b9bc21cd64..e454624e89 100644 --- a/src/ol/style.js +++ b/src/ol/style.js @@ -2,11 +2,9 @@ * @module ol/style */ import IconImageCache from './style/IconImageCache.js'; -var _ol_style_ = {}; /** * The {@link ol.style.IconImageCache} for {@link ol.style.Icon} images. * @api */ -_ol_style_.iconImageCache = new IconImageCache(); -export default _ol_style_; +export var iconImageCache = new IconImageCache(); diff --git a/src/ol/style/IconImage.js b/src/ol/style/IconImage.js index ee92b98241..1174f69cd2 100644 --- a/src/ol/style/IconImage.js +++ b/src/ol/style/IconImage.js @@ -7,7 +7,7 @@ import _ol_events_ from '../events.js'; import EventTarget from '../events/EventTarget.js'; import EventType from '../events/EventType.js'; import ImageState from '../ImageState.js'; -import _ol_style_ from '../style.js'; +import {iconImageCache} from '../style.js'; /** * @constructor @@ -103,7 +103,6 @@ inherits(_ol_style_IconImage_, EventTarget); */ _ol_style_IconImage_.get = function(image, src, size, crossOrigin, imageState, color) { - var iconImageCache = _ol_style_.iconImageCache; var iconImage = iconImageCache.get(src, crossOrigin, color); if (!iconImage) { iconImage = new _ol_style_IconImage_( diff --git a/test/spec/ol/style/icon.test.js b/test/spec/ol/style/icon.test.js index fc1728fcb5..53963a513b 100644 --- a/test/spec/ol/style/icon.test.js +++ b/test/spec/ol/style/icon.test.js @@ -1,5 +1,5 @@ import {getUid} from '../../../../src/ol/index.js'; -import _ol_style_ from '../../../../src/ol/style.js'; +import {iconImageCache} from '../../../../src/ol/style.js'; import _ol_style_Icon_ from '../../../../src/ol/style/Icon.js'; import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js'; @@ -226,10 +226,9 @@ describe('ol.style.Icon', function() { it('takes the real image size', function() { // pretend that the image is already in the cache, // this image will be used for the icon. - var cache = _ol_style_.iconImageCache; var src = 'test.png'; var iconImage = new _ol_style_IconImage_(null, 'test.png', imgSize); - cache.set(src, null, null, iconImage); + iconImageCache.set(src, null, null, iconImage); var iconStyle = new _ol_style_Icon_({ src: 'test.png' diff --git a/test/spec/ol/style/iconimagecache.test.js b/test/spec/ol/style/iconimagecache.test.js index d1f2a7ded8..2d1035dd8e 100644 --- a/test/spec/ol/style/iconimagecache.test.js +++ b/test/spec/ol/style/iconimagecache.test.js @@ -1,86 +1,80 @@ import {nullFunction} from '../../../../src/ol/index.js'; import _ol_events_ from '../../../../src/ol/events.js'; -import _ol_style_ from '../../../../src/ol/style.js'; +import {iconImageCache} from '../../../../src/ol/style.js'; import _ol_style_IconImage_ from '../../../../src/ol/style/IconImage.js'; describe('ol.style.IconImageCache', function() { var originalMaxCacheSize; beforeEach(function() { - var cache = _ol_style_.iconImageCache; - cache.clear(); - originalMaxCacheSize = cache.maxCacheSize; - cache.maxCacheSize_ = 4; + iconImageCache.clear(); + originalMaxCacheSize = iconImageCache.maxCacheSize; + iconImageCache.maxCacheSize_ = 4; }); afterEach(function() { - var cache = _ol_style_.iconImageCache; - cache.maxCacheSize_ = originalMaxCacheSize; - cache.clear(); + iconImageCache.maxCacheSize_ = originalMaxCacheSize; + iconImageCache.clear(); }); describe('#expire', function() { it('expires images when expected', function() { - var cache = _ol_style_.iconImageCache; - var i, src, iconImage; for (i = 0; i < 4; ++i) { src = i + ''; iconImage = new _ol_style_IconImage_(null, src); - cache.set(src, null, null, iconImage); + iconImageCache.set(src, null, null, iconImage); } - expect(cache.cacheSize_).to.eql(4); + expect(iconImageCache.cacheSize_).to.eql(4); - cache.expire(); - expect(cache.cacheSize_).to.eql(4); + iconImageCache.expire(); + expect(iconImageCache.cacheSize_).to.eql(4); src = '4'; iconImage = new _ol_style_IconImage_(null, src); - cache.set(src, null, null, iconImage); - expect(cache.cacheSize_).to.eql(5); + iconImageCache.set(src, null, null, iconImage); + expect(iconImageCache.cacheSize_).to.eql(5); - cache.expire(); // remove '0' and '4' - expect(cache.cacheSize_).to.eql(3); + iconImageCache.expire(); // remove '0' and '4' + expect(iconImageCache.cacheSize_).to.eql(3); src = '0'; iconImage = new _ol_style_IconImage_(null, src); _ol_events_.listen(iconImage, 'change', nullFunction, false); - cache.set(src, null, null, iconImage); - expect(cache.cacheSize_).to.eql(4); + iconImageCache.set(src, null, null, iconImage); + expect(iconImageCache.cacheSize_).to.eql(4); src = '4'; iconImage = new _ol_style_IconImage_(null, src); _ol_events_.listen(iconImage, 'change', nullFunction, false); - cache.set(src, null, null, iconImage); - expect(cache.cacheSize_).to.eql(5); + iconImageCache.set(src, null, null, iconImage); + expect(iconImageCache.cacheSize_).to.eql(5); // check that '0' and '4' are not removed from the cache - cache.expire(); - expect(cache.get('0', null, null)).to.not.be(null); - expect(cache.get('4', null, null)).to.not.be(null); + iconImageCache.expire(); + expect(iconImageCache.get('0', null, null)).to.not.be(null); + expect(iconImageCache.get('4', null, null)).to.not.be(null); }); }); describe('#setSize', function() { it('sets max cache size and expires cache', function() { - var cache = _ol_style_.iconImageCache; - var i, src, iconImage; for (i = 0; i < 3; ++i) { src = i + ''; iconImage = new _ol_style_IconImage_(null, src); - cache.set(src, null, null, iconImage); + iconImageCache.set(src, null, null, iconImage); } - expect(cache.cacheSize_).to.eql(3); + expect(iconImageCache.cacheSize_).to.eql(3); - cache.setSize(2); + iconImageCache.setSize(2); - expect(cache.maxCacheSize_).to.eql(2); - expect(cache.cacheSize_).to.eql(2); + expect(iconImageCache.maxCacheSize_).to.eql(2); + expect(iconImageCache.cacheSize_).to.eql(2); }); }); });