Closed samreid closed 3 years ago
restTime
is the first field that is read from Bunny's privateState
. In Bunny.js line 431:
// private fields
this.restTime = required( NumberIO.fromStateObject( stateObject.private.restTime ) );
this.hopTime = required( NumberIO.fromStateObject( stateObject.private.hopTime ) );
this.cumulativeRestTime = required( NumberIO.fromStateObject( stateObject.private.cumulativeRestTime ) );
this.cumulativeHopTime = required( NumberIO.fromStateObject( stateObject.private.cumulativeHopTime ) );
this.hopDelta = required( Vector3.Vector3IO.fromStateObject( stateObject.private.hopDelta ) );
this.hopStartPosition = required( Vector3.Vector3IO.fromStateObject( stateObject.private.hopStartPosition ) );
In Slack dev-public this morning, @samreid said:
After https://github.com/phetsims/phet-io/issues/1785 private state data and schema is now nested under “_private” instead of “private”.
Related?
Yes, I have a proposed fix and am testing currently.
Fixed and tested in Natural Selection, closing.
Reopening.
First, I'm also not convinced that this is a good change. Typically, fields with underscores are private, and should be used ONLY inside the implementation of an object. That's not what's going on here. This field is the collection of private data that must be packed/unpacked by the IO Type implementation, so its use is not limited to the internal implementation. Therefore I think this is an improper use of the underscore prefix.
Second, if you do keep this change, https://github.com/phetsims/phet-io/blob/master/doc/phet-io-instrumentation-technical-guide.md needs to be updated:
by convention, they should be nested under the
private
key in the state object.
Inspecting the sites where _.private
is now used (exposed) in the commits above, I like this rename even less. If we don't like private
, how about privateState
?
@pixelzoom and I reviewed some cases, and determined that:
stateObject._private
in code, since it looks like a private access.private
may be a keyword in some languages, _private
is probably safer._privateState
if we wish.
From https://github.com/phetsims/energy-forms-and-changes/issues/410#issuecomment-852406524, I noticed that Studio "Preview Sim" is failing for Natural Selection.