-
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
detached rulesets #1859
detached rulesets #1859
Conversation
Wow! That was fast. Starting to experiment with it right now. |
One bug I forgot to put a todo on is you can't assign the ruleset to a |
Okay I'd like to merge this. Its a big addition so is everyone happy @jonschlinkert @SomMeri @matthew-dean |
So far I found two major issues:
|
This is cool, but I still somewhat prefer passing mixin references, as it doesn't introduce a new type of syntax, and it also allows you to interpret and pass variables within rulesets. This introduces a new type of paradigm that could potentially be confusing if mixin references are added, as it looks like a mixin call in order to output it, which is different usage than typical variable output. However, the I'm guessing you took this approach because it's easier to implement, but I still feel like @seven-phases-max's syntax (with your additions) is more logical, as it doesn't introduce a new "idea" like this does. It's just assigning / passing a mixin to a variable, and then calling it like a regular mixin. So, for clarity, this makes sense to me:
EDIT: However, to be fair, passing in a ruleset to a variable or assigning it directly to @ruleset is probably a distinction without a difference. I guess what I'm missing is the ability to do normal mixin stuff on these rulesets like guards and variables, but maybe this is a fine first step. Just my thoughts. |
Unfortunalty I'm a bit limited in time for the moment to craft a prototype for that "by reference" feature (Hoping to make it in a few weeks or so). Either way I don't think we have to either choose between them or to not release one before the other. So far I don't see any syntax conflicts in between so the other one can be transparently added later if everything goes OK. (If i'm not mistaken the only big disputed thing in the end was the necessity of a |
Passing mixin references as I said before does introduce new syntax and in |
Matthew, regarding primary usecases see #1867 - and there are lots of other |
@lukeapage I do not have much time now, so I looked only on detached-rulesets.less test and I liked it. Is there going to be beta release with new features or something like that? I can try to break it next week or so. |
@seven-phases-max I changed that < 512 on the chunker to < 1 and then ran it again. I'll get that fixed and then I'll move onto the brackets. I suspect most of the problems are we don't have multiple fallbacks for chunker - there are a whole load of hacks in the parser to handle not being able to memo and restore multiple times, so if need be I might fix all of that. |
@SomMeri I could release a beta version but generally I find people don't seem to use it. Instead I'm trying the opposite - releasing more often and fixing bugs in minor releases, so that people who want stability are best off going with the previous major release.last minor release. But I guess that could be better described on our website! |
@lukeapage Makes sense, I was thinking about this more this morning. This still does provide a lot of powerful and useful scenarios, and we could close off a LOT of stuff involving magic @content vars and passing rules into @media blocks within mixins (which should be part of added test cases), and maybe even some stuff around keyframes (although I haven't worked through it). And it's much better than a multi-line string to solve the problem, so it's still pretty awesome. Nice work. |
+1 This is fantastic, and coincidentally is exactly what I need to implement a few things for a project I'm working on (making a better |
…ing detached rulesets. Also now save the current chunk (may not be required).
…fixing both issues with 2 new test cases
Okay, I think thats alot more solid - should have fixed. Last thing on my todo list if no-one finds another issue with this branch is to add some test cases for error scenarios - using the detached ruleset as a property value etc! |
cool, take it there weren't any problems? I expanded the tests a bit more and wrote tests for errors. I'll call this ready to go and merge it in in a couple of days |
Everything I'd expected to work works like a charm. The only uncertain visibility thing I stepped into was:
At first I expected it to inherit On the other hand the following example still puts that in doubt:
result:
(I.e. |
Yes, I added a test case for exactly this, and its as I would expect.. |
@seven-phases-max Mixins normally search for variables/mixins at the point of their definition and when that fails, mixin will search in caller scope. It is as if mixins would have many "hidden" parameters. I think that it was intentional and not a bug, although I can not find issue where this was discussed. Rewriting your example:
compiles into:
So, I think that the above behavior is consistent with how mixins behave. |
@SomMeri I read your example as supporting @seven-phases-max and suggesting maybe we should fallback to allow searching in the current scope - because thats what mixins do. tbh I didn't realise that example worked. Should we keep it simple for now and consider adding support later (since we can always add but not take away) ? |
@lukeapage That depends on how much work it requires I think. This is useful feature many people want, so it should not be hold back without strong reason. In the long run, they should work the same way. It is easier for both users and coders that way. It is better if people do not have to remember all kinds of special cases and situations. I would be also perfectly ok with making mixins not to see callers scope - but that is necessary for now and would break many existing less projects, so it is not an option. Getting less scoping and variables right is already complicated enough, especially after you make things like #996 to work or after you make interpolated imports see also variables defined after them. It is the thing I spend most time on, anything else is comparatively straightforward. There always seem to be one more unexpected special case, so I'm trying to minimize them. It will get even more complicated with #1848. |
I guess it's better to add then if everything else is actually inheriting the callers scope. Unless this becomes too complicated already to bother (that's quite minor issue so we can always say "experimental", "partially implemented" and "not fully stabilized" yet :) |
For this feature it adds quite a bit of complexity - we have to wrap the ruleset in something that refuses to evaluate it properly (but stores scope) until its called and then adds the calling scope to the bottom of the stack! so I would leave it for now but consider it a known issue (then if its easier for less4js to be consistent it can be) |
I am in the process of doing this - it seems it is required for some media query combinations. I am going to change mixin definition to work in exactly the same way (instead of being special cased inside the eval of ruleset) |
detached rulesets as discussed on a few issues.
See tests.
Knocked up in an hour, needs some thoughts on if this is the best syntax and whether we go ahead and some extra tests and anything else I may have missed.