From 32f331c18983260fde74a4dad0519caa7cedb1f5 Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Mon, 26 Jun 2017 12:19:58 -0400 Subject: [PATCH] Mark private SourceCache methods with leading '_' --- src/source/source_cache.js | 42 ++++++++++++------------- test/unit/source/source_cache.test.js | 44 +++++++++++++-------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/source/source_cache.js b/src/source/source_cache.js index d267160922f..4082153d54f 100644 --- a/src/source/source_cache.js +++ b/src/source/source_cache.js @@ -50,7 +50,7 @@ class SourceCache extends Evented { this._source = Source.create(id, options, dispatcher, this); this._tiles = {}; - this._cache = new Cache(0, this.unloadTile.bind(this)); + this._cache = new Cache(0, this._unloadTile.bind(this)); this._timers = {}; this._cacheTimers = {}; this._maxTileCacheSize = null; @@ -97,16 +97,16 @@ class SourceCache extends Evented { return this._source; } - loadTile(tile, callback) { + _loadTile(tile, callback) { return this._source.loadTile(tile, callback); } - unloadTile(tile) { + _unloadTile(tile) { if (this._source.unloadTile) return this._source.unloadTile(tile); } - abortTile(tile) { + _abortTile(tile) { if (this._source.abortTile) return this._source.abortTile(tile); } @@ -141,11 +141,11 @@ class SourceCache extends Evented { reload() { this._cache.reset(); for (const i in this._tiles) { - this.reloadTile(i, 'reloading'); + this._reloadTile(i, 'reloading'); } } - reloadTile(id, state) { + _reloadTile(id, state) { const tile = this._tiles[id]; // this potentially does not address all underlying @@ -161,7 +161,7 @@ class SourceCache extends Evented { tile.state = state; } - this.loadTile(tile, this._tileLoaded.bind(this, tile, id, state)); + this._loadTile(tile, this._tileLoaded.bind(this, tile, id, state)); } _tileLoaded(tile, id, previousState, err) { @@ -221,7 +221,7 @@ class SourceCache extends Evented { * @returns {boolean} whether the operation was complete * @private */ - findLoadedChildren(coord, maxCoveringZoom, retain) { + _findLoadedChildren(coord, maxCoveringZoom, retain) { let found = false; for (const id in this._tiles) { @@ -351,7 +351,7 @@ class SourceCache extends Evented { for (i = 0; i < visibleCoords.length; i++) { coord = visibleCoords[i]; - tile = this.addTile(coord); + tile = this._addTile(coord); retain[coord.id] = true; @@ -360,10 +360,10 @@ class SourceCache extends Evented { // The tile we require is not yet loaded. // Retain child or parent tiles that cover the same area. - if (!this.findLoadedChildren(coord, maxCoveringZoom, retain)) { + if (!this._findLoadedChildren(coord, maxCoveringZoom, retain)) { parentTile = this.findLoadedParent(coord, minCoveringZoom, retain); if (parentTile) { - this.addTile(parentTile.coord); + this._addTile(parentTile.coord); } } } @@ -383,12 +383,12 @@ class SourceCache extends Evented { // fadeEndTime is in the future, then this tile is still // fading in. Find tiles to cross-fade with it. if (typeof tile.fadeEndTime === 'undefined' || tile.fadeEndTime >= Date.now()) { - if (this.findLoadedChildren(coord, maxCoveringZoom, retain)) { + if (this._findLoadedChildren(coord, maxCoveringZoom, retain)) { retain[id] = true; } parentTile = this.findLoadedParent(coord, minCoveringZoom, parentsForFading); if (parentTile) { - this.addTile(parentTile.coord); + this._addTile(parentTile.coord); } } } @@ -408,7 +408,7 @@ class SourceCache extends Evented { // Remove the tiles we don't need anymore. const remove = util.keysDifference(this._tiles, retain); for (i = 0; i < remove.length; i++) { - this.removeTile(+remove[i]); + this._removeTile(+remove[i]); } } @@ -418,7 +418,7 @@ class SourceCache extends Evented { * @returns {Tile} the added Tile. * @private */ - addTile(tileCoord) { + _addTile(tileCoord) { let tile = this._tiles[tileCoord.id]; if (tile) return tile; @@ -438,7 +438,7 @@ class SourceCache extends Evented { const zoom = tileCoord.z; const overscaling = zoom > this._source.maxzoom ? Math.pow(2, zoom - this._source.maxzoom) : 1; tile = new Tile(tileCoord, this._source.tileSize * overscaling, this._source.maxzoom); - this.loadTile(tile, this._tileLoaded.bind(this, tile, tileCoord.id, tile.state)); + this._loadTile(tile, this._tileLoaded.bind(this, tile, tileCoord.id, tile.state)); } tile.uses++; @@ -452,7 +452,7 @@ class SourceCache extends Evented { const expiryTimeout = tile.getExpiryTimeout(); if (expiryTimeout) { this._timers[id] = setTimeout(() => { - this.reloadTile(id, 'expired'); + this._reloadTile(id, 'expired'); this._timers[id] = undefined; }, expiryTimeout); } @@ -474,7 +474,7 @@ class SourceCache extends Evented { * @returns {undefined} nothing * @private */ - removeTile(id) { + _removeTile(id) { const tile = this._tiles[id]; if (!tile) return; @@ -497,8 +497,8 @@ class SourceCache extends Evented { this._setCacheInvalidationTimer(wrappedId, tile); } else { tile.aborted = true; - this.abortTile(tile); - this.unloadTile(tile); + this._abortTile(tile); + this._unloadTile(tile); } } @@ -508,7 +508,7 @@ class SourceCache extends Evented { */ clearTiles() { for (const id in this._tiles) - this.removeTile(id); + this._removeTile(id); this._cache.reset(); } diff --git a/test/unit/source/source_cache.test.js b/test/unit/source/source_cache.test.js index 65d56818997..96c12344c9f 100644 --- a/test/unit/source/source_cache.test.js +++ b/test/unit/source/source_cache.test.js @@ -77,7 +77,7 @@ test('SourceCache#addTile', (t) => { } }); sourceCache.onAdd(); - sourceCache.addTile(coord); + sourceCache._addTile(coord); }); t.test('adds tile when uncached', (t) => { @@ -89,7 +89,7 @@ test('SourceCache#addTile', (t) => { t.end(); }); sourceCache.onAdd(); - sourceCache.addTile(coord); + sourceCache._addTile(coord); }); t.test('uses cached tile', (t) => { @@ -110,9 +110,9 @@ test('SourceCache#addTile', (t) => { tr.width = 512; tr.height = 512; sourceCache.updateCacheSize(tr); - sourceCache.addTile(coord); - sourceCache.removeTile(coord.id); - sourceCache.addTile(coord); + sourceCache._addTile(coord); + sourceCache._removeTile(coord.id); + sourceCache._addTile(coord); t.equal(load, 1); t.equal(add, 1); @@ -132,7 +132,7 @@ test('SourceCache#addTile', (t) => { sourceCache._setCacheInvalidationTimer = (id) => { sourceCache._cacheTimers[id] = setTimeout(() => {}, 0); }; - sourceCache.loadTile = (tile, callback) => { + sourceCache._loadTile = (tile, callback) => { tile.state = 'loaded'; tile.getExpiryTimeout = () => time; sourceCache._setTileReloadTimer(coord.id, tile); @@ -148,17 +148,17 @@ test('SourceCache#addTile', (t) => { t.notOk(sourceCache._timers[id]); t.notOk(sourceCache._cacheTimers[id]); - sourceCache.addTile(coord); + sourceCache._addTile(coord); t.ok(sourceCache._timers[id]); t.notOk(sourceCache._cacheTimers[id]); - sourceCache.removeTile(coord.id); + sourceCache._removeTile(coord.id); t.notOk(sourceCache._timers[id]); t.ok(sourceCache._cacheTimers[id]); - sourceCache.addTile(coord); + sourceCache._addTile(coord); t.ok(sourceCache._timers[id]); t.notOk(sourceCache._cacheTimers[id]); @@ -180,8 +180,8 @@ test('SourceCache#addTile', (t) => { }) .on('dataloading', () => { add++; }); - const t1 = sourceCache.addTile(coord); - const t2 = sourceCache.addTile(new TileCoord(0, 0, 0, 1)); + const t1 = sourceCache._addTile(coord); + const t2 = sourceCache._addTile(new TileCoord(0, 0, 0, 1)); t.equal(load, 2); t.equal(add, 2); @@ -197,9 +197,9 @@ test('SourceCache#removeTile', (t) => { t.test('removes tile', (t) => { const coord = new TileCoord(0, 0, 0); const sourceCache = createSourceCache({}); - sourceCache.addTile(coord); + sourceCache._addTile(coord); sourceCache.on('data', ()=> { - sourceCache.removeTile(coord.id); + sourceCache._removeTile(coord.id); t.notOk(sourceCache._tiles[coord.id]); t.end(); }); @@ -221,8 +221,8 @@ test('SourceCache#removeTile', (t) => { tr.height = 512; sourceCache.updateCacheSize(tr); - sourceCache.addTile(coord); - sourceCache.removeTile(coord.id); + sourceCache._addTile(coord); + sourceCache._removeTile(coord.id); t.end(); }); @@ -243,8 +243,8 @@ test('SourceCache#removeTile', (t) => { } }); - sourceCache.addTile(coord); - sourceCache.removeTile(coord.id); + sourceCache._addTile(coord); + sourceCache._removeTile(coord.id); t.equal(abort, 1); t.equal(unload, 1); @@ -705,7 +705,7 @@ test('SourceCache#clearTiles', (t) => { }); sourceCache.onAdd(); - sourceCache.addTile(coord); + sourceCache._addTile(coord); sourceCache.clearTiles(); t.equal(abort, 1); @@ -860,7 +860,7 @@ test('SourceCache#loaded (no errors)', (t) => { sourceCache.on('data', (e) => { if (e.sourceDataType === 'metadata') { const coord = new TileCoord(0, 0, 0); - sourceCache.addTile(coord); + sourceCache._addTile(coord); t.ok(sourceCache.loaded()); t.end(); @@ -879,7 +879,7 @@ test('SourceCache#loaded (with errors)', (t) => { sourceCache.on('data', (e) => { if (e.sourceDataType === 'metadata') { const coord = new TileCoord(0, 0, 0); - sourceCache.addTile(coord); + sourceCache._addTile(coord); t.ok(sourceCache.loaded()); t.end(); @@ -987,12 +987,12 @@ test('SourceCache reloads expiring tiles', (t) => { expiryDate.setMilliseconds(expiryDate.getMilliseconds() + 50); const sourceCache = createSourceCache({ expires: expiryDate }); - sourceCache.reloadTile = (id, state) => { + sourceCache._reloadTile = (id, state) => { t.equal(state, 'expired'); t.end(); }; - sourceCache.addTile(coord); + sourceCache._addTile(coord); }); t.end();