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 b7c61ad commit cad1d03
Show file tree
Hide file tree
Showing 24 changed files with 56 additions and 163 deletions.
9 changes: 2 additions & 7 deletions js/common/model/BaseVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import Vector from './Vector.js';
import Graph from './Graph.js';
import VectorSet from './VectorSet.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import Disposable from '../../../../axon/js/Disposable.js';

// constants
const OPTIONS = {
isRemovable: false, // BaseVectors are not removable
isTipDraggable: false, // BaseVectors are not draggable by the tip
isOnGraphInitially: true // BaseVectors are always on the graph
isOnGraphInitially: true, // BaseVectors are always on the graph
isDisposable: false
};

export default abstract class BaseVector extends Vector {
Expand All @@ -37,11 +37,6 @@ export default abstract class BaseVector extends Vector {

super( initialTailPosition, initialComponents, graph, vectorSet, symbol, OPTIONS );
}

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

vectorAddition.register( 'BaseVector', BaseVector );
9 changes: 2 additions & 7 deletions js/common/model/SumVector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import VectorSet from './VectorSet.js';
import Property from '../../../../axon/js/Property.js';
import { ObservableArray } from '../../../../axon/js/createObservableArray.js';
import { LabelDisplayData } from './RootVector.js';
import Disposable from '../../../../axon/js/Disposable.js';

// constants
const SUM_VECTOR_OPTIONS = {
isTipDraggable: false, // Sum vectors are not draggable by the tip.
isRemovable: false, // Sum vectors are not removable which means they are also not disposable
isOnGraphInitially: true // Sum vectors are always on the graph
isOnGraphInitially: true, // Sum vectors are always on the graph
isDisposable: false
};

export default class SumVector extends Vector {
Expand Down Expand Up @@ -78,11 +78,6 @@ export default class SumVector extends Vector {
} );
}

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

/**
* Update the sum vector components. Calculated from all the vectors that are on the graph.
*/
Expand Down
9 changes: 2 additions & 7 deletions js/common/view/ComponentStyleControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import VectorAdditionStrings from '../../VectorAdditionStrings.js';
import ComponentVectorStyles from '../model/ComponentVectorStyles.js';
import VectorAdditionConstants from '../VectorAdditionConstants.js';
import ComponentStyleRadioButtonGroup from './ComponentStyleRadioButtonGroup.js';
import Disposable from '../../../../axon/js/Disposable.js';

const MAX_WIDTH = VectorAdditionConstants.GRAPH_CONTROL_PANEL_CONTENT_WIDTH;

Expand Down Expand Up @@ -44,14 +43,10 @@ export default class ComponentStyleControl extends VBox {
// VBoxOptions
children: children,
align: 'left',
spacing: VectorAdditionConstants.GRAPH_CONTROL_PANEL_Y_SPACING
spacing: VectorAdditionConstants.GRAPH_CONTROL_PANEL_Y_SPACING,
isDisposable: false
} );
}

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

vectorAddition.register( 'ComponentStyleControl', ComponentStyleControl );
9 changes: 2 additions & 7 deletions js/common/view/ComponentStyleRadioButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import ComponentVectorStyles from '../model/ComponentVectorStyles.js';
import VectorAdditionConstants from '../VectorAdditionConstants.js';
import GridBox from './GridBox.js';
import VectorAdditionIconFactory from './VectorAdditionIconFactory.js';
import Disposable from '../../../../axon/js/Disposable.js';

export default class ComponentStyleRadioButtonGroup extends Node {

Expand All @@ -39,14 +38,10 @@ export default class ComponentStyleRadioButtonGroup extends Node {
} );

super( {
children: [ gridBox ]
children: [ gridBox ],
isDisposable: false
} );
}

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

vectorAddition.register( 'ComponentStyleRadioButtonGroup', ComponentStyleRadioButtonGroup );
14 changes: 5 additions & 9 deletions js/common/view/CoordinateSnapRadioButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import CoordinateSnapModes from '../model/CoordinateSnapModes.js';
import VectorColorPalette from '../model/VectorColorPalette.js';
import VectorAdditionConstants from '../VectorAdditionConstants.js';
import VectorAdditionIconFactory from './VectorAdditionIconFactory.js';
import { EmptySelfOptions, optionize3 } from '../../../../phet-core/js/optionize.js';
import { EmptySelfOptions, optionize4 } from '../../../../phet-core/js/optionize.js';
import { NodeTranslationOptions } from '../../../../scenery/js/imports.js';
import Disposable from '../../../../axon/js/Disposable.js';

