Skip to main content

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
Returns: number - The new value

decrement

Decreases the number by the specified amount.
number
default:"1"
The amount to decrease by
Returns: 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
Returns: 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

Since NumberAtom 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 random method uses a utility function that handles the range calculation
  • reset always returns to the initial value provided during creation
  • All operations trigger reactive updates
  • Direct assignments like numberAtom() = 5 will not work; use set() or the provided methods