Skip to content

Commit

Permalink
Optionizing valid values, see #270
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Jul 26, 2024
1 parent 41c83c2 commit 35bfe10
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions js/common/model/MappedWrappedProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ import Property, { PropertyOptions } from '../../../../axon/js/Property.js';
import DynamicProperty from '../../../../axon/js/DynamicProperty.js';
import densityBuoyancyCommon from '../../densityBuoyancyCommon.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';

export type HasValueProperty = {
valueProperty: Property<number>;
};

type MappedWrappedPropertyOptions<T> = PropertyOptions<T>;

export default abstract class MappedWrappedProperty<T extends HasValueProperty> extends Property<T> {
protected readonly dynamicValueProperty: TReadOnlyProperty<number>;
public readonly customValue: T;
public readonly availableValues: T[];

protected constructor( initialValue: T, customValue: T, availableValues: T[], providedOptions: PropertyOptions<T> ) {

// TODO AV: Is this still needed? https://github.com/phetsims/density-buoyancy-common/issues/270
if ( availableValues.length > 0 ) {
protected constructor( initialValue: T, customValue: T, availableValues: T[], providedOptions: MappedWrappedPropertyOptions<T> ) {

// TODO AV: https://github.com/phetsims/density-buoyancy-common/issues/270 optionize please
providedOptions.validValues = availableValues;
}
const options = optionize<MappedWrappedPropertyOptions<T>, EmptySelfOptions, PropertyOptions<T>>()( {
validValues: availableValues
}, providedOptions );

super( initialValue, providedOptions );
super( initialValue, options );

this.dynamicValueProperty = new DynamicProperty<number, number, T>( this, {
bidirectional: false,
Expand Down

0 comments on commit 35bfe10

Please sign in to comment.