-
Notifications
You must be signed in to change notification settings - Fork 132
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
Re-introduce lazy loading #2367 #2450
Merged
yucheng11122017
merged 16 commits into
MarkBind:master
from
LamJiuFong:2367-reintroduce-lazy-loading
Mar 17, 2024
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5831792
Add width and height option to Pic and Annotation
4498597
Improve code quality on lazy loading
aca23e6
Update test
4f622a4
Merge branch 'master' into 2367-reintroduce-lazy-loading
a99c6b9
Update unit tests for lazy loading
edd443a
Merge branch 'master' into 2367-reintroduce-lazy-loading
LamJiuFong 1516b05
Update test
a6c8980
Change log warning output and update test
a44621b
Merge branch 'master' into 2367-reintroduce-lazy-loading
LamJiuFong b7c6b0b
Update log warning message
7d871f3
Update docs/userGuide/syntax/pictures.md
LamJiuFong 7afad7d
Merge branch 'master' into 2367-reintroduce-lazy-loading
LamJiuFong d5bdec7
Update tests
16d7de0
Merge branch 'master' into 2367-reintroduce-lazy-loading
LamJiuFong 6180b27
Merge branch 'master' into 2367-reintroduce-lazy-loading
LamJiuFong 92b1c36
Remove unnecessary changes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
:src="src" | ||
:alt="alt" | ||
:width="computedWidth" | ||
:height="computedHeight" | ||
:loading="computedLoadType" | ||
class="img-fluid rounded" | ||
@load.once="computeWidth" | ||
@load.once="computeWidthAndHeight" | ||
/> | ||
<span class="image-caption"> | ||
<slot></slot> | ||
|
@@ -35,6 +37,10 @@ export default { | |
type: String, | ||
default: '', | ||
}, | ||
lazy: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
addClass: { | ||
type: String, | ||
default: '', | ||
|
@@ -53,20 +59,30 @@ export default { | |
} | ||
return this.widthFromHeight; | ||
}, | ||
computedHeight() { | ||
return this.heightFromWidth; | ||
}, | ||
computedLoadType() { | ||
return this.lazy ? 'lazy' : 'eager'; | ||
}, | ||
}, | ||
data() { | ||
return { | ||
widthFromHeight: '', | ||
heightFromWidth: '', | ||
}; | ||
}, | ||
methods: { | ||
computeWidth() { | ||
if (!this.hasWidth && this.hasHeight) { | ||
const renderedImg = this.$refs.pic; | ||
const imgHeight = renderedImg.naturalHeight; | ||
const imgWidth = renderedImg.naturalWidth; | ||
const aspectRatio = imgWidth / imgHeight; | ||
computeWidthAndHeight() { | ||
const renderedImg = this.$refs.pic; | ||
const imgHeight = renderedImg.naturalHeight; | ||
const imgWidth = renderedImg.naturalWidth; | ||
const aspectRatio = imgWidth / imgHeight; | ||
if (this.hasWidth) { // if width is present, overwrite the height (if any) to maintain aspect ratio | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm if this behavior necessary? I think its ok for a user to adjust the aspect ratio as needed. |
||
this.heightFromWidth = Math.round(toNumber(this.width) / aspectRatio).toString(); | ||
} else if (this.hasHeight) { | ||
this.widthFromHeight = Math.round(toNumber(this.height) * aspectRatio).toString(); | ||
this.heightFromWidth = this.height; | ||
} | ||
}, | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with this I think - though I remember some discussions about spy-on vs mock, where mock tends to be preferred over spying as errors can't be produced from winston.
Here is some additional discussions on stack overflow for your consideration...
And a related issue in markbind #2099 - feel free to weigh in with your thoughts.
Thanks @luminousleek for sharing these links with me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've got an example of how you might mock the logger in #2463
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestions @kaixin-hc @luminousleek ! Will follow the suggestions and update my code.