Skip to content

Commit

Permalink
Ignore an empty data points array, see: #241
Browse files Browse the repository at this point in the history
  • Loading branch information
marlitas committed Jun 7, 2024
1 parent e28abbe commit 2e8165e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion js/common/model/SharingModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ export default class SharingModel<T extends Snack> extends PhetioObject implemen
implementation: function( this: SharingModel<Snack>, dataPoints: number[] ) {

// Validate data points
if ( dataPoints.length > this.maxPlatesProperty.value ) {
// If a client passes through an empty array of data points, ignore and return early.
if ( dataPoints.length === 0 ) {
return;
}
else if ( dataPoints.length > this.maxPlatesProperty.value ) {
dataPoints = dataPoints.slice( 0, this.maxPlatesProperty.value );
}
dataPoints.forEach( ( dataPoint, i ) => {
Expand Down
6 changes: 5 additions & 1 deletion js/level-out/model/LevelOutModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,11 @@ export default class LevelOutModel extends PhetioObject implements TModel {
implementation: function( this: LevelOutModel, dataPoints: number[] ) {

// Validate data points
if ( dataPoints.length > this.maxCupsProperty.value ) {
// If a client passes through an empty array of data points, ignore and return early.
if ( dataPoints.length === 0 ) {
return;
}
else if ( dataPoints.length > this.maxCupsProperty.value ) {
dataPoints = dataPoints.slice( 0, this.maxCupsProperty.value );
}
dataPoints.forEach( ( dataPoint, i ) => {
Expand Down

0 comments on commit 2e8165e

Please sign in to comment.