This commit is contained in:
Eric van der Vlist 2022-10-20 16:58:33 +02:00
parent d970b288e4
commit c800235ebb
1 changed files with 15 additions and 9 deletions

View File

@ -4,23 +4,20 @@ import { range, isEqual } from 'lodash';
import { Rectangle, TileFactory, TileKeyObject } from './types'; import { Rectangle, TileFactory, TileKeyObject } from './types';
import tileUri from './uris'; import tileUri from './uris';
/**
* @hidden
*/
export const thisIsAModule = true; export const thisIsAModule = true;
/** /**
* A cache to store tiles without being subject to re-initialization when components are unmounted/remounted.
*
* This cache is a map of map, the first key identifying the `<TiledLayer` and the second one for `<Tile>`s.
*
* Idea stolen [on the web](https://dev.to/tiagof/react-re-mounting-vs-re-rendering-lnh)
*
* TODO: housekeeping
* *
*/ */
declare global { declare global {
var cacheForTiledLayer: any; var cacheForTiledLayer: any;
} }
export {}; //export {};
globalThis.cacheForTiledLayer = new Map(); globalThis.cacheForTiledLayer = new Map();
@ -44,8 +41,17 @@ export interface TiledLayerProperties {
* This component has no need to know the number nor the size of its tiles: tiles can be added when needed and * This component has no need to know the number nor the size of its tiles: tiles can be added when needed and
* its unit is the tile size (the parent component needs to transform its enclosing SVG group to adapt its units) * its unit is the tile size (the parent component needs to transform its enclosing SVG group to adapt its units)
* *
* The `globalThis.cacheForTiledLayer` global variable is used as a cache to store tiles without being subject
* to re-initialization when components are unmounted/remounted.
*
* This cache is a map of map, the first key identifying the `<TiledLayer` and the second one for `<Tile>`s.
*
* Idea stolen [on the web](https://dev.to/tiagof/react-re-mounting-vs-re-rendering-lnh)
*
* TODO: cache housekeeping
*
* TODO: test tiles'X and Y boundaries. * TODO: test tiles'X and Y boundaries.
* TODO: housekeeping *
* TODO: remove tileFactory to facilitate memoisation. * TODO: remove tileFactory to facilitate memoisation.
* *
*/ */