-
Notifications
You must be signed in to change notification settings - Fork 0
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
Isolate units between diagrams #92
Conversation
…ath instances, and the actions that work with the units array. - variable model looks for a unitsManager on its parent container. - add unitsManager to the AppStore so the variables can find it. This will also have to be added to the variables shared model. - extract initializeMath from createMath since it is all about setting up the units of the math instance - export UnitsManager because shared variables model will need access it. - move IMathLib to eliminate circular dependency
- add a cypress test for the case that exposes the problem with it being an action - add comments explaining the complexity of getMathUnit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The restructuring looks good. I didn't test it though. Added some comments re. documentation.
src/diagram/units-manager.ts
Outdated
// - this adds the units of the input variable to the unitsManager.units array. | ||
// - a temporary `mathValue` is returned for the input variable | ||
// - `computedValueIncludingMessageAndError` returns a value for the equation variable. | ||
// - because the units array was updated, and `self.math` is used by `mathValue`, both this triggers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// - because the units array was updated, and `self.math` is used by `mathValue`, both this triggers | |
// - because the units array was updated, and `self.math` is used by `mathValue`, this triggers |
src/diagram/units-manager.ts
Outdated
return mathUnit; | ||
} | ||
|
||
// NOTE: this is both an action and a view. It is called by MST views to get the math.Unit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that it is an action, but it is not clear to me why you say it is also a view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to update the comment to clarify this. Technically it is not a view, but it is used by real views, so that indirectly makes it function as a view.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
==========================================
+ Coverage 71.31% 71.71% +0.39%
==========================================
Files 46 46
Lines 1248 1269 +21
Branches 290 291 +1
==========================================
+ Hits 890 910 +20
- Misses 343 344 +1
Partials 15 15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Here is a PR in CLUE that is using this PR and the next one:
concord-consortium/collaborative-learning#2424
Note: there is a console warning when used in CLUE:
I haven't tracked down the warning precisely. This warning was also there before this PR. It makes sense given the double nature of
getMathUnit
. It will be called when rendering QuantityNode, which will then update the observable units. This update of the observable units will trigger any components that use the units to render their values, units, or error messages to be re-rendered.So this illustrates the 2 issues with mixing views and actions are:
Because this problem existed before this PR I don't think it is worth fixing in this PR. I think the right fix is a refactoring which keeps the units updated based on the current list of variables. So basically a reaction that is watching all of the variables and reconstructing the units array whenever a variable's unit is changed. The tricky part is figuring out where to put this reaction so it will work both in the stand-alone quantity-playground and when it is used inside of CLUE.