pick() in state()
expressionsince 0.5experimentalrequires runtimeIn state() and in mutations: one value at random each time the expression is evaluated, once per owner in state(), at every event in set().
On this page · 8 sections+−
Syntax
pick(<value>, …) | pick(split(<text>, "<delimiter>"))registry syntax: pick(value, ...) | pick(split(text, "delimiter"))
Parameters
- valuesliterals of one type, or
split(…)one or more - All values must have the same type.
Return value
One of the values. With nothing to pick, set() changes nothing and state() starts as "".
Example
dice.cssreactive
.die { --face: state(1);}.die:on(click) { --face: set(pick(1, 2, 3, 4, 5, 6));}state()Function · hover any red tokenMakes each matching element the owner of an independent state with an initial value.Reference →
Behavior
- In
state()each owner picks once, when its state is created. - In
set()a new value is picked on every event. - In an
:on()mutation,--face: set(pick(1, 2, 3, 4, 5, 6))picks a new value at each event.
Supported contexts
- The initial value of
--x: state(…), the expression of an:on()mutation. In other declarationspick()is the stable value function: seepick().
Limitations
- Experimental since 0.5.0.
- Values of one type only.
Related
Experimental · syntax may change between minor versions