Skip to content

Commit

Permalink
perf: improve performance of computing dock configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Feb 19, 2024
1 parent 5d19b06 commit 7adeab9
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 109 deletions.
4 changes: 4 additions & 0 deletions how-to/workspace-platform-starter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## v17.2.0

- Improved performance of computing dock configuration, especially on theme changes.

## v17.0.0

- Added support for dock submenus
- Added support for customizing the taskbar icon for the splash screen window
- Added an example of navigating content using navigation controls. Enabled through default window options in the main [manifest.fin.json](./public/manifest.fin.json) and in our developer docs snapshot [developer.snapshot.fin.json](./public/common/snapshots/developer.snapshot.fin.json)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isStringValue } from "./utils";

const IMAGE_CACHE: { [key: string]: string } = {};
const IMAGE_CACHE = new Map<string, { dataUri: string | undefined }>();

/**
* Load an image to a data url containing base64 image data.
Expand All @@ -18,8 +18,9 @@ export async function imageUrlToDataUrl(

const key = `${url}_${dimensions}`;

if (IMAGE_CACHE[key]) {
return IMAGE_CACHE[key];
const cachedValue = IMAGE_CACHE.get(key);
if (cachedValue) {
return cachedValue.dataUri;
}

return new Promise<string | undefined>((resolve) => {
Expand All @@ -41,17 +42,19 @@ export async function imageUrlToDataUrl(
if (ctx) {
ctx.drawImage(img, 0, 0, dimensions, dimensions);
dataUri = canvas.toDataURL("image/png", 1);
IMAGE_CACHE[key] = dataUri;
IMAGE_CACHE.set(key, { dataUri });
}
} catch {}
resolve(dataUri);
});
img.addEventListener("error", () => {
IMAGE_CACHE.set(key, { dataUri: undefined });
// eslint-disable-next-line unicorn/no-useless-undefined
resolve(undefined);
});
img.src = url;
} catch {
IMAGE_CACHE.set(key, { dataUri: undefined });
// eslint-disable-next-line unicorn/no-useless-undefined
resolve(undefined);
}
Expand Down
Loading

0 comments on commit 7adeab9

Please sign in to comment.