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

fix(jqLite): make jqLite invoke jqLite.cleanData as a method #15846

Closed
wants to merge 2 commits into from

Conversation

mgol
Copy link
Member

@mgol mgol commented Mar 22, 2017

The previous implementation of jqLite didn't use cleanData from the jqLite
object but instead used a cached version which maede it impossible to
monkey-patch jqLite.cleanData similarly to how you can do it in jQuery.

The cleanData method is not meant to be called directly by userland code;
its purpose is mainly to be able to be monkey-patched; therefore, the previous
implementation didn't make a lot of sense.

This commit enables one of the tests so far run only with jQuery to run with
jqLite as well.

Ref #8486
Ref #8695

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Fix.

What is the current behavior? (You can also link to an open issue here)
jqLite.cleanData is not used directly so it can't be monkey-patched like its jQuery equivalent.

What is the new behavior (if this is a feature change)?
The opposite.

Does this PR introduce a breaking change?
I don't think so.

Please check if the PR fulfills these requirements

Other information:
This is a followup to #8695.

The previous implementation of jqLite didn't use cleanData from the jqLite
object but instead used a cached version which maede it impossible to
monkey-patch jqLite.cleanData similarly to how you can do it in jQuery.

The cleanData method is not meant to be called directly by userland code;
its purpose is mainly to be able to be monkey-patched; therefore, the previous
implementation didn't make a lot of sense.

This commit enables one of the tests so far run only with jQuery to run with
jqLite as well.

Ref angular#8486
Ref angular#8695
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.

Generally LGTM. My only concern is whether this might break some (obscure) tests.

src/jqLite.js Outdated
@@ -309,13 +303,11 @@ function jqLiteClone(element) {
}

function jqLiteDealoc(element, onlyDescendants) {
if (!onlyDescendants) jqLiteRemoveData(element);
if (!onlyDescendants && element.nodeType === NODE_TYPE_ELEMENT) jqLite.cleanData([element]);
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure this doesn't break some usecases or tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've updated the logic.

@@ -309,13 +303,10 @@ function jqLiteClone(element) {
}

function jqLiteDealoc(element, onlyDescendants) {
if (!onlyDescendants) jqLiteRemoveData(element);
if (!onlyDescendants && jqLiteAcceptsData(element)) jqLite.cleanData([element]);
Copy link
Member Author

Choose a reason for hiding this comment

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

@gkalpak Let me elaborate why it shouldn't break anything now. The only situation where we would fire jqLiteRemoveData(element) before and not fire jqLite.cleanData([element]) here now is when jqLiteAcceptsData(element) is false. But if you then look at jqLiteRemoveData source, it changes anything only if element.ng339 is defined. This property is only set to something non-undefined inside jqLiteExpandoStore and only if the second passed argument is truthy. That, in turn, happens in two places only: one is inside jqLiteData, the other one is in jqLite#on. In both cases this setter is guarded by the jqLiteAcceptsData(element) being truthy which contradicts our assumptions.

Therefore, there should be no observable differences to external code here.

@mgol mgol closed this in bf5c2ee Mar 27, 2017
mgol added a commit that referenced this pull request Mar 27, 2017
The previous implementation of jqLite didn't use cleanData from the jqLite
object but instead used a cached version which maede it impossible to
monkey-patch jqLite.cleanData similarly to how you can do it in jQuery.

The cleanData method is not meant to be called directly by userland code;
its purpose is mainly to be able to be monkey-patched; therefore, the previous
implementation didn't make a lot of sense.

This commit enables one of the tests so far run only with jQuery to run with
jqLite as well.

(cherry-picked from bf5c2ee)

Ref #8486
Ref #8695
Closes #15846
@mgol mgol deleted the cleanData-test branch March 27, 2017 12:39
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.

3 participants