-
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
Mixin guard default
function (#1584)
#1606
Mixin guard default
function (#1584)
#1606
Conversation
Wow, am impressed. Am unwell at the moment but will give it a better look |
nice! I'm deep in the middle of doing docs updates @seven-phases-max mind if I grab your content and use it once this is released? @lukeapage hope you feel better |
@lukeapage Get well! @jonschlinkert Sure (just in case - a markdown copy of it is here) |
awesome! thanks |
Jon are you updating lesscss.org or a new repository? I was planning on |
I'd like to get involved in that documentation as well. I'd gladly proofread what you guys come up with. |
Nice, I'll be pushing stuff up tonight! Sent from my iPhone On Oct 20, 2013, at 5:07 PM, Soviut notifications@github.com wrote:
|
The less-docs repo just at first, then when it's ready we can switch it to the other if that makes sense. It's not ideal, but the existing site is a different beast Sent from my iPhone On Oct 20, 2013, at 4:44 PM, Luke Page notifications@github.com wrote:
|
Radness! |
…ly exclusive guards")
merged |
👍 |
By the way, this is pretty late, but the parentheses in
|
@matthew-dean Well, it's made as a built-in function (not a directive/keyword) so parens are required. See #1584 for the history of this syntax. |
and its not too late to change it, it hasn't been released. I'm guessing (an obscure case) but you could do
I would much rather introduce new functions than introduce new syntax |
I guess we can also turn it into a keyword anytime later (if necessary), but keyword would also need some extra code in the parser (while function needs no parser changes). I.e. a keyword might be a bit overkilling for this relatively minor feature, at the moment at least :) |
Ok, I see. It seemed like a keyword, but I can see the interpretation as a kind of "is" function. :) |
Function
default
Usage:
Expressions
It is possible to use the value returned by
default
with guard operators.For example
.mixin() when not(default()) {}
will match only if there's at least one more mixin definition that matches.mixin()
call:result:
Another example:
result:
Outside of guards
default
is available as built-in function only inside guard expressions. If used outside of a mixin guard condition it is interpreted as a regular CSS value:result:
Advanced usage and multiple
default()
callsIt is allowed to make multiple
default()
calls in the same guard condition or in a different conditions of a mixins with the same name:However LESS will throw a error if it detects a potential conflict between multiple mixin definitions using
default()
:In above example it is impossible to determine what value each
default()
call should return since they recursively depend on each other.This "multiple
default()
calls" analysis is not too deep and very simple as its main intention is mostly to notify a user of possibledefault
misuse, henceThe following also causes a error:
Although there's no direct conflict with
.m(3);
since (1) and (2) do not interfere because of (3), the whole mixin family is interpreted as erroneous (basically, it is the same error as in previous example).And finally, here's advanced correct "multiple
default()
calls" usage (not too practical perhaps, but to illustrate why this is allowed at all):result:
And more examples in included tests...