-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to handle gotchas related to Property setDeferred #281
Comments
Looking through Property functions, perhaps This is a pretty serious bug; one that I am unsure how to solve easily but which is easy to demonstrate.
In the general case, calling |
I understand the motivation for this "deferred" feature. But it seems like something that should be avoided. And it's not robustly instrumented or adequately tested - only 1 unit test! |
I don't think so--that would break its interface. You should be able to get a Property value at any time. When a property is deferred, you should still be able to read the old value. This behavior is also tested in the unit test: const property = new Property( 0 );
//...
property.setDeferred( true );
property.value = 1;
property.value = 2;
assert.equal( property.value, 0, 'should have original value' ); Reset also makes sense to me. Resetting is equivalent to setting the original value. So it should behave the same as any defer.
Agreed, we have been using it sparingly. Particularly because it is not re-entrant.
Yes, there is only 1 test, but 7 assertions are tested in it. What else do you recommend to test? |
I disagree. What is the use case for reading a Property's value while it's in a deferred state? Imo this encourages a certain type of code that should be avoided.
Again, I disagree. What is the use case? And there are other things that don't seem to have been considered (or maybe just not documented?):
If we're going to use it sparingly, what is the purpose of allowing anything other than
Recommended tests:
Robustness:
|
I commented out that occurrence of Property.get() and ran the test again. It failed again with a similar issue on a different Property. |
Could we prevent reads from deferred properties if we change the PhetioStateEngine sequence to hold off of creating new elements until the Properties have all taken their new values? I'm not sure whether that is technically feasible. |
What about children Properties of dynamic elements, is that ok? How does the PhET-iO state engine know when it has done all it can without dynamic elements? |
I don't have anything else to add here, so unassigning. |
Perhaps we need to tweak our state setting algorithm:
This way the order of "undeferring" (firing Property listeners) at the end of state set would first do static items, then it would do dynamic elements that may be more likely to try to access undeferred items. Am I understanding the problem that we are trying to solve correctly? |
This does not feel like an imminent problem. Maybe it would be appropriate to work on in the context of a practical problem when one arises. Re-labeling until then. |
Over in #277, I encountered Property
setDeferred
for the first time. This feature seems to have gotchas that are not at all guarded.For example, after a
set
, you may stillget
the old value:Should
get()
fail an assertion if it's called whilethis.isDeferred === true
?Are there other gotchas?
The text was updated successfully, but these errors were encountered: