Skip to content

Commit

Permalink
Improve types, see #94
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Dec 19, 2024
1 parent edca8a0 commit 3b74486
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion js/least-squares-regression/model/DataPoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default class DataPoint {
// Emitter that fires when the data point has returned to its origin.
public readonly returnedToOriginEmitter: Emitter;

// TODO https://github.com/phetsims/least-squares-regression/issues/94 should this be in the subtype?
public positionUpdateListener?: () => void;
public userControlledListener?: ( userControlled: boolean ) => void;
public returnedToOriginListener?: () => void;
Expand Down
2 changes: 1 addition & 1 deletion js/least-squares-regression/model/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export default class Graph {
/**
* Add the dataPoint to the dataPointsOnGraph Array and add 'My Line' and 'Best Fit Line' model Residuals.
*/
public addPointAndResiduals( dataPoint: DataPoint & { positionUpdateListener?: () => void } ): void {
public addPointAndResiduals( dataPoint: DataPoint ): void {
this.dataPointsOnGraph.push( dataPoint );
this.addMyLineResidual( dataPoint );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,18 @@ export default class LeastSquaresRegressionModel {
this.dataPoints.remove( dataPoint );
}

if ( dataPoint.positionProperty && dataPoint.positionUpdateListener &&
if ( dataPoint.positionUpdateListener &&
dataPoint.positionProperty.hasListener( dataPoint.positionUpdateListener ) ) {
dataPoint.positionProperty.unlink( dataPoint.positionUpdateListener );
}

if ( dataPoint.userControlledProperty && dataPoint.userControlledListener &&
if ( dataPoint.userControlledListener &&
dataPoint.userControlledProperty.hasListener( dataPoint.userControlledListener ) ) {
dataPoint.userControlledProperty.unlink( dataPoint.userControlledListener );
}

if ( dataPoint.returnedToOriginEmitter &&
dataPoint.returnedToOriginEmitter.hasListener( dataPoint.returnedToOriginListener! ) ) {
dataPoint.returnedToOriginEmitter.removeListener( dataPoint.returnedToOriginListener! );
if ( dataPoint.returnedToOriginListener && dataPoint.returnedToOriginEmitter.hasListener( dataPoint.returnedToOriginListener ) ) {
dataPoint.returnedToOriginEmitter.removeListener( dataPoint.returnedToOriginListener );
}
};

Expand Down

0 comments on commit 3b74486

Please sign in to comment.