Skip to content

Commit

Permalink
use isDisposable:false where appropriate, phetsims/axon#436
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Jul 5, 2023
1 parent 4c67f62 commit 32557dd
Show file tree
Hide file tree
Showing 41 changed files with 110 additions and 342 deletions.
7 changes: 1 addition & 6 deletions js/common/model/Allele.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
Expand Down Expand Up @@ -56,6 +55,7 @@ export default class Allele extends PhetioObject {
const options = optionize<AlleleOptions, SelfOptions, PhetioObjectOptions>()( {

// PhetioObjectOptions
isDisposable: false,
phetioType: Allele.AlleleIO,
phetioState: false
}, providedOptions );
Expand All @@ -70,11 +70,6 @@ export default class Allele extends PhetioObject {
this.tandemNamePrefix = options.tandemNamePrefix;
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

/**
* AlleleIO implements 'Reference type serialization', as described in the Serialization section of
* https://github.com/phetsims/phet-io/blob/master/doc/phet-io-instrumentation-technical-guide.md#serialization
Expand Down
7 changes: 1 addition & 6 deletions js/common/model/DataProbe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Property from '../../../../axon/js/Property.js';
Expand Down Expand Up @@ -51,6 +50,7 @@ export default class DataProbe extends PhetioObject {
const options = optionize<DataProbeOptions, SelfOptions, PhetioObjectOptions>()( {

// PhetioObjectOptions
isDisposable: false,
phetioState: false // to prevent serialization, because we don't have an IO Type
}, providedOptions );

Expand Down Expand Up @@ -91,11 +91,6 @@ export default class DataProbe extends PhetioObject {
this.visibleProperty.reset();
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

/**
* Gets the bunny counts for a specific generation value.
* @param dataProbeGeneration - current position of the data probe on the x-axis
Expand Down
7 changes: 1 addition & 6 deletions js/common/model/Gene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Property from '../../../../axon/js/Property.js';
Expand Down Expand Up @@ -108,6 +107,7 @@ export default class Gene extends PhetioObject {
const options = optionize<GeneOptions, SelfOptions, PhetioObjectOptions>()( {

// PhetioObjectOptions
isDisposable: false,
phetioType: Gene.GeneIO,
phetioState: false
}, providedOptions );
Expand Down Expand Up @@ -163,11 +163,6 @@ export default class Gene extends PhetioObject {
this.mutationComingProperty.reset();
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

/**
* Cancels a mutation that has been scheduled.
*/
Expand Down
7 changes: 1 addition & 6 deletions js/common/model/GenerationClock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
Expand Down Expand Up @@ -46,6 +45,7 @@ export default class GenerationClock extends PhetioObject {
const options = optionize<GenerationClockOptions, SelfOptions, PhetioObjectOptions>()( {

// PhetioObjectOptions
isDisposable: false,
phetioState: false, // to prevent serialization, because we don't have an IO Type
phetioDocumentation: 'the clock that marks the duration of a generation'
}, providedOptions );
Expand Down Expand Up @@ -113,11 +113,6 @@ export default class GenerationClock extends PhetioObject {
this.timeInSecondsProperty.reset();
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

/**
* @param dt - the time step, in seconds
*/
Expand Down
2 changes: 1 addition & 1 deletion js/common/model/Organism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type SelfOptions = {
};

export type OrganismOptions = SelfOptions &
PickOptional<PhetioObjectOptions, 'tandem' | 'phetioType' | 'phetioDynamicElement'>;
PickOptional<PhetioObjectOptions, 'tandem' | 'phetioType' | 'phetioDynamicElement' | 'isDisposable'>;

export default class Organism extends PhetioObject {

Expand Down
7 changes: 1 addition & 6 deletions js/common/model/PedigreeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import Property from '../../../../axon/js/Property.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
Expand All @@ -30,6 +29,7 @@ export default class PedigreeModel extends PhetioObject {
const options = optionize<PedigreeModelOptions, SelfOptions, PhetioObjectOptions>()( {

// PhetioObjectOptions
isDisposable: false,
phetioState: false, // to prevent serialization, because we don't have an IO Type
phetioDocumentation: 'model elements that are specific to the Pedigree feature'
}, providedOptions );
Expand Down Expand Up @@ -57,11 +57,6 @@ export default class PedigreeModel extends PhetioObject {
this.earsAllelesVisibleProperty.reset();
this.teethAllelesVisibleProperty.reset();
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}
}

naturalSelection.register( 'PedigreeModel', PedigreeModel );
7 changes: 1 addition & 6 deletions js/common/model/PopulationModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import createObservableArray, { ObservableArray } from '../../../../axon/js/createObservableArray.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
Expand Down Expand Up @@ -99,6 +98,7 @@ export default class PopulationModel extends PhetioObject {
xAxisLength: 5,

// PhetioObjectOptions
isDisposable: false,
phetioState: false, // to prevent serialization, because we don't have an IO Type
phetioDocumentation: 'model elements that are specific to the Population feature'
}, providedOptions );
Expand Down Expand Up @@ -253,11 +253,6 @@ export default class PopulationModel extends PhetioObject {
} );
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

public reset(): void {

// Clear data points. Use this approach because these are instances of ObservableArrayDef.
Expand Down
7 changes: 1 addition & 6 deletions js/common/model/ProportionsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import BooleanProperty from '../../../../axon/js/BooleanProperty.js';
import createObservableArray, { ObservableArray } from '../../../../axon/js/createObservableArray.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
Expand Down Expand Up @@ -73,6 +72,7 @@ export default class ProportionsModel extends PhetioObject {
const options = optionize<ProportionsModelOptions, SelfOptions, PhetioObjectOptions>()( {

// PhetioObjectOptions
isDisposable: false,
phetioState: false, // to prevent serialization, because we don't have an IO Type
phetioDocumentation: 'model elements that are specific to the Proportions feature'
}, providedOptions );
Expand Down Expand Up @@ -226,11 +226,6 @@ export default class ProportionsModel extends PhetioObject {
this.teethVisibleProperty.reset();
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

/**
* Records start counts for the current generation.
*/
Expand Down
17 changes: 7 additions & 10 deletions js/common/model/Shrub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,22 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import naturalSelection from '../../naturalSelection.js';
import EnvironmentModelViewTransform from './EnvironmentModelViewTransform.js';
import Organism, { OrganismOptions } from './Organism.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';

type SelfOptions = EmptySelfOptions;

type ShrubOptions = SelfOptions & OrganismOptions;
type ShrubOptions = SelfOptions & StrictOmit<OrganismOptions, 'isDisposable'>;

export default class Shrub extends Organism {

public constructor( modelViewTransform: EnvironmentModelViewTransform, options?: ShrubOptions ) {
super( modelViewTransform, options );
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
public constructor( modelViewTransform: EnvironmentModelViewTransform, providedOptions?: ShrubOptions ) {
super( modelViewTransform, optionize<ShrubOptions, SelfOptions, OrganismOptions>()( {
isDisposable: false
}, providedOptions ) );
}
}

Expand Down
22 changes: 4 additions & 18 deletions js/common/view/AddMutationsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize, { combineOptions, EmptySelfOptions, optionize3 } from '../../../../phet-core/js/optionize.js';
Expand Down Expand Up @@ -113,11 +112,6 @@ export default class AddMutationsPanel extends NaturalSelectionPanel {
this.rows = rows;
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}

/**
* Gets the row that corresponds to a gene.
*/
Expand Down Expand Up @@ -164,7 +158,8 @@ class Row extends HBox {
spacing: COLUMN_SPACING,
visiblePropertyOptions: {
phetioFeatured: true
}
},
isDisposable: false
}, providedOptions );

// label that indicates the gene, to the left of the push buttons
Expand Down Expand Up @@ -266,11 +261,6 @@ class Row extends HBox {

this.gene = gene;
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}
}

type MutationButtonSelfOptions = EmptySelfOptions;
Expand Down Expand Up @@ -389,7 +379,8 @@ class TitleNode extends Text {

// TextOptions
font: NaturalSelectionConstants.TITLE_FONT,
maxWidth: 180 // determined empirically
maxWidth: 180, // determined empirically
isDisposable: false
}, providedOptions );

const stringProperty = new DerivedStringProperty( [
Expand All @@ -404,11 +395,6 @@ class TitleNode extends Text {

super( stringProperty, options );
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}
}

naturalSelection.register( 'AddMutationsPanel', AddMutationsPanel );
3 changes: 2 additions & 1 deletion js/common/view/EnvironmentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export default class EnvironmentPanel extends Panel {
cornerRadius: 0,
fill: null,
stroke: null,
phetioVisiblePropertyInstrumented: false
phetioVisiblePropertyInstrumented: false,
isDisposable: false
}, providedOptions );

// Where the bunnies, food, etc. are displayed
Expand Down
9 changes: 2 additions & 7 deletions js/common/view/EnvironmentRadioButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import EnumerationProperty from '../../../../axon/js/EnumerationProperty.js';
import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import PickRequired from '../../../../phet-core/js/types/PickRequired.js';
Expand Down Expand Up @@ -52,7 +51,8 @@ export default class EnvironmentRadioButtonGroup extends RectangularRadioButtonG
},
enabledPropertyOptions: {
phetioReadOnly: true // see https://github.com/phetsims/natural-selection/issues/296
}
},
isDisposable: false
}, providedOptions );

