Skip to content

Conversation

xintongxia
Copy link

For #4039

Background

Change List

  • IconManager: add a loaded field indicating if the icons are fully loaded.

const imageData = await loadImage(icon.url);

const data = resizeImage(ctx, imageData, width, height);
if (i === icons.length - 1) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • This marks loaded when the last image is loaded, not when all images are loaded.
  • What happens when the icon set changes?

Copy link
Author

Choose a reason for hiding this comment

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

  • What happens when the icon set changes?

reset loaded to false when there are more icons required to be loaded.

@xintongxia xintongxia force-pushed the xx/icon-render-test branch from 5d3d8e1 to 09d58d7 Compare January 2, 2020 22:53
@xintongxia xintongxia force-pushed the xx/icon-render-test branch from 9137728 to fbf3290 Compare January 2, 2020 23:05
let loaded = 0;
for (const icon of icons) {
loadImage(icon.url).then(imageData => {
loaded++;
Copy link
Collaborator

Choose a reason for hiding this comment

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

More scenarios to consider:

  • loaded will never be set if one of the images fails to load, e.g. url is not found. Is that intended?
  • This logic breaks if data is changed and a new batch of icons start loading. How do you handle that?

@xintongxia xintongxia force-pushed the xx/icon-render-test branch from 7cca557 to 6b6aa21 Compare January 3, 2020 00:55
@coveralls
Copy link

coveralls commented Jan 3, 2020

Coverage Status

Coverage increased (+2.5%) to 83.289% when pulling 611635a on xx/icon-render-test into 29e66d6 on master.


get loaded() {
const requestedIcons = Object.keys(this._mapping).length;
return this._autoPacking && requestedIcons && this._loadedIcons === requestedIcons;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd recommend tracking the number of pending requests rather than the number of fulfilled requests:

this._pendingCount++;
loadSomething(...).finally(() => this._pendingCount--);

That way you don't need to know how to calculate the total number of requests here with _autoPacking and _mapping. The auto packing logic may change in the future and maintainers may forget to update this function, given that there are no tests. If requests are tracked where they start, it will be much more robust.

@xintongxia xintongxia merged commit 5877187 into master Jan 3, 2020
@xintongxia xintongxia deleted the xx/icon-render-test branch January 3, 2020 22:24
1chandu pushed a commit that referenced this pull request Jan 8, 2020
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.

3 participants