Skip to content

Commit

Permalink
Add FieldStateObject type, see #325
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed May 7, 2024
1 parent 8162442 commit 70673ab
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/common/model/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export default abstract class Field extends PhetioObject {
}
}

private toStateObject(): object {
private toStateObject(): FieldStateObject {
return {
airborneProjectiles: this.airborneProjectiles.map( projectile => Projectile.ProjectileIO.toStateObject( projectile ) ),
landedProjectiles: this.landedProjectiles.map( projectile => Projectile.ProjectileIO.toStateObject( projectile ) )
Expand All @@ -380,7 +380,7 @@ export default abstract class Field extends PhetioObject {
landedProjectiles: ArrayIO( Projectile.ProjectileIO )
},
toStateObject: field => field.toStateObject(),
applyState: ( field: Field, stateObject ) => {
applyState: ( field: Field, stateObject: FieldStateObject ) => {

field.airborneProjectiles.length = 0;
field.landedProjectiles.length = 0;
Expand All @@ -396,4 +396,9 @@ export default abstract class Field extends PhetioObject {
} );
}

type FieldStateObject = {
airborneProjectiles: ProjectileStateObject[];
landedProjectiles: ProjectileStateObject[];
};

projectileDataLab.register( 'Field', Field );

0 comments on commit 70673ab

Please sign in to comment.