phetsims / natural-selection

"Natural Selection" is an educational simulation in HTML5, by PhET Interactive Simulations
GNU General Public License v3.0
3 stars 7 forks source link

Use STATE_SCHEMA to limit IOType boilerplate #305

Closed zepumph closed 3 years ago

zepumph commented 3 years ago

Over in https://github.com/phetsims/phet-io/issues/1782, I finally got to cleaning up how stateSchema duplicates much of how applyState and toStateObject are most likely implemented.

In this sim specifically, I found 2 potential problems with just blowing away the toStateObject and the applyState methods on Bunny.js

Note that the required calls are redundant because there is a lot of type validation that is done for anything in the state schema, both for applyState and toStateObject.

zepumph commented 3 years ago

@pixelzoom, would you please review the above commit. If you feel like the validateInstance isn't actually needed, then you can delete the entire applyState function and the IOType will automatically grab it from StateSchema.defaultApplyState.

pixelzoom commented 3 years ago

I'm going to leave the call to validateInstance in Bunny applyState. It's a useful additional layer of protection again PhET-iO regressions, and it's a pattern that I've used throughout Natural Selection. But thanks for bringing this to my attention. Closing.