Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

CSS: Skip falsy values inaddClass( array ), compress code#5003

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mgol merged 1 commit intojquery:mainfrommgol:addClass-falsy
Jan 24, 2022

Conversation

mgol
Copy link
Member

Summary

This change makes jQuery skip falsy values inaddClass( array )
&removeClass( array ) instead of stopping iteration when the first falsy
value is detected. This makes code like:

elem.addClass(["a","","b"]);

add both thea &b classes.

The code was also optimized for size a bit.

Fixesgh-4998

+0 bytes thanks to the optimizations 🎉; initially it was at +8 bytes. IntoggleClass we now also avoid needlessly recomputing the array of classes.

I'm yet to check how much can these optimizations be backported to 3.x-stable as we have some deprecatedtoggleClass logic there but I'll check after this lands.

Checklist

This change makes jQuery skip falsy values in `addClass( array )`& `removeClass( array )` instead of stopping iteration when the first falsyvalue is detected. This makes code like:```jselem.addClass( [ "a", "", "b" ] );```add both the `a` & `b` classes.The code was also optimized for size a bit.Fixesjquerygh-4998
@mgolmgol added the CSS labelJan 20, 2022
@mgolmgol added this to the3.6.1 milestoneJan 20, 2022
@mgolmgol added the Discuss in MeetingReserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labelJan 24, 2022
@timmywiltimmywil removed the Discuss in MeetingReserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labelJan 24, 2022
Copy link
Member

@timmywiltimmywil left a comment

Choose a reason for hiding this comment

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

I like the change to use each.

@mgolmgol merged commita338b40 intojquery:mainJan 24, 2022
@mgolmgol deleted the addClass-falsy branchJanuary 24, 2022 17:56
mgol added a commit that referenced this pull requestJan 24, 2022
This change makes jQuery skip falsy values in `addClass( array )`& `removeClass( array )` instead of stopping iteration when the first falsyvalue is detected. This makes code like:```jselem.addClass( [ "a", "", "b" ] );```add both the `a` & `b` classes.The code was also optimized for size a bit so it doesn't increase theminified gzipped size.Fixesgh-4998Closesgh-5003(partially cherry picked from commita338b40)
@mgol
Copy link
MemberAuthor

Landed onmain ina338b40 and on3.x-stable in a slightly modified version in9b34bdb.

The3.x-stable version has fewer modifications intoggleClass as it needs to support the deprecated value-less signature but even in that state it's also at +0 bytes.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@timmywiltimmywiltimmywil approved these changes

@gibson042gibson042Awaiting requested review from gibson042

Assignees
No one assigned
Labels
Milestone
3.6.1
Development

Successfully merging this pull request may close these issues.

addClass() called with an array doesn't add all of the classes if one of them is an empty string
2 participants
@mgol@timmywil

[8]ページ先頭

©2009-2025 Movatter.jp