Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: image asset ids #107

Merged
merged 11 commits into from
Nov 15, 2024
Merged

fix: image asset ids #107

merged 11 commits into from
Nov 15, 2024

Conversation

samuelOsborne
Copy link
Collaborator

No description provided.

Copy link

changeset-bot bot commented Nov 6, 2024

🦋 Changeset detected

Latest commit: 1bc5558

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@dotlottie/dotlottie-js Patch
next Patch
node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Nov 6, 2024

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
dotlottie-js 21.73 KB (+0.61% 🔺) 435 ms (+0.61% 🔺) 1.1 s (+30.4% 🔺) 1.5 s

@samuelOsborne samuelOsborne marked this pull request as ready for review November 6, 2024 16:07
@samuelOsborne samuelOsborne changed the title Fix/image asset ids fix: image asset ids Nov 6, 2024
Copy link
Member

@theashraf theashraf left a comment

Choose a reason for hiding this comment

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

I think we need to establish a clear distinction between the following in the LottieImage class:

  • id
  • fileName
    In this update, we're relying on fileName as the new identifier, so we might no longer need the id property for images.

or, we could continue using id as the filename, inferring the extension automatically from the image data ?


this.animations.forEach((animation) => {
images.set(animation.id, animation.imageAssets);
animation.imageAssets.forEach((imageAsset) => {
if (dupeMap.has(imageAsset.id)) {
Copy link
Member

Choose a reason for hiding this comment

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

The id is not always the same as the filename, for example

id: image_0, filename: image_0.png
is not the same as
id: image_0, filename: 'image_0.webp'

right ? probably our ids should be the filename and we can get rid of using the image id in this case, no ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Inside the lottie itself, images had an id field, and then a name and path attribute, thats why I mapped it like this to the image class.

The id is just the filename without the extension
In your example the id stayed the same despite changing the extension

* @returns Map of duplicate image ids and their count.
*/
private _getMapOfDuplicateImageIds(): Map<string, number> {
let count = 0;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this global count variable ? isn't the map already has the occurrence of each image by its ID ?

count = dupeMap.get(imageAsset.id) ?? 0;
dupeMap.set(imageAsset.id, count + 1);
} else {
dupeMap.set(imageAsset.id, 1);
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be an occuranceMap not duplicateMap, right ? as based on this line, even if there is a unique image id, still would be pushed to the map with an occurance of 1

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was duplicateMap as duplicate filename not the content of the image, will change to filename occurence map

@@ -140,6 +140,8 @@ export class LottieImageCommon {
}
// Default to png if the file extension isn't available
this.fileName = `${newName}.${fileExt}`;
} else {
this.fileName = `${newName}.png`;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the extension inferred from the mimetype of the data ? defaulting it to png is safe ?

Copy link
Member

@theashraf theashraf left a comment

Choose a reason for hiding this comment

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

Let's add a changeset ?

@samuelOsborne samuelOsborne merged commit 2566abe into main Nov 15, 2024
2 checks passed
@samuelOsborne samuelOsborne deleted the fix/image-asset-ids branch November 15, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants