Performance: Built-in map functions
Using built-in map functions affects CSS preprocessing speed and the size of generated CSS, impacting initial page load and style calculation.
$colors: (primary: #0055ff, secondary: #ff5500, accent: #00ff55); $primary-color: map-get($colors, primary); $secondary-color: map-get($colors, secondary); $accent-color: map-get($colors, accent); .button { color: $primary-color; background-color: $secondary-color; border-color: $accent-color; }
$colors: (primary: #0055ff, secondary: #ff5500, accent: #00ff55); .button { color: map-get($colors, primary); background-color: map-get($colors, secondary); border-color: map-get($colors, accent); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated map-get calls | N/A (preprocessing only) | N/A | N/A | [X] Bad |
| Caching map values in variables | N/A (preprocessing only) | N/A | N/A | [OK] Good |
map-get(), map-has-key(), map-keys(), or map-values()?map-get() retrieves a value, map-keys() lists keys, map-values() lists values, and map-has-key() checks if a key exists.map-has-key() returns true or false if a key is in the map."color" from a Sass map named $theme?map-get($map, $key) where the key is a string or identifier."color" is correct.$settings: ("font": "Arial", "size": 16px, "color": #333);map-keys($settings) return?map-keys() returns a list of keys from the map, preserving quotes if keys are strings.$map: ("a": 1, "b": 2);
$value: map-get($map, c);$colors: ("primary": #0055ff, "secondary": #ff5500, "tertiary": #00ff55);"background": #f0f0f0 to $colors without overwriting existing keys?map-merge() which combines maps.map-merge($colors, ("background": #f0f0f0)) adds the new pair without removing existing ones.Pass the test and this pattern moves unknown