-
Notifications
You must be signed in to change notification settings - Fork 6
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
support ?shuffleListeners #189
Comments
@samreid, while talking with you over in phetsims/axon#215 about tackling this problem, you had mentioned that it wasn't too challenging. I would like to employ your help in problem solving this one. Basically the simplified problem I'm seeing is that there are two listeners on model.soluteProperty. The first is from the derived model Property The first are listeners that change core model DerivedProperties. The second are view listeners that need the entire model to be up to date before making their changes. For this particular error, reproduce with @samreid do you have any thoughts? |
I experimented with UPDATE: Likewise, we could use |
Here's a patch that may be better than nothing: Index: js/molarity/model/Solution.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- js/molarity/model/Solution.js (revision 820954e694f41f7d4f5fbec4391088f9068e882a)
+++ js/molarity/model/Solution.js (date 1575951303816)
@@ -115,7 +115,11 @@
if ( this.concentrationProperty.value > 0 ) {
const solute = this.soluteProperty.get();
const colorScale = Util.linear( 0, solute.saturatedConcentration, 0, 1, this.concentrationProperty.value );
- return Color.interpolateRGBA( solute.minColor, solute.maxColor, colorScale );
+
+ // When listeners are fired in an arbitrary order, sometimes there is a transient, intermediate value that
+ // is out of range. However, once all listeners have fired, this value should already be between 0..1
+ const clampedColorScale = Util.clamp( colorScale, 0, 1 );
+ return Color.interpolateRGBA( solute.minColor, solute.maxColor, clampedColorScale );
}
else {
return this.solvent.color;
This makes the listener order independent, but I wonder if it may inadvertently mask problems even after all values have updated. What do you think? |
I think that we have two bulls butting heads:
The above band-aid would likely work for that particular view listener. |
I'd like to know how to better handle these issues. In my opinion (and I feel like we've discussed this before), it should be allowed to have some set of listeners (even if we don't call if that) which must be done before anything else. In the past this was explicit and obvious because the Question to developer team at large: How much energy do we want to spend fixing these "problems" exposed by |
I don't think this should block publication of Molarity coming up imminently. |
I haven't felt the need personally to ensure things work with all permutations of listeners, but if so I think it would be great to have more support for this. |
After a large discussion with developers in today's dev meeting, here are some notes:
For Molarity specifically, we aren't going to hold up publication. First we will see if the order dependency can be fixed by alerting based on the slider changing instead of based on the model Property. If that doesn't work, then I will document that listener order dependency. Then later on in February there will be a sub-team meeting to investigate adding transaction support to multi-dependency Types. I'll set a calendar reminder for February. |
I think it could help a lot if we flag DerivedProperty listeners for identification, then update all DerivedProperties in a tree before sending any notifications. I don't think that strategy would work for multilink, which is more about side effects. @zepumph would getting all of the DerivedProperty values correct before notifications address the interactive description style problems mentioned in this issue? |
Yes that think that may be helpful, though in one particular case I decided to move the logic from a Property link over to the endDrag of a slider (#206). I'm excited to see how phetsims/axon#276 goes. |
This issue was quite helpful for understanding how PhET uses listener order in its notification code. To me, we fully depend on listener order in many many cases, most often in regards to how you wire up changes to model Properties in the model, and also listen to the Properties in the view, often within the same listener list. While |
From phetsims/axon#215, when running with
?shuffleListeners
we get an error:I'll take a look.
The text was updated successfully, but these errors were encountered: