Skip to content

BooleanProperty

BooleanProperty (from scenerystack/axon) is a Property whose value is constrained to boolean — truthy/falsy non-boolean values are rejected by its built-in validator, not silently coerced. It's the standard type for simulation flags like "is the sim paused," "is this checkbox checked," or "is this Node visible."

ts
import { BooleanProperty } from 'scenerystack/axon';

const isPlayingProperty = new BooleanProperty( true );

isPlayingProperty.link( isPlaying => {
  console.log( isPlaying ? 'playing' : 'paused' );
} );

isPlayingProperty.toggle(); // logs "paused"

Methods

BooleanProperty adds exactly one method beyond what it inherits from Property:

MethodEffect
toggle()Sets value = !value

Everything else — value, link, lazyLink, reset, dispose, and so on — comes from Property<boolean>; see the Property reference for the full list.

Options

BooleanPropertyOptions is PropertyOptions<boolean> with isValidValue, valueType, and phetioValueType removed — BooleanProperty sets valueType: 'boolean' and the PhET-iO BooleanIO type internally, so you cannot override them.

ts
const isVisibleProperty = new BooleanProperty( false, {
  // any remaining PropertyOptions, e.g.:
  reentrant: false
} );

Combining booleans

To derive a boolean from other Properties (a && b, a || b, !a), don't write your own listener — use DerivedProperty.and, .or, and .not, which return a read-only TReadOnlyProperty<boolean> kept automatically in sync.