Closed zepumph closed 3 years ago
@samreid what do you think about the above? I added a test to demonstrate the bugginess. My understanding is that no common code that is adding linked elements in master right now would do so out of order, but please check in on CT when you review to double check.
The test and implementation look good. My only recommendation is to eliminate:
// This is to help guard against setting addLinkedElement before initializingPhetioObject.
const LINKED_ELEMENT_PLACEHOLDER = null;
and just use null
directly, like so:
If you do decide to keep a named constant for this, a better name would be nice. Perhaps LINKED_ELEMENTS_DISABLED
or something?
but please check in on CT when you review to double check.
I didn't see any CT errors that I could attribute to this change.
Sounds good to me. Thanks!
@samreid were over in https://github.com/phetsims/scenery/issues/1046 and thought it was pretty buggy to have the opportunity to add a linked element before instrumenting for PhET-iO, given what addLinkedElement() currently does (null out this.linkedElements).
There is an assertion to make sure that this doesn't happen:
myObject.addLinkedElement();
myObject.initializePhetioObject();
myObject.addLinkedElement(); // error
But not when you just do 1 and 2. I think we can add an assertion to guard this earlier.