-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
The proposed feature set for :extend #2101
Comments
Yeh, I think extending mixins is more important. It's interesting no one has brought up other extend options (till you did) |
I've added needs decision because I'd like to see how much complexity it adds before we decide whether it's still needed. Anyone wanting to implement, just write out a plan and let's discuss. |
Why does it need a decision if consensus was already made? It took a long time for us to reach this decision. Doesn't it just need implementation? I don't disagree that extending mixins is also important, though. |
A few raw and quick thoughts: Also as discussed in other topics a But that's just thoughts. Eventually I would even like to implement this myself but to be honest I doubt this really would happen "soon"... So I guess this all also hardly depends on who's going to implement it. Obviously we don't need everything at once so some evolutionary advances in tiny steps should not make it too complex (e.g. try |
Yes, exactly. To me, that was the more logical and intuitive default use case, and probably the only use of extend I would (personally) use / promote. "all" is excessively greedy for average use, and shallow exact (default) is unintuitively narrow (because it deviates from mixin behavior). |
Fine, changed. We reached consensus on what to do, I just thought from the lack of feedback that the hunger had gone.. |
Thanks. Maybe Github should have a voting mechanism for top features to implement. Some of my pet favorites are:
|
What do you think about supporting an (optional) exclamation point on flags for clarity / separation from element selectors?
I know our keywords don't conflict, but it might be intuitive for some because of |
Btw., since the PR is coming (@bassjobsen 👍), I'd want to stress my concerns about |
exclamation point, could be, |
Are there really any use cases for Personally, if we just add |
Well, |
Per the pull request discussion, and reviewing that code, I can actually see where Because those two similar selectors can't yet extend a detached ruleset or a mixin, there really is no clean way to refactor and keep a logical structure (and keep your rules minimized). So there's a particular pattern that My guess is simply providing the tool will surface other use cases / patterns like that that aren't immediately obvious. EDIT: It should be noted though that the default use of extend without a keyword does much of this already. So I guess the only added pattern to this is greedy selector matching. I just haven't really used extend much in my own styles so I haven't really toyed with these other patterns. |
to correct myself:
My mistake, it's actually exactly the opposite,
|
@matthew-dean Could you please provide a minimal example that shows the difference between |
There are some examples in #2506 but I'll do my best to explain from my perspective in some more detail. So, the easiest way to understand or test Therefore, there are some examples in which So, in #2506, the way I generated the output is simply by taking two cases of .a button .q {
color: red;
} These two statements should produce identical output: .b:extend(button any) {
background: black;
} .b:extend(button all) {
background: black;
} Because "all" is basically: .b:extend(button any deep) {
background: black;
}
Where you'll see differing behavior for So, that means that .a {
.b {
color: red;
.c {
line-height: 1;
}
}
} Here is what I would expect from each output: // using all or ALL or !all
.d:extend(.b all) { }
// output today - testable with current parser
.a .b,
.a .d {
color: red;
}
.a .b .c,
.a .d .c {
line-height: 1;
} // using any or ANY or !any
.d:extend(.b any) { }
// expected output
.a .b,
.a .d {
color: red;
}
.a .b .c {
line-height: 1;
} So, it's pretty straightforward. .d:extend(.b any) { background: blue; }
// output
.a .b,
.a .d {
color: red;
}
.a .b .c {
line-height: 1;
}
.d {
background: blue;
} Or, to demonstrate "joining" to the center node: .d:extend(.a .b any) { background: blue; }
// output
.a .b,
.d {
color: red;
}
.a .b .c {
line-height: 1;
}
.d {
background: blue;
} AND, if you were paying attention, you might have caught that the above is the exact same output as writing: .d:extend(.a .b) { background: blue; } The reason is that So, it actually should be really testable, because it should behave like I think that should be pretty comprehensive. The important thing to remember is just that all of this behavior is already there in Does this help clarify? |
Ok, now I guess I see what is the trick. And I'm afraid in this state we'll have to postpone
is identical to this:
So
Does this help? P.S. Just to clarify, in this PR the |
And just in case, to make sure... what result you would expect for this code:
? |
(Speaking of the |
So... what if we just disable |
Yes, I think see the problem. If that's the case that extend is applied after the collapse, how does the "all" algorithm do deep--. ohhhhh.... it does because it's matching a part of the selector, so post-collapse of a tree, it simply matches part of the result. D'oh!
Yes, definitely "deep" is useful. Since you have a good understanding of the intent of it, what do you think about "any"'s usefulness? And the naming of both now? Since it seems less useful than deep, and it's an algorithmic change, we could postpone indefinitely. Just curious, since everything collapses, how would Also, what issue defines |
I guess there's none. (There were some snippets here and there but nothing especially dedicated). In summary it's just:
css result:
In other words it matches exactly like a mixin with the same name would (except that mixins ignore combinators but |
Strictly speaking the tree is not collapsed yet, so the nodes are there and it iterates through the nodes but it just joins node's selectors into arrays across and compares those resulting arrays (at least how I understand it - well, it's all there, you can see how difficult it looks to describe :). I.e. |
Wouldn't |
Curiously it will. Though for more complex examples the similarity ends (e.g. if there more bananas, only the lowest one is matched with |
On issue #1155, there was community consensus on the usage of extend in a way that offered flexibility for different use cases but kept things simple through the use of keyword flags. I've pulled out the relevant section/syntax that was agreed upon:
:extend( selector [exact|any] [shallow|deep] [all])
:extend(.button exact)
matches.button {}
but not#main .button a
-:extend(.a .b)
is considered an exact match to.a { .b { } }
):extend(.button any)
matches.button {}
and#main .button a
).a:extend(.button shallow)
will not include hover in.button { &:hover { } }
).a:extend(.button deep)
will include hover in.button { &:hover { } }
)Example:
The reasons, arguments, and use cases for these other uses of
:extend
are documented in issue #1155. After the discussion and consensus, the first case and last case were implemented because they were easier to implement first, but I think the remaining implementation got lost in the noise. I'd love to see the rest of:extend
implemented as I think these other use cases are still valid and there's various issues that come up here that essentially relate to what's still missing. (See: less/less-docs#177).I'd love to see the work on
:extend
continue! (And other great ideas, like extending mixins.)The text was updated successfully, but these errors were encountered: