-
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
Public variables on namespaces #1848
Comments
👍 |
yes. I am not against them. We could implement them as they used to be implemented when they were part of less. see #6 !! |
though I'd like to see some thought about the syntax. possibly only allowing on just throwing out some other syntaxes
|
|
yes to b clear I'd suggest the first 2 depending on whether it was an interpolated format or not (e.g.
the grammer being |
+1 to
Especially during interpolation:
|
The idea of prefixing the namespace with an
You're referencing the namespace with |
I agree but this means it doesn't work in interpolated cases unless you have 2 differing syntaxes. I don't like |
I don't think it necessarily puts
The first, like @Soviut says, reads as "within the namespace #ns, reference the @SiZe variable" (and would be semantically in tune with namespaced mixins). The second reads as "within a variable context, reference size from the #ns namespace" (and would be semantically in tune with interpolation). However, I still feel like
Hmm... it's actually hard to say which feels better. But... much as I've said on other issues, it might still suggest both could be correct? (To summarize, I believe |
Keep in mind that we should be able to set/override variables within namespaces so we need the syntax to work with that as well.
|
Agreed. Otherwise libraries would wrap vars in namespaces, but you wouldn't be able to "configure" the library. |
(crosslinking the topic where this feature and the syntax emerged before: #1357, just for reference). |
Just a thought on
We may to not allow to use that in a selector interpolation at all. Just the same way as we don't allow any functions or arithmetic (or anything else except a simple variable) to be there. After all one can always write:
Yep, a bit restrictive and makes the selector interpolation case verbose, but if it makes the syntax less confusing in other situations... why not? |
I just had this come up on a project, where I really really needed to namespace my variables, but also wanted to expose them. My solution:
I'm assuming that one can, by design, do something like the above? The downside, of course, is needing to "import" colors into every scope that needs them available. But, basically, by "setting" variables via a mixin, then calling the mixin name in a scope, it has the desired effect. Which leads me to the idea that for setting variables, because of inheritance, it doesn't need a special "setting" format. It can be:
|
@seven-phases-max I think your idea is valid, or we could just opt to not switchup the syntax within the interpolation syntax.
On the one hand, it's possibly one extra @, but at least everyone would know what the heck you were referring to. |
I guess yes. I believe it was considered as something dangerous and unintended during -> 1.4.x move mostly because of various variable leaking issues emerged first and its general strangeness at those times. But now it's pretty much "standard" functionality and it's too late to prohibit this even if we'd want to. |
Don't forget that first of all the
In this context the second part of the propose, i.e. |
@seven-phases-max The scope wouldn't be open. It would still only live in the context of the local scope (sort of). I get what you're saying, but SCRAP THAT, AN IDEA JUST HAPPENED. I had examples with
I love that we now have detached rulesets. I was looking at those and marvelling at what we could do with them. At some point some time ago, looking at the new detached rulesets, I thought, "You know, it would be great if I could extract property values from the ruleset, or even use mixin guards against a specific property value. Maybe I'll suggest that as a feature request". I just realized that the goals of name-spaced variables, and the idea of referencing properties of a ruleset can actually be the same goal.
(When I was thinking about a specific property of a set, it seemed similar to me as a specific attribute of an element, hence I went straight to So, what I mean is: since detached rulesets already exist, we already have a kind of syntax to assign a set of property / values to a single variable. What's missing is property accessors. With them, we could also do:
What's nice is that it feels a little cleaner in interpolation without dots or
For library overrides:
What do you guys think of this? EDIT: Note below that the "ruleset syntax for variables" idea should be attributed to @jonschlinkert, proposed in #1357. |
That's just "properies are variables!" feature. A "detached ruleset" is still a normal ruleset (just not explicitly named), i.e. if we can write |
Yep, I realize it's double-purposing, but that's exactly the point. The detached ruleset syntax already closely matches a name-spaced variable set suggested by others. Look at this syntax from @jonschlinkert for variables (the proposal he made in #1357).
This is the exact syntax for detached rulesets. In other words, by solving a problem elsewhere, we've already implemented part 1 of his proposal. Now, it's just a matter of implementing part 2: retrieval. The only difference is that I'm suggesting Accessing properties of other rulesets (non-detached, i.e. not assigned to a variable) is interesting, but I don't think it necessarily follows that we have to do that. Detached rulesets could be a special case. |
Attribute accessors do seem to make a lot of sense. The syntax is potentially cleaner than the |
Another problem is that inside
In that sense more classic stuff seems to be a bit more easy:
I don't know how much it is contradictory with selector attributes though... |
I feel like you may be creating problems that may not exist. For one, are variables supported in detached rulesets? On the off chance it is or we ever get there, what's wrong with this?
Then, you could support derived properties:
To me, you've made an argument FOR this syntax, since you could create calculated properties, which sounds awesome. In your second example, the syntax is less graceful or intuitive for interpolated vars. ( |
So, yes, what I'm proposing is that you could use properties AS namespaced variables, but, because they are rulesets, you could ALSO use variables as variables in the ruleset, if we wanted to (or already) permit variables in the ruleset.
This, however, wouldn't be completely necessary if we don't currently evaluate variables in detached rulesets. |
So this was is very similar to the format that was in the original ruby less - read #6 "Setting" "constants" or overriding constants in a "namespace" is another matter. For me the biggest problem is that constants are constants.. changing the constants from one scope in another seems like a big ask for a compiler written around declarative statements. The technical problem is that less evaluates in one pass and that constants can be introduced by a mixin call - if the contents of that mixin could be overridden at some point, is the value still a constant or does it start becoming a variable - e.g. # pallette {
color: red;
}
@normal-var: red;
.class {
color: @normal-var;
color2: #pallette[color];
#palette[color]: green;
@normal-var: blue;
}
.class2 {
color: @normal-var;
color2: #pallette[color];
} So.. you would think (or I would think) that constants would work the same way.. but its hard to define #pallette {
@color: green; // or does this stay the original color?
}
.class {
color: blue;
color2: green; // assuming the later variable overrides
}
.class2 {
color: red;
color2: green; // or was this overridden for that scope only so this should be red?
} and I guess the use-case for setting constants is that without that it is just a grouping mechanism for variables. with setting it allows libraries to group and keep seperate their own constants. an alternative mechanism for overriding a variable might be..
and I guess I prefer that. One reason I bring this up is that it effects what @matthew-dean is saying about detached rulesets - it would be pretty weird to only half override a detached ruleset assigned to a variable, like I did in the second example, where as it isn't weird to just look up the variable from the last matching namespace with that property in it. |
Nothing. My point is that "detached rulesets" should not be treated as something special. Notice that "detached rulesets" feature introduced no special syntax except Now here is the problem: if we treat a detached ruleset as some kind of new special namespace (so that only
See now? So that's my point: with
Yes, everything that can be used in a standard ruleset can be used in a detached ruleset (because the dt-ruleset is a standard ruleset too except its "name"). So this code is currently valid (will be in 1.7.0):
So no, I'm not against syntax, I'm against treating the DR feature as a yet another new special kind of namespace (so that instead of one namespace abstraction with problems we'll have two namespace abstractions with problems :) |
My favourite syntax for reading variables from namespaces is:
It is simple and seems to me to be the most intuitive, it is almost the same as calling mixins. I do not like The
or even chain them for much longer:
|
The biggest use case for namespace variable modification seems to be library configuration. Going wild with detached rulesets, it would be possible to keep less as declarative language, variables as constants and have library configuration too:
The advantage is that then it would be possible to have two "copies" of the same library initialized with two different arguments:
Other then that, i like the the trick shown in this comment, it feels to be "lessy". If it would be combined with variables reading, then it would be possible to do following:
|
What if we extend |
@calvinjuarez - You, my friend, are a fucking genius. You're right, that would effectively make You win the Internets today. I love this idea. |
Well, this thread has seen essentially that suggestion before. :P #fullCircle I'll update the gist. |
Ok, but what would be a syntax for accessing/defining just selector then? (E.g. |
@seven-phases-max I think that's a separate issue. To quote myself:
I think @lukeapage had a good comment about not trying to be over-clever with syntax to the point of ambiguity. So if accessing just selector is needed (and I'm not convinced it is), that should be tracked as a separate issue with its own solution. |
Ha, yes, true. I know Luke had suggested that very thing with variables, but then properties got in and confused things. That is, we started to debate if So yes, I didn't mean to suggest it was entirely your idea--there are a lot of brilliant people here--just that you simplified and clarified 3 different threads made over a year with one simple suggestion. In the end, you brought it all together, so I'm giving you credit for that. :-) @seven-phases-max Just so that I don't totally discard your question, I think at this point I would lean towards |
Yes, but if you take Technically, originally for the selector stuff, the sketching syntax proposal was something like
is exactly what goes against those things you quoted above. |
Right. It would go against what I quoted. So I'm saying I'm against it. That is, I would be against And, I'm saying assigning selectors to variables seems like much less of a problem. I'm not sure we need it. So the potential future conflict against a desire to write |
So you mean you don't need a hypothetical |
Touché. Not necessarily. I think, in that example, the assignment to a variable was just to allow the variable to be passed to the
Another way to put it, if we have a core function in which we're inputting a selector, we should find a way to pass that selector without specially wrapping it or assigning it to a variable, just for the purpose of passing it into the function. If we do, it's just extra syntax that we've forced ourselves to create. Yes, the outcome of this issue may shift a few of those other pending issues, but I think that's okay. I think this is the more valuable one to get right. |
I don't like .selector {
min-height: 1px;
width: 100%;
}
@var: $(.selector); As such, to my mind, the similarity to jQuery is a big reason not to use And speaking of distinct and fresh, I think the only symbols as "safe" as |
@calvinjuarez Agree for the same reasons. It looks like jQuery, but isn't. But, as I said, my recommendation is that we move that discussion to issue... #2270 ? And narrow the scope of this issue back to accessing within namespaces. |
👍 sounds good. Sorry about that. |
No need to be sorry. Hey, if at the end, we get something cool done, it's all good. 😄 |
What about It's already being used as a template token to indicate 'previous selector set' when used inside a selector declaration. Might as well make that go full-circle and create a |
@matthew-dean I think For this thread, are there any objections to the following for namespaced variable accessing? @{#ns var} // and `@{#ns > var}` (w/ `#ns@var` as sugar in the next major version)
Then this can be marked as "ready", and we can move the property access discussion ( |
No objections to those variants. I also think prepending |
this feature would be very similar to maps in Sass. hopefully the syntax for retrieving a value will be better than |
Despite this seeming close to final syntax, I think this syntax needs to be revisited, based on discussion in #2767 and less/less-meta#10. But not a total revisiting. @seven-phases-max's arguments in this thread toward That is, if you support DR variable access (which aligning ruleset behavior may allow), then And @lukeapage's concerns about mixins introducing constants within scope might be lessened if we make scoping rules a bit more robust. In short, I would say this should be part of a larger syntax review in 3.0 (as part of the roadmap proposal) to make sure all these pieces together make sense. |
As I mentioned in the comment above, this discussion got reset a bit because of changes that are part of some syntax and behavior clean-up discussions for 3.0. Because the discussion about syntax covers more than just this issue (but consistency with other 3.0 proposals), I'm going to close this issue in favor of the discussion here: less/less-meta#12. It would be great if anyone involved in this discussion could give their 2 cents on that issue. |
I realize this isn't a new topic but it I think the time has come to consider implementing public variables on namespaces. Many prominent libraries for LESS (bootstrap, hat, etc.), have emerged, each with dozens of configuration variables which could very well overlap and conflict with each other.
Currently, namespaces support private variables, the only way to get at them is via mixins within the namespace and those mixins can then be used externally; Sort of like a closure:
Which yields:
However, I think it would be very handy to do the following:
As well as update those variables within the namespace:
The text was updated successfully, but these errors were encountered: