-
Notifications
You must be signed in to change notification settings - Fork 273
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
refactor: change type and methods in MediaRange.ts
#6120
Conversation
HI @hinzzx, thank you for the change,
These are the important things to document, you can use the above description as a base and build on it, paraphrase it, etc.. Thank you, ilhan |
In addition, we can notice (from the build failure details) that several Media Gallery tests are failing due to our refactoring, you will have to check and fix the root cause: MediaGallery layout |
packages/base/src/MediaRange.ts
Outdated
@@ -83,7 +83,7 @@ const getCurrentRange = (name: string, width = window.innerWidth): string => { | |||
let currentRangeName; | |||
|
|||
rangeSet.forEach((value, key) => { | |||
if (width >= value[0] && width <= value[1]) { | |||
if (Math.floor(width) >= value[0] && Math.floor(width) <= value[1]) { |
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.
Better introduce a new const for "Math.floor(width)" before the loop, because now we call "Math.floor" twice per iteration , while it can be calculated just once.
f.e.
const effectiveWidth = Math.floor(width)
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.
Hi Ilhan, thanks for the tips and recommendations,
After some (manual) testing and debugging, I came to the following conclusion:
Following the logic that width: 1023px
=> "S" size and width: 1023.5px
=> M size, I found out that even without our change with the Math.floor()
, the width
value, our method getCurrentRange
recieves is always rounded ( with Math.round
logic, which returns the bigger integer after .5 and the smaller one below .5 ). With that said I even think that we might need to revert the Math.floor() change in order to keep the old logic, since our method never recieves a floating number.
Please correct me, if Im wrong.
Best regards,
Stoyan
We did the following changes:
getCurrentRange
now always returns a result, because it fallbacks to the defaultrangeSet
, previously it was returning "null";initRangeSet
method now expects 2 params, instead of 3.initRangeSet
, instead ofinitRangeSet(name: string, borders: [600, 1100, 1400], names: [S, L, M])
, we now use it like:Related to: #6080