Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/s2-core/src/renderer/BaseRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { DisplayObjectConfig, Path } from '@antv/g';
import flru, { flruCache } from 'flru';
import type { BaseCell } from '../cell';
import { CellClipBox } from '../common/interface';
import { CustomRendererConfig } from '../common/interface/renderer';
import { SimpleBBox } from '../engine';
import { getPreparedText } from '../utils/cell/customRenderer';

export abstract class BaseRenderer {
static mediaCache = new Map<string, HTMLElement | null>();
static mediaCache: flruCache<HTMLElement | null> = flru(200);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议将魔法数字 200 提取为具名常量,以提高代码的可读性和可维护性。例如,可以定义一个私有静态只读属性来存储这个值。

Suggested change
static mediaCache: flruCache<HTMLElement | null> = flru(200);
private static readonly MEDIA_CACHE_MAX_SIZE = 200;
static mediaCache: flruCache<HTMLElement | null> = flru(BaseRenderer.MEDIA_CACHE_MAX_SIZE);


abstract prepare(
renderer: CustomRendererConfig,
Expand Down
4 changes: 3 additions & 1 deletion packages/s2-core/src/utils/cell/customRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { flruCache } from 'flru';

const loadError = new Error('Failed to load image and fallback');

export function asyncDrawImage(options: {
src: string;
fallback?: string;
timeout?: number;
mediaCache?: Map<string, HTMLElement | null>;
mediaCache?: flruCache<HTMLElement | null>;
crossOrigin?: string | null;
}): Promise<HTMLImageElement> {
const {
Expand Down
Loading