Skip to content

Commit

Permalink
Mark private SourceCache methods with leading '_'
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Jun 26, 2017
1 parent 8e0d81f commit 32f331c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
42 changes: 21 additions & 21 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand All @@ -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]);
}
}

Expand All @@ -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;
Expand All @@ -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++;
Expand All @@ -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);
}
Expand All @@ -474,7 +474,7 @@ class SourceCache extends Evented {
* @returns {undefined} nothing
* @private
*/
removeTile(id) {
_removeTile(id) {
const tile = this._tiles[id];
if (!tile)
return;
Expand All @@ -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);
}
}

Expand All @@ -508,7 +508,7 @@ class SourceCache extends Evented {
*/
clearTiles() {
for (const id in this._tiles)
this.removeTile(id);
this._removeTile(id);
this._cache.reset();
}

Expand Down
44 changes: 22 additions & 22 deletions test/unit/source/source_cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test('SourceCache#addTile', (t) => {
}
});
sourceCache.onAdd();
sourceCache.addTile(coord);
sourceCache._addTile(coord);
});

t.test('adds tile when uncached', (t) => {
Expand All @@ -89,7 +89,7 @@ test('SourceCache#addTile', (t) => {
t.end();
});
sourceCache.onAdd();
sourceCache.addTile(coord);
sourceCache._addTile(coord);
});

t.test('uses cached tile', (t) => {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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]);
Expand All @@ -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);
Expand All @@ -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();
});
Expand All @@ -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();
});
Expand All @@ -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);
Expand Down Expand Up @@ -705,7 +705,7 @@ test('SourceCache#clearTiles', (t) => {
});
sourceCache.onAdd();

sourceCache.addTile(coord);
sourceCache._addTile(coord);
sourceCache.clearTiles();

t.equal(abort, 1);
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 32f331c

Please sign in to comment.