X Tutup
Skip to content

Proper cleanup in NgClass#3557

Closed
pkozlowski-opensource wants to merge 2 commits intoangular:masterfrom
pkozlowski-opensource:class_corner_cases
Closed

Proper cleanup in NgClass#3557
pkozlowski-opensource wants to merge 2 commits intoangular:masterfrom
pkozlowski-opensource:class_corner_cases

Conversation

@pkozlowski-opensource
Copy link
Copy Markdown
Member

No description provided.

@pkozlowski-opensource pkozlowski-opensource added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 10, 2015
@pkozlowski-opensource
Copy link
Copy Markdown
Member Author

@mhevery this is a follow up PR addressing your comment in PR #3498.

I've decided to not add binding to class since it would create strange corner cases, ex.:
<div class="{{exp}}"> <-- throws since there is no class property vs.
<div class="{{exp}}" ng-class="otherExp"> <-- oh, now it works, but creates many corner cases since both expressions can change.

Instead I'm injecting @Attribute('class') initialClasses: string so interpolation on class behaves consistently, regardless of the presence of the NgClass directive.

@mhevery mhevery added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 10, 2015
@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Aug 10, 2015

But we could map class to className property just like we map innerHTML so <div class="{{exp}}"> should work regardless of ng-class

@pkozlowski-opensource
Copy link
Copy Markdown
Member Author

Ah, ok, this could work. I will add some more tests tommorow to see if we are not bumping into non-obvious corner cases.

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Aug 10, 2015

thanks!

On Mon, Aug 10, 2015 at 2:10 PM, Pawel Kozlowski notifications@github.com
wrote:

Ah, ok, this could work. I will add some more tests tommorow to see if we
are not bumping into non-obvious corner cases.


Reply to this email directly or view it on GitHub
#3557 (comment).

@pkozlowski-opensource
Copy link
Copy Markdown
Member Author

@mhevery so, I went over some use cases and I can see one problem with mapping class -> className. As soon as we do this binding to [class] "takes over" classes on a given DOM element and can potentially "destroy" CSS classes set by other attributes / binding / directives. Few examples:

  • <div [class.foo]="showFoo" [class]="exp"> - here any change to exp will wipe out foo
  • <div class="foo" with-host> where with-host has host: {"[class]": "expr"} - here any change to exp will wipe out foo (currently host attribute class has special treatement)
  • <div [class]="exp" im-touching-classlist> where im-touching-classlist is a directive that manipulates classList - here any change to exp will wipe out changes done by im-touching-classlist

I must admit that currently I don't have great idea on how to handle all those corner cases :-/ Given this I would like to re-discuss introducing class -> className mapping as it might be opening a can of worms :-(

//cc: @vsavkin

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Aug 11, 2015

@pkozlowski-opensource All of your points are valid and I share the same concerns. These issues exists whether or not we map class-name to class since you could just write <div [class.foo]="showFoo" [class]="exp" [class-name]="exp" class="foo {{exp}}" class-name="foo {{exp}}" ...> and get in the same issue regardless of wether we map class to className.

So I think the discussion of

  • (a) how do we merge the different ways we have for expressing class bindings in an unsurprising ways with
  • (b) weather or not we should map class to className

are really independent. Ignoring (a) do you see a down side of doing (b)? I think (b) is desirable.

@pkozlowski-opensource pkozlowski-opensource force-pushed the class_corner_cases branch 2 times, most recently from ee71663 to c3f162d Compare August 12, 2015 13:20
@pkozlowski-opensource pkozlowski-opensource added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Aug 12, 2015
@pkozlowski-opensource
Copy link
Copy Markdown
Member Author

@mhevery I think I've implemented both binding to [class] (aliased to className) and did all the changes to NgClass to properly clean up / take changes to [class] into account. It seem to work "correctly" for a surprising number of cases :-)

PTAL

@pkozlowski-opensource
Copy link
Copy Markdown
Member Author

Putting into .35 milestone as the associated issue is in .35

@mhevery
Copy link
Copy Markdown
Contributor

mhevery commented Aug 12, 2015

Can you answer my two questions? Otherwise LGTM.

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Aug 12, 2015
@mary-poppins
Copy link
Copy Markdown

Merging PR #3557 on behalf of @mhevery to branch presubmit-mhevery-pr-3557.

@mary-poppins mary-poppins removed the action: merge The PR is ready for merge by the caretaker label Aug 12, 2015
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup