Closed zepumph closed 1 year ago
I don't think we should be recomputing/updating disposed Properties, including DerivedProperties. Patched above, and it resolves this issue. @zepumph thoughts/review?
Oh my goodness wow. Thanks for the commit and I love it. It means I can remove my workaround (committed above).
The last piece for me is that on Friday @samreid and I spoke, and it felt like he was less convinced that this was the best solution. Sorry if I have misspoken, but @samreid would comment and feel free to close now that @jonathanolson has added his thoughts.
@samreid and I looked at this, and determined that @jonathanolson's fix is sufficient and that no more work needs to be done here. Closing.
Discovered in https://github.com/phetsims/axon/issues/215 and more specifically https://github.com/phetsims/expression-exchange/issues/161, the issue is when a Property is a dependency on a DerivedProperty AND also has a listener that disposes that DerivedProperty. Here is a simple case that causes the assertion:
Triggering: https://github.com/phetsims/axon/blob/eb190c8159265f88f52cfc4a8c8a1d51509970fa/js/DerivedProperty.ts#L140
Solutions:
hasListenerOrderDependencies: true
to each case, like was done in https://github.com/phetsims/scenery/commit/5f13ff0a0c31c51696282efea377952455b3c0bf over in https://github.com/phetsims/expression-exchange/issues/161// Just mark that there is a deferred value, then calculate the derivation below when setDeferred() is called. // This is in part supported by the PhET-iO state engine because it can account for intermediate states, such // that this Property won't notify until after it is undeferred and has taken its final value.
I would like to proceed with (3) (or something like it),
@jonathanolson, could you please comment on if that feels acceptable to you (no-op recomputation if the derivedProperty is disposed)? It makes sense to me and solves the order dependency.
Noting this came from good conversation with @samreid. Thanks!
hasListenerOrderDependencies
in PressListener, please remove it if we go with a different strategy.