type SelfOptions = EmptySelfOptions;

Expand All @@ -31,8 +30,10 @@ export default class CoordinateSnapRadioButtonGroup extends RectangularRadioButt
polarVectorColorPalette: VectorColorPalette,
providedOptions?: CoordinateSnapRadioButtonGroupOptions ) {

const options = optionize3<CoordinateSnapRadioButtonGroupOptions, SelfOptions, RectangularRadioButtonGroupOptions>()(
{}, VectorAdditionConstants.RADIO_BUTTON_GROUP_OPTIONS, providedOptions );
const options = optionize4<CoordinateSnapRadioButtonGroupOptions, SelfOptions, RectangularRadioButtonGroupOptions>()(
{}, VectorAdditionConstants.RADIO_BUTTON_GROUP_OPTIONS, {
isDisposable: false
}, providedOptions );

// Create the description of the buttons
const items: RectangularRadioButtonGroupItem<CoordinateSnapModes>[] = [
Expand All @@ -48,11 +49,6 @@ export default class CoordinateSnapRadioButtonGroup extends RectangularRadioButt

super( coordinateSnapModeProperty, items, options );
}

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

vectorAddition.register( 'CoordinateSnapRadioButtonGroup', CoordinateSnapRadioButtonGroup );
14 changes: 5 additions & 9 deletions js/common/view/GraphControlPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import { Node, NodeTranslationOptions, VBox } from '../../../../scenery/js/impor
import Panel, { PanelOptions } from '../../../../sun/js/Panel.js';
import vectorAddition from '../../vectorAddition.js';
import VectorAdditionConstants from '../VectorAdditionConstants.js';
import { EmptySelfOptions, optionize3 } from '../../../../phet-core/js/optionize.js';
import Disposable from '../../../../axon/js/Disposable.js';
import { EmptySelfOptions, optionize4 } from '../../../../phet-core/js/optionize.js';

type SelfOptions = EmptySelfOptions;

Expand All @@ -22,8 +21,10 @@ export default class GraphControlPanel extends Panel {

protected constructor( children: Node[], providedOptions?: GraphControlPanelOptions ) {

const options = optionize3<GraphControlPanelOptions, SelfOptions, PanelOptions>()(
{}, VectorAdditionConstants.PANEL_OPTIONS, providedOptions );
const options = optionize4<GraphControlPanelOptions, SelfOptions, PanelOptions>()(
{}, VectorAdditionConstants.PANEL_OPTIONS, {
isDisposable: false
}, providedOptions );

const content = new VBox( {
children: children,
Expand All @@ -38,11 +39,6 @@ export default class GraphControlPanel extends Panel {

super( content, options );
}

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

vectorAddition.register( 'GraphControlPanel', GraphControlPanel );
9 changes: 2 additions & 7 deletions js/common/view/GraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Property from '../../../../axon/js/Property.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import PickOptional from '../../../../phet-core/js/types/PickOptional.js';
import optionize from '../../../../phet-core/js/optionize.js';
import Disposable from '../../../../axon/js/Disposable.js';

//----------------------------------------------------------------------------------------
// constants
Expand Down Expand Up @@ -84,7 +83,8 @@ export default class GraphNode extends Node {
children.push( new OriginManipulator( graph ) );

super( {
children: children
children: children,
isDisposable: false
} );

// Clicking in the graph clears the active (selected) vector.
Expand All @@ -95,11 +95,6 @@ export default class GraphNode extends Node {
down: () => { graph.activeVectorProperty.value = null; }
} );
}

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

/**
Expand Down
9 changes: 2 additions & 7 deletions js/common/view/OriginManipulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { Color, DragListener } from '../../../../scenery/js/imports.js';
import vectorAddition from '../../vectorAddition.js';
import Graph from '../model/Graph.js';
import VectorAdditionColors from '../VectorAdditionColors.js';
import Disposable from '../../../../axon/js/Disposable.js';

// constants

Expand All @@ -33,7 +32,8 @@ const ORIGIN_OPTIONS = {
highlightColor: Color.WHITE,
shadowColor: ORIGIN_COLOR.darkerColor(),
lineWidth: 1,
stroke: ORIGIN_COLOR.darkerColor()
stroke: ORIGIN_COLOR.darkerColor(),
isDisposable: false
};

export default class OriginManipulator extends ShadedSphereNode {
Expand Down Expand Up @@ -82,11 +82,6 @@ export default class OriginManipulator extends ShadedSphereNode {
this.center = modelViewTransform.modelToViewPosition( Vector2.ZERO );
} );
}

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

vectorAddition.register( 'OriginManipulator', OriginManipulator );
11 changes: 5 additions & 6 deletions js/common/view/RootVectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ export default class RootVectorNode extends Node {
arrowType: 'solid',
arrowOptions: {
cursor: 'move'
}
},

// NodeOptions
isDisposable: false

}, providedOptions );

//----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,11 +117,6 @@ export default class RootVectorNode extends Node {
};
}

public override dispose(): void {
this.disposeRootVectorNode();
super.dispose();
}

/**
* Updates the tail and tip position of the view. Called when the model changes tail/tip.
*/
Expand Down
11 changes: 4 additions & 7 deletions js/common/view/SceneNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import ComponentVectorStyles from '../model/ComponentVectorStyles.js';
import optionize from '../../../../phet-core/js/optionize.js';
import Property from '../../../../axon/js/Property.js';
import BaseVector from '../model/BaseVector.js';
import Disposable from '../../../../axon/js/Disposable.js';

type SelfOptions = {
includeEraser?: boolean; // Indicates if an EraserButton should be included
Expand Down Expand Up @@ -70,7 +69,10 @@ export default class SceneNode extends Node {
const options = optionize<SceneNodeOptions, SelfOptions, NodeOptions>()( {

// SelfOptions
includeEraser: true
includeEraser: true,

// NodeOptions
isDisposable: false
}, providedOptions );

super();
Expand Down Expand Up @@ -140,11 +142,6 @@ export default class SceneNode extends Node {
this.vectorSets = graph.vectorSets;
}

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

/**
* Gets the VectorSetNode associated with a VectorSet.
*/
Expand Down
6 changes: 0 additions & 6 deletions js/common/view/SumComponentVectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import optionize, { EmptySelfOptions } from '../../../../phet-core/js/optionize.
import ComponentVector from '../model/ComponentVector.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import SumVector from '../model/SumVector.js';
import Disposable from '../../../../axon/js/Disposable.js';

type SelfOptions = EmptySelfOptions;
type SumComponentVectorNodeOptions = SelfOptions & ComponentVectorNodeOptions;
Expand Down Expand Up @@ -66,11 +65,6 @@ export default class SumComponentVectorNode extends ComponentVectorNode {
);
}

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

/**
* Handles visibility of sum component vectors.
*/
Expand Down
6 changes: 0 additions & 6 deletions js/common/view/SumVectorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import VectorNode, { VectorNodeOptions } from './VectorNode.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import optionize, { combineOptions, EmptySelfOptions } from '../../../../phet-core/js/optionize.js';
import { RootVectorArrowNodeOptions } from './RootVectorNode.js';
import Disposable from '../../../../axon/js/Disposable.js';

type SelfOptions = EmptySelfOptions;
type SumVectorNodeOptions = SelfOptions & VectorNodeOptions;
Expand Down Expand Up @@ -75,11 +74,6 @@ export default class SumVectorNode extends VectorNode {
}
} );
}

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

vectorAddition.register( 'SumVectorNode', SumVectorNode );
2 changes: 1 addition & 1 deletion js/common/view/ToggleBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type SelfOptions = {
};

export type ToggleBoxOptions = SelfOptions & NodeTranslationOptions &
PickOptional<AccordionBoxOptions, 'expandedProperty' | 'contentXSpacing'>;
PickOptional<AccordionBoxOptions, 'expandedProperty' | 'contentXSpacing' | 'isDisposable'>;

export default class ToggleBox extends AccordionBox {

Expand Down
7 changes: 1 addition & 6 deletions js/common/view/VectorAdditionScreenView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Tandem from '../../../../tandem/js/Tandem.js';
import vectorAddition from '../../vectorAddition.js';
import VectorAdditionModel from '../model/VectorAdditionModel.js';
import VectorAdditionConstants from '../VectorAdditionConstants.js';
import Disposable from '../../../../axon/js/Disposable.js';

export default class VectorAdditionScreenView extends ScreenView {

Expand All @@ -24,6 +23,7 @@ export default class VectorAdditionScreenView extends ScreenView {

super( {
layoutBounds: VectorAdditionConstants.SCREEN_VIEW_BOUNDS,
isDisposable: false,
tandem: tandem
} );

Expand All @@ -39,11 +39,6 @@ export default class VectorAdditionScreenView extends ScreenView {
this.addChild( this.resetAllButton );
}

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

public reset(): void {

// cancel any interactions that are in progress
Expand Down
Loading

0 comments on commit cad1d03

Please sign in to comment.