-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Support nested maps in sass:map functions #1739
Comments
I'm not opposed to allowing Off-topic, but: $side-nav: (
bg gray,
color (
hover (
search yellow,
home red,
filter blue
)
)
); This isn't a map, it's a (nested) list of pairs. It works with map functions for compatibility reasons, but (in addition to being harder to read than a real map) it's likely to be much less efficient. |
@nex3 yes @blackfalcon is referring to my non-native library which used lists of pairs; I have a newer version which implements the same argument patterns for $map: ();
$map: merge($map, alpha, beta, (gamma: 5));
// n.b. equivalent to above
// $map: merge($map, alpha, beta, gamma, 5);
// result
// $map: (alpha: (beta: (gamma: 5))); |
Sorry for offtopic again, but I always wondered why Sass didn't use more understandable arrays (
Regarding In other words, such approach would be more flexible, since dosn't require strict order of arguments: // bulletproof way, since even if to API of `merge` will be added new methods,
// you would have more chances to be on safe side
$map: merge($map, $path: (alpha, beta, gamma), $set: true);
// or when you want shorter way and don't care much about any changes
$map: merge($myMap, (alpha, beta, gamma), true); In other words, I'm not enough experienced programmer to say, but as far as I know most languages trying to avoid relying on providing of endless arguments unless it's 100% guaranteed that there won't be no new methods for function in future. And, since nobody can foresee future... Anyway, I definitely vote for native support of |
@ArmorDarks The upside of this (so-called) WRT your other point, I'm sure this is because curly braces and square braces have very specific meanings in CSS and they wish to avoid confusion. Sass has always restricted itself to syntax styles that seem like part of CSS, and round braces are the only kind seen in vanilla CSS rules (e.g. css transforms etc.) |
Now that's good news! Too, I don't see a good reason to introduce |
If we're going to have a deep version of |
@chriseppstein what's your opinion on my comment above? |
Maybe issue #1349 should be reviewed once more. In case it will be implemented, you won't need endless arguments for However, ability to provide |
As much as I'm used to it, I'm pretty sure dot notation would be a bad idea in the current Sass echosystem. |
@hugogiraudel Can you share with us your opinion why is it so, in mentioned issue above? Thanks in advance |
@ArmorDarks contrived example: (cc @hugogiraudel) This is legal: foo.bar {
$map: (
nth(&, 1): 'baz',
foo: (bar: 'qux')
);
$value: map-get($map, nth(&, 1)); // essentially map-get($map, foo.bar);
test: inspect($value); // => 'baz'
} However, |
@ArmorDarks The short answer is that CSS (and thus Sass) is function based. If I am not mistaken, this is the main reason why Sass decided to go with functional notation instead of dot notation. Introducing the dot would not only be the source of hard to track bugs like the one explained by @davidkpiano, but also disrupt the global harmony. |
@hugogiraudel hm, can't agree with it. JavaScript is object-based, with hard rely on functions too. So, it shouldn't use dot notation too, since two ways to do same thing would make things disharmoned? Same for Python, etc. Not to mention, that JS has dot notation, brackets notation and special functions for getting values from ES6 maps (not objects). And you can write your own function to get values from objects too. Which makes about 4 ways to do, from first glance, same thing, but each approach was introduced to target specific purposes. @davidkpiano Thanks for your input. Though, I think that discussion should go into mentioned issue above, since we're diving into offtopic deeper. Since you replied here, I'm probably forced to reply here too. Regarding your example — there is no error here. With
Once again, I'm sorry for post, that raised another discussion here, which in fact should be discussed here #1349. Let's back to our current issue. I doubt that someone will argue with fact, that all would only benefit from having To summarize, I think that there were only few little things that were missed:
And my proposal to use Regarding my proposal — it seems that Sass community more appreciate endless arguments approach, and using of |
@ArmorDarks I agree with you about list/arrays and maps/objects in your comment. I would have liked to see these features implemented in the same way that In less than 3 seconds can you determine this $promo-bg: map-merge($promo-bg, (
origin-fix: ((100% + abs(map-get(map-get($promo-bg, foo), offset))) / (map-get(map-get($promo-bg, foo), width) / (100% + abs(map-get(map-get($promo-bg, foo), offset))))) / 2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------^
)); Here's the same test with dot notation. $promo-bg.foo.orgin-fix: ((100% + abs($promo-bg.foo.offset)) / ($promo-bg.foo.width / (100% + abs($promo-bg.foo.offset)))) / 2;
----------------------------------------------------------------------------------------------------------------------^ |
Keep in mind, for lexical parsing reasons (and potential complexity), that this is legal: $foo\.bar: 'baz';
.foo {
test: $foo\.bar; // => "baz"
} |
@tjbenton thanks for the support. I totally agree with you. More of it, I was always confused, why Sass preferred to use But am I the only person, that seeing, that in fact CSS's rules are objects itself, but only with For the sake of illustration, object-like ruleset in CSS: cssObject {
width: 1px;
color: #000;
} and JavaScript object: var cssObject = {
width: 1px,
color: #000
} I hope everybody can see how they are close. Why would we need to invent new syntax with We can open issue about |
@ArmorDarks Keep in mind that CSS rulesets are not exactly objects like JavaScript objects. This is legal in CSS but not legal as an object/dict/map: .ruleset {
font-size: 24px;
font-size: 2rem; // illegal in JS
} |
I would imagine the reason that both dot-notation and curly-brace-object-notation have not been used for Sass syntax, despite their well known meaning in other languages like JS, is that Sass' syntax has always been modelled to look like CSS and to not conflict with existing CSS syntactical patterns. Thus curly braces are exclusively used to delimit CSS declarations and dots—adjacent to strings—are exclusively used to indicate class selectors. This might seem unnecessary or perverse but in my observation keeping the language clear and accessible to new users has always been a high priority for Sass, and I believe it's correct |
@davidkpiano I'm talking not about literal similarity, but about same conceptual approach. CSS's rulestes are objects by it's nature, but with slightly another syntax @lunelson I can't agree with that. Introducing of |
While @davidkpiano is correct
@lunelson Adding dot notation and curly-brace object notation wouldn't conflict with existing CSS syntactical patterns. It would actually be more inline with CSS patterns that what is currently implemented. Dots
Brackets
Rule set/structure
$foo: {
bar: [
{
name: Lorem,
theme: a,
},
{
name: Lorem,
theme: c,
}
],
baz: {
qux: "garply"
}
}; Using As for the parsing of it, I don't think that it would be that difficult because the only dot/bracket notation has to be tied to a variable. When the variable is defined it has to be followed by a
While I would love to see sass change to use |
I think we have to create new issue about it, since particularly that issue related to |
@chriseppstein Reply to (comment) about map merge. I can see this working in a couple of different ways. Going under the assumption
All 3 No matter which is direction is chosen for dealing with merging maps, I would still like to see a If $map: (
foo: (
bar: (
baz: "baz",
qux: "qux",
quux: "quux",
corge: "corge",
grault: "grault"
)
),
);
Examples: With
|
This thread is getting extremely off-topic, so I'm locking it. In summary, we will add support for multiple keys to $map: (a: (b: (c: d)))
map-get($map, a, b, c) // => d
map-merge($map, a, b, c, x) // => (a: (b: (c: x))) |
I agree that separate |
I wonder, is that feature has been put on hold? |
I've created a small library of functions which transparently provide the API as proposed here; they provide nested |
Is anyone still working on this planned feature? Or has the plan been deprecated. |
There's a formal proposal in development. See the links directly above. |
I forgot to mention: since the proposal was accepted and the blog post soliciting comments published on 16 September, the countdown has begun for public comment. I'll give it two weeks with the option of going longer if there's substantial discussion. If there isn't, on 30 September it will be locked in and we'll ship the feature in Dart Sass. |
Closing this out because LibSass is now deprecated and we aren't expecting to add any additional features to it. |
Thanks! will there be a guide how to migrate from node-sass to dart-sass for front-end non-dart JavaScript applications & websites? |
Dart Sass supports the same JavaScript API as Node Sass, so just replace |
Edited by @nex3
@lunelson project sass-list-maps has support for nested list maps, using the
map-get-z function
.https://github.com/lunelson/sass-list-maps
The following example says it all:
FACT: Up to a point, even when using maps extended naming conventions come into play. Using
map-get-z
we can actually use structure to categorize versus naming conventions. I vote for structure every time.I don't mind using the plug-in, but I think that this is a feature that Sass should support natively.
The text was updated successfully, but these errors were encountered: