Overview
reatomNumber creates an atom that manages numeric state with built-in methods for common number operations like increment, decrement, random, and reset.
Import
Type Signature
Parameters
number
default:"0"
The initial numeric value
string
default:"'numberAtom'"
Optional name for the atom, useful for debugging
Methods
increment
Increases the number by the specified amount.number
default:"1"
The amount to increase by
number - The new value
decrement
Decreases the number by the specified amount.number
default:"1"
The amount to decrease by
number - The new value
random
Sets the number to a random value within the specified range.number
The minimum value (inclusive). If not specified, uses a default minimum
number
The maximum value (exclusive). If not specified, uses a default maximum
number - The new random value
reset
Resets the number to its initial value. Returns:number - The initial value
Basic Usage
Advanced Usage
Counter with Min/Max Bounds
Score System
Progress Tracking
Random Number Generator
Using with Atom Methods
SinceNumberAtom extends Atom, you can use standard atom methods:
Notes
- Default increment/decrement amount is 1
- All methods return the new value after the operation
- The
randommethod uses a utility function that handles the range calculation resetalways returns to the initial value provided during creation- All operations trigger reactive updates
- Direct assignments like
numberAtom() = 5will not work; useset()or the provided methods