// icons
Expand Down Expand Up @@ -95,11 +95,6 @@ export default class EnvironmentRadioButtonGroup extends RectangularRadioButtonG

super( environmentProperty, content, options );
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}
}

naturalSelection.register( 'EnvironmentRadioButtonGroup', EnvironmentRadioButtonGroup );
14 changes: 2 additions & 12 deletions js/common/view/EnvironmentalFactorsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @author Chris Malley (PixelZoom, Inc.)
*/

import Disposable from '../../../../axon/js/Disposable.js';
import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Property from '../../../../axon/js/Property.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
Expand Down Expand Up @@ -96,11 +95,6 @@ export default class EnvironmentalFactorsPanel extends NaturalSelectionPanel {

super( content, options );
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}
}

type TitleTextSelfOptions = EmptySelfOptions;
Expand All @@ -121,7 +115,8 @@ class TitleText extends Text {
phetioVisiblePropertyInstrumented: true,
visiblePropertyOptions: {
phetioFeatured: true
}
},
isDisposable: false
}, providedOptions );

const stringProperty = new DerivedStringProperty( [
Expand All @@ -136,11 +131,6 @@ class TitleText extends Text {

super( stringProperty, options );
}

public override dispose(): void {
Disposable.assertNotDisposable();
super.dispose();
}
}

naturalSelection.register( 'EnvironmentalFactorsPanel', EnvironmentalFactorsPanel );
Loading

0 comments on commit 32557dd

Please sign in to comment.