Skip to content

Commit

Permalink
feat: remove WebP support check in load func (#19)
Browse files Browse the repository at this point in the history
## Summary

<!-- Please summarize your changes. -->

<!-- Please link to any applicable information (forum posts, bug
reports, etc.). -->

Removed the WebP support check in the load function. The rationale is
that the load function should only be responsible for loading images.
This change was decided upon after an in-depth discussion with @manudeli
. Shoutout to @manudeli

## Checks

<!-- For completed items, change [ ] to [x]. -->

<!-- If you leave this checklist empty, your PR will very likely be
closed. -->

Please check the following:

- [x] I have written documents and tests, if needed.
  • Loading branch information
tooooo1 authored Sep 15, 2023
1 parent ef6cb52 commit 67ba10a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-moles-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fepack/image": patch
---

feat: remove WebP support check in load func
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ coverage:
project:
default:
target: 100%
threshold: 60%
threshold: 100%
fepack-image:
target: 100%
threshold: 60%
threshold: 100%

comment:
layout: "header, reach, diff, flags, components"
Expand Down
12 changes: 3 additions & 9 deletions packages/image/src/load.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import checkWebPSupport from "./checkWebPSupport";

interface ImageSource {
defaultSrc: string;
webpSrc?: string;
}

/**
* Loads the given images. If WebP is supported and a WebP source is provided, it will load that. Otherwise, it loads the default source.
* Loads the given images. If WebP is WebP source is provided, it will load that. Otherwise, it loads the default source.
* @param {ImageSource[]} images - Array of image sources to preload.
*/
async function load(images: ImageSource[]) {
const webpSupported = await checkWebPSupport();

function load(images: ImageSource[]) {
for (const image of images) {
const selectedSource =
webpSupported && image.webpSrc ? image.webpSrc : image.defaultSrc;
const imageElement = new Image();
imageElement.src = selectedSource;
imageElement.src = image.webpSrc ? image.webpSrc : image.defaultSrc;
}
}

Expand Down

0 comments on commit 67ba10a

Please sign in to comment.