Skip to content

Commit 5ef053c

Browse files
committed
[css-values-5] Add an image showing the random caching, and rephrase the intro. #13132
1 parent ba60227 commit 5ef053c

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

‎css-values-5/Overview.bs‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,25 +2781,28 @@ Evaluating Random Values</h3>
27812781
<h3 id=random-caching>
27822782
Caching Random Values: the <<random-value-sharing>> value</h3>
27832783

2784-
In a programming language like JavaScript,
2785-
there's a clear temporal ordering to code,
2786-
so you can tell exactly <em>when</em> something like a call to {{Math/random()|Math.random()}} is evaluated.
2787-
You can also store the results in a variable,
2788-
making it clear when you're reusing a single random value in multiple places,
2789-
versus using a distinct random value in each location.
2790-
2791-
CSS, on the other hand, is a declarative language
2792-
(code is not "executed" in any particular order,
2793-
nor is there any control over how many times something is "executed");
2794-
it makes it very easy to apply identical styles to multiple elements
2795-
but difficult to specify distinct values for each of them
2796-
(making it unclear whether a property using ''random()''
2797-
is meant to resolve to the same value on each element it's applied to
2798-
or to distinct values on each);
2799-
and it has very limited "variable" functionality
2800-
(making it difficult to intentionally reuse a particular randomly-generated value in several places).
2801-
2802-
To resolve these issues,
2784+
CSS is a declarative language,
2785+
so functions don't have a specific "time" when they're "evaluated",
2786+
which makes it tricky to establish exactly when values are "shared" vs "unique".
2787+
The [=random functions=] default to making their values <em>as unique as possible</em>;
2788+
even if you write the exact same ''random()'' function in multiple places,
2789+
or apply the same ''random()'' function to multiple elements,
2790+
each instance will resolve to different values.
2791+
2792+
If some degree of sharing <em>is</em> wanted,
2793+
the <<random-value-sharing>> value can be specified,
2794+
forcing values to be shared between properties and/or between elements.
2795+
2796+
<figure class=example>
2797+
<img src="images/random-sharing.png">
2798+
<figcaption>
2799+
Providing a custom ident (''--foo'') allows multiple properties to share a value;<br>
2800+
providing ''element-shared'' allows multiple elements to share a value;<br>
2801+
providing both allow multiple properties across multiple elemnents to share.
2802+
</figcaption>
2803+
</figure>
2804+
2805+
More specifically,
28032806
the ''random()'' and ''random-item()'' functions are defined to generate random values
28042807
under the following caching semantics:
28052808

297 KB
Loading

0 commit comments

Comments
 (0)