Skip to content

Commit

Permalink
remove as many LinkableElement usages as possible, using PhetioProper…
Browse files Browse the repository at this point in the history
…ty where we have to, phetsims/tandem#299

Signed-off-by: Michael Kauzmann <[email protected]>
  • Loading branch information
zepumph committed Jun 20, 2023
1 parent bdaee27 commit 9a1468f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
3 changes: 1 addition & 2 deletions js/DynamicProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ import Property, { PropertyOptions } from './Property.js';
import ReadOnlyProperty from './ReadOnlyProperty.js';
import optionize from '../../phet-core/js/optionize.js';
import TReadOnlyProperty from './TReadOnlyProperty.js';
import LinkableProperty from './LinkableProperty.js';

export type TNullableProperty<T> = TReadOnlyProperty<T | null> | TReadOnlyProperty<T>;

Expand Down Expand Up @@ -142,7 +141,7 @@ export type DynamicPropertyOptions<ThisValueType, InnerValueType, OuterValueType
// } );
// Here, ThisValueType=number (we're a Property<number>). You've passed in a Property<Foo>, so OuterValueType is a Foo.
// InnerValueType is what we get from our derive (Color), and what the parameter of our map is.
export default class DynamicProperty<ThisValueType, InnerValueType, OuterValueType> extends ReadOnlyProperty<ThisValueType> implements LinkableProperty<ThisValueType> {
export default class DynamicProperty<ThisValueType, InnerValueType, OuterValueType> extends ReadOnlyProperty<ThisValueType> implements TProperty<ThisValueType> {

// Set to true when this Property's value is changing from an external source.
private isExternallyChanging: boolean;
Expand Down
14 changes: 0 additions & 14 deletions js/LinkableProperty.ts

This file was deleted.

14 changes: 0 additions & 14 deletions js/LinkableReadOnlyProperty.ts

This file was deleted.

12 changes: 12 additions & 0 deletions js/PhetioProperty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2023, University of Colorado Boulder

import PhetioObject from '../../tandem/js/PhetioObject.js';
import TProperty from './TProperty.js';

// When calling PhetioObject.addLinkedElement, the parameter must be a PhetioObject, so this type alias covers that ground
// and helps with cases like LocalizedStringProperty (and DynamicProperty in general) which satisfies the TProperty
// interface and is a PhetioObject. It is best to try to use the ReadOnlyProperty class hierarchy first, and this Type
// Alias can help cover cases where that doesn't work, see https://github.com/phetsims/tandem/issues/299
type PhetioProperty<T> = TProperty<T> & PhetioObject;

export default PhetioProperty;
4 changes: 2 additions & 2 deletions js/TRangedProperty.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2023, University of Colorado Boulder

import LinkableProperty from './LinkableProperty.js';
import TReadOnlyProperty from './TReadOnlyProperty.js';
import Range from '../../dot/js/Range.js';
import IntentionalAny from '../../phet-core/js/types/IntentionalAny.js';
import ReadOnlyProperty from './ReadOnlyProperty.js';
import TinyProperty from './TinyProperty.js';
import PhetioProperty from './PhetioProperty.js';

// Minimal types for Properties that support a rangeProperty.
export type TRangedProperty = LinkableProperty<number> & { range: Range; readonly rangeProperty: TReadOnlyProperty<Range> };
export type TRangedProperty = PhetioProperty<number> & { range: Range; readonly rangeProperty: TReadOnlyProperty<Range> };

export function isTRangedProperty( something: IntentionalAny ): something is TRangedProperty {
return ( something instanceof ReadOnlyProperty || something instanceof TinyProperty ) && something.isSettable() &&
Expand Down

0 comments on commit 9a1468f

Please sign in to comment.