Skip to content

Commit

Permalink
fix Disposable, removing disposer and options and using disposeEmitter,
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Apr 4, 2023
1 parent 4dd4290 commit 4c32be2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 3 additions & 4 deletions js/PhetioObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import TandemConstants, { PhetioID, PhetioObjectMetadata } from './TandemConstan
import tandemNamespace from './tandemNamespace.js';
import IOType from './types/IOType.js';
import IntentionalAny from '../../phet-core/js/types/IntentionalAny.js';
import Disposable, { DisposableOptions } from '../../axon/js/Disposable.js';
import Disposable from '../../axon/js/Disposable.js';
import LinkableElement from './LinkableElement.js';

// constants
Expand Down Expand Up @@ -135,8 +135,7 @@ type SelfOptions = StrictOmit<Partial<PhetioObjectMetadata>, 'phetioTypeName' |
// sim.screen1.view.upperThermometerNode
tandemNameSuffix?: string | string[] | null;
};
type ParentOptions = DisposableOptions;
export type PhetioObjectOptions = SelfOptions & ParentOptions;
export type PhetioObjectOptions = SelfOptions;

type PhetioObjectMetadataKeys = keyof ( StrictOmit<PhetioObjectMetadata, 'phetioTypeName' | 'phetioDynamicElementName'> ) | 'phetioType';
export type PhetioObjectMetadataInput = Pick<PhetioObject, PhetioObjectMetadataKeys>;
Expand Down Expand Up @@ -174,7 +173,7 @@ class PhetioObject extends Disposable {
public phetioID: PhetioID;

public constructor( options?: PhetioObjectOptions ) {
super( options );
super();

this.tandem = DEFAULTS.tandem;
this.phetioID = this.tandem.phetioID;
Expand Down
11 changes: 7 additions & 4 deletions js/PhetioObjectTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ QUnit.test( 'PhetioObject end without start', assert => {
}
} );

QUnit.test( 'PhetioObject disposer', assert => {
QUnit.test( 'PhetioObject is a Disposable', assert => {
const object1 = new PhetioObject();
const object2 = new PhetioObject( {
disposer: object1
} );

assert.ok( !!object1.disposeEmitter, 'disposeEmitter needed' );

const object2 = new PhetioObject();

object1.disposeEmitter.addListener( () => object2.dispose() );

assert.ok( !object1.isDisposed, '1 is not disposed' );
assert.ok( !object2.isDisposed, '2 is not disposed' );
Expand Down

0 comments on commit 4c32be2

Please sign in to comment.