Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

perf(jqLite): avoid repeated add/removeAttribute in jqLiteRemoveClass #16131

Merged
merged 2 commits into from
Sep 17, 2017

Conversation

jbedard
Copy link
Contributor

@jbedard jbedard commented Jul 26, 2017

This does something similar to what was suggested in #16078, although keeps it a little more like jqLiteAddClass for now.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

LGTM (as soon as Travis is happy)

src/jqLite.js Outdated
});

element.setAttribute('class', trim(existingClasses));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should you do a check to ensure that we don't set this unnecessarily which potentially causes unnecessary renders?

Ref: https://github.com/jquery/jquery/blob/master/src/attributes/classes.js#L41-L45

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that should be done along with addClass in its own commit...

@jbedard
Copy link
Contributor Author

jbedard commented Aug 3, 2017

Passed now. However I decided to add one more commit like @dcherman suggested to only actually set the class attribute if it changed (for both addClass and removeClass).

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

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

LGTM
Do you think it is worth adding some tests to verify the new behavior (i.e. that we don't call get/setAttribute() more times than necessary)?

@Narretz
Copy link
Contributor

Narretz commented Sep 6, 2017

@jbedard can you please rebase this? The tests currently don't run because of a Travis problem at the branch point.

@jbedard
Copy link
Contributor Author

jbedard commented Sep 10, 2017

Rebased.

The tests had to be put in if (_jqLiteMode) since they are testing a JQLite implementation detail (I think jquery3 tests passed, but not jquery2).

@@ -914,6 +914,37 @@ describe('jqLite', function() {
});


//JQLite specific implementation/performance tests
Copy link
Member

Choose a reason for hiding this comment

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

A space before JQLite?

@@ -1031,6 +1062,37 @@ describe('jqLite', function() {
jqA.removeClass('foo baz noexistent');
expect(a.className).toBe('bar');
});


//JQLite specific implementation/performance tests
Copy link
Member

Choose a reason for hiding this comment

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

A space before JQLite?

@@ -914,6 +914,37 @@ describe('jqLite', function() {
});


//JQLite specific implementation/performance tests
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: add space

@jbedard jbedard merged commit 5728076 into angular:master Sep 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants