-
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
Add ellipsis support when calling a mixin #1857
Conversation
I don't have any particular opinion so far, just doing some tests. My first observation: the way it is implemented it's not just "expand argument that was collapsed using
output:
(Note that I'm not saying it's bad :) |
I like the syntax.. I've been thinking about the benefits and use-cases. I see you use it alot to extend mixins and just pass the rest of the argument list. Its kind of a work-around for the consumer of the mixin passing it as one argument to start with e.g.
And the code addition isn't that much more complicated, so I'm leaning towards taking it. Can you offer any more use-cases and reasons for this to be useful? |
Thanks! It might be useful for extending a 3rd-party lib that uses variable-argument mixins; something like https://github.com/visionmedia/nib but for LESS. Also, even with the workaround, I believe it is still not possible to partially match a list ( |
@jonschlinkert @matthew-dean @SomMeri would be good to get your opinions since it sounds like myself and @seven-phases-max are more on the pro side. I'm only hesitant because we want to make sure every feature is needed and is worth the maintenance effort and language complexity add |
@lukeapage I do not see any harm that could be caused by this and if it is useful, then why not. The Looping like this is even more readable then looping with index variable and what not:
Disclaimer: I did not tested it, only read comments here so far. |
I just would like to put a few notes. As I already mentioned this feature is not limited only to mixins arguments but applies to any value lists (though I guess it was unintentional). In other words, it also can be used to do the work that some hypothetical |
I haven't personally ever written a So, I feel unqualified to give my opinion on this feature, as I don't see many use cases to use |
The proposed syntax offers a nice and tidy equivalent of how one would iterate over a list using list comprehension in pure functional languages. I reaaaaaaa---lly like it. 👍 |
Yep, I also always keep this feature in mind (I even have a special Less setup with this feature enabled for my own use :) Hoping someday it gets enough votes to get in. |
@seven-phases-max I'll reiterate that I don't have enough experience with these to put in any strong opinion. If you, @lukeapage, and @rjgotten are on board, shove that puppy in. |
I think the only thing that irks me a bit is that this probably wouldn't handle the case of list-of-list correctly and would produce a wrong result when it arrives on the last member of an outer list. What does the following produce? .mixin(@head, @tail...) {
@first: extract(@head, 1);
@second: extract(@head, 2);
@{first}: @second;
.mixin(@tail...);
}
.class {
@values : a A, b B, c C;
.mixin(@values...);
} Does this produce what I would expect? I.e. .class {
a : A;
b : B;
c : C;
} |
For your example it's:
I guess this problem is related to #1943. |
Maybe my example is just flawed. What happens if we explicitly add the base case of the tail recursion? That is; what if we do: .mixin() {}
.mixin(@head, @tail...) {
@first: extract(@head, 1);
@second: extract(@head, 2);
@{first}: @second;
.mixin(@tail...);
}
.class {
@values : a A, b B, c C;
.mixin(@values...);
} |
Hmm, indeed, you're right. Empty one is required in this case as a terminator for an empty tail in the end. And yes, on the final call the |
👍 |
@seven-phases-max it seems like the general view is a +, I'm happy - do you want to merge it in? |
@lukeapage Yes, I'll do then. |
Done. |
🎉 🎈 🏆 Yay! It's happening! 🎈 🎉 |
Thats great :party: |
This adds support for expanding arguments that were collapsed using
.mixin(@foo; @rest...) { }
by being able to write.mixin2(@rest...);
An example file that uses this feature extensively can be found at https://gist.github.com/philschatz/839d32ef87bc22ba5231
Also, thanks for adding plugin support! If you're interested, I've used it for: