-
Notifications
You must be signed in to change notification settings - Fork 3
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
Create reactive datastore for models with Mobx #277
Conversation
Pull Request Test Coverage Report for Build 422168898
💛 - Coveralls |
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.
This is cool. It took me forever to review because I had to go back and re-read the MobX docs, but am understanding things much better now.
I just have a couple of comments about if and how the metric data will eventually be added to the DataStore
. Not suggesting at all that changes need to be made, just curious about design decisions.
if (metricFileData) { | ||
this.allRecords = this.dataTransformer(metricFileData); | ||
} | ||
this.isLoading = false; |
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'm trying to wrap my head around when it would make sense to make a store vs making observable attributes on a model like you've done here.
It makes sense that you would want isLoading
to be observable so that components can change what they render based on this status boolean. Why did you choose to just set this in an action here vs creating a store and setting this in the store like you did for the TenantStore.currentTenant
?
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.
Is your intention to eventually store the metric data as part of the TenantStore
using getMetricsForTenant
?
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 did it this way because the relationship between tenant and metric is strictly hierarchical ... the Mobx docs advise against normalizing those kinds of relationships or making your stores resemble relational database tables or something like that. Instead the metrics are literally nested within TenantStore.currentTenant
.
As to your second question, it's a good question ... I don't really know the answer yet. There are some places where a currentMetric
would make sense (e.g. you have navigated to the page for a single metric), but in other places you will see multiple metrics at once. There is nothing nested below a Metric
so it wouldn't serve the same limiting function to designate one as "current" and thus it might not even be necessary to do it at all? Figuring this out will be a big part of #274.
await dataPromise; | ||
expect(metric.isLoading).toBe(false); | ||
expect(metric.records).toBeDefined(); | ||
expect.assertions(5); |
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.
Great tests. Smart to use when
reaction for these tests!
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.
Very nice. 🐶
Description of the change
This adds reactivity to our data models with MobX and organizes them into a central data store. This was mostly pretty straightforward, since this application doesn't do much yet, but there was some weird stuff that seemed worth highlighting as we figure out how best to use Mobx.
readonly
to the extent possible. The notable exception is in the relationship between Metrics and Collections; because it's cyclic, one side has to get updated after instantiation, so it can't be readonly. It is still not observable, though, and I left a comment to that effect for posterity.(Note that this is stacked on top of #273 so you may want to look at that one first if you haven't yet and it's still open)
Type of change
Related issues
Checklists
Development
These boxes should be checked by the submitter prior to merging:
Code review
These boxes should be checked by reviewers prior to merging: