-
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
Iterating mixin only works first time it's called #2849
Comments
I've got this working now but I'm still not sure if this is a bug or not so I'll leave it open. For anyone who stumbles accross this looking for a fix, setting
|
Yes, the result is expected (since after the first loop the variable is in the global/parent scope and then inside .prepend-classes(@rules) {
@classes: foo, bar, baz;
.apply(@class, @rules) {@rules();}
.-(@i, @rules) when (@i > 0) {
.-(@i - 1, @rules);
.apply(extract(@classes, @i), @rules);
}
.-(length(@classes), @rules);
} Though in your particular case I wonder if you need a loop at all: .prepend-classes(@rules) {
.foo, .bar, .baz {
@rules();
}
}
.prepend-classes({
&-red-class {background: red}
}); And vice versa... |
Closing as duplicate of #1316. |
The loop is needed in my particular use case as I do something different depending on the class, the above was just a simplified example to reproduce the issue. Thanks for taking the time to explain what's going on here though, much appreciated. |
I have the following mixin:
Which when used like this:
Should output this:
It works, but only the first time the mixin is called. Any time after that
@{class}
always returns the last value. So for this example running the exact same code a second time outputs this:I may be interpreting the docs incorrectly but it seems to me according to this part of the docs it should work as the variable is local to this mixin.
The line
@class: extract(@classes, @i);
always sets@class
correctly. It's only when you try and output@class
inside@rules
the value isn't passed through correctly.Working demo
The text was updated successfully, but these errors were encountered: