Skip to content

MappedProperty

Overview

Similar to DerivedProperty, but restricted to one Property and provides value-mapped and bidirectional support. It's basically a DynamicProperty where you don't need to wrap it in an additional Property, and is typed a bit easier

For example:

const stringProperty = new Property<string>( 'hello' ); const lengthProperty = new MappedProperty( stringProperty, { map: ( str: string ) => str.length } ); lengthProperty.value; // 5 stringProperty.value = 'hi'; lengthProperty.value; // 2

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class MappedProperty

import { MappedProperty } from 'scenerystack/axon';

Constructor

new MappedProperty( property : TReadOnlyProperty<InputValueType>, providedOptions? : MappedPropertyOptions<ThisValueType, InputValueType> )

Instance Methods

Type MappedPropertyOptions

import type { MappedPropertyOptions } from 'scenerystack/axon';
  • bidirectional?: boolean
    If set to true then changes to this Property (if valuePropertyProperty.value is non-null at the time) will also be made to valuePropertyProperty.value.
  • map?: ( ( inputValue: InputValueType ) => ThisValueType ) | KeysMatching<InputValueType, ThisValueType>
    Maps our input Property value to/from this Property's value. See top-level documentation for usage. If it's a string, it will grab that named property out (e.g. it's like passing u => u[ derive ])
  • inverseMap?: ( ( thisValue: ThisValueType ) => InputValueType ) | KeysMatching<ThisValueType, InputValueType>
  • & StrictOmit<DynamicPropertyOptions<ThisValueType, InputValueType, TReadOnlyProperty<InputValueType>>, "defaultValue" | "derive">

Source Code

See the source for MappedProperty.ts in the axon repository.