Skip to content

Commit

Permalink
Adjust RichText stringProperty API to accept read-only Properties sim…
Browse files Browse the repository at this point in the history
…ilarly to Text, see #1671
  • Loading branch information
jonathanolson committed Nov 5, 2024
1 parent e1300ab commit 2275077
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions js/nodes/RichText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,15 @@ export default class RichText extends WidthSizable( Node ) {

/**
* See documentation for Node.setVisibleProperty, except this is for the text string.
*
* NOTE: Setting the .string after passing a truly read-only Property will fail at runtime. We choose to allow passing
* in read-only Properties for convenience.
*/
public setStringProperty( newTarget: TProperty<string> | null ): this {
return this._stringProperty.setTargetProperty( newTarget, this, RichText.STRING_PROPERTY_TANDEM_NAME );
public setStringProperty( newTarget: TReadOnlyProperty<string> | null ): this {
return this._stringProperty.setTargetProperty( newTarget as TProperty<string>, this, RichText.STRING_PROPERTY_TANDEM_NAME );
}

public set stringProperty( property: TProperty<string> | null ) { this.setStringProperty( property ); }
public set stringProperty( property: TReadOnlyProperty<string> | null ) { this.setStringProperty( property ); }

public get stringProperty(): TProperty<string> { return this.getStringProperty(); }

Expand Down
3 changes: 3 additions & 0 deletions js/nodes/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ export default class Text extends Paintable( Node ) {

/**
* See documentation for Node.setVisibleProperty, except this is for the text string.
*
* NOTE: Setting the .string after passing a truly read-only Property will fail at runtime. We choose to allow passing
* in read-only Properties for convenience.
*/
public setStringProperty( newTarget: TReadOnlyProperty<string> | null ): this {
return this._stringProperty.setTargetProperty( newTarget as TProperty<string>, this, Text.STRING_PROPERTY_TANDEM_NAME );
Expand Down

0 comments on commit 2275077

Please sign in to comment.