Skip to content

Commit

Permalink
ComboBox work + Description Property value sets for phetsims/sun#865
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanolson committed Dec 20, 2023
1 parent 0656c8c commit a22433c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions js/DescriptionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import TinyProperty from '../../axon/js/TinyProperty.js';
import localeOrderProperty from './i18n/localeOrderProperty.js';
import Multilink, { UnknownMultilink } from '../../axon/js/Multilink.js';
import dotRandom from '../../dot/js/dotRandom.js';
import TProperty from '../../axon/js/TProperty.js';

export type DescriptionStrings = {
locale: Locale;
Expand All @@ -33,6 +34,7 @@ export default class DescriptionContext {
private readonly links: Link[] = [];
private readonly listens: Listen[] = [];
private readonly assignments: Assignment[] = [];
private readonly propertyAssignments: PropertyAssignment[] = [];
private readonly multilinks: UnknownMultilink[] = [];

public get( tandemID: string ): PhetioObject | null {
Expand Down Expand Up @@ -97,6 +99,15 @@ export default class DescriptionContext {
node[ property ] = value;
}

public propertySet( property: TProperty<unknown>, value: unknown ): void {
const index = this.propertyAssignments.findIndex( assignment => assignment.property === property );
if ( index < 0 ) {
this.propertyAssignments.push( new PropertyAssignment( property, property.value ) );
}

property.value = value;
}

public dispose(): void {
// NOTE: can links/listens be tied to a tandem/object? So that if we "remove" the object, we will assume it's disposed?

Expand All @@ -123,6 +134,13 @@ export default class DescriptionContext {
assignment.target[ assignment.property ] = assignment.initialValue;
}
}
while ( this.propertyAssignments.length ) {
const assignment = this.propertyAssignments.pop()!;

if ( !assignment.property.isDisposed ) {
assignment.property.value = assignment.initialValue;
}
}
while ( this.multilinks.length ) {
const multilink = this.multilinks.pop()!;

Expand Down Expand Up @@ -255,4 +273,11 @@ class Assignment {
) {}
}

class PropertyAssignment {
public constructor(
public readonly property: TProperty<unknown>,
public readonly initialValue: unknown
) {}
}

joist.register( 'DescriptionContext', DescriptionContext );

0 comments on commit a22433c

Please sign in to comment.