-
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
State management refactor #42
Conversation
850a240
to
4e823e6
Compare
4e823e6
to
af75d30
Compare
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 looks really good to me. I left a couple comments about future improvements.
I think the only thing that would be good to change in this PR is the duplicate code around creating the snapshot to send to applySnapshot
.
const rootCollection = useMemo(() => { | ||
return collections.find((c: ICollection) => !c.parent); | ||
}, [collections]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [collections, collections.length]); |
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.
Probably not now, but this would be better moved into the model. So to support that we'd have to make the model not just be a types.map(...
but instead be a types.model(...
so it could have a view of rootCollection
.
In theory the number of collections might be constant even though the root collection has changed. I don't know collections well enough to know how likely this is.
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [collections, collections.length]); |
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 another example of something that would be better as a view on the model. But again it probably doesn't make sense to change that in this PR unless there are bugs caused by the current approach.
src/hooks/useCodapState.tsx
Outdated
const newCollectionModels = colls.map((coll: ICollection) => { | ||
const { areParentChildLinksConfigured, attrs, caseName, cases: _cases, childAttrName, | ||
collapseChildren, guid, id, name, parent, title, type } = coll; | ||
return { | ||
areParentChildLinksConfigured, attrs, caseName, cases: _cases, childAttrName, | ||
collapseChildren, guid, id, name, parent, title, type | ||
}; | ||
}); | ||
applySnapshot(collections, newCollectionModels); |
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 looks like the same code that is in updateCollections
, can you consolidate it?
@scytacki Thanks. I consolidated the duplicate code. I also had a go at updating the collections model like I think you were suggesting. Do those changes make sense? They appear to work fine, though I find the structure a little awkward. It seems a bit weird to have a |
To be more analogous with CODAP itself, |
@kswenson Thanks. That makes a lot of sense. I spent some time trying to make that work, but it doesn't seem as straightforward as you might expect, and it's still not clear to me how much more time it'd take to work that out. So I'd like to either stick with the current model changes or undo them and save that work for later like Scott originally suggested, if that sounds reasonable to you and @scytacki? |
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 looks good to me. Yes I think it is fine to punt the renaming.
There might be some issues with the useEffect dependencies just including collectionsModel
. However we can probably wait until we find a problem before addressing that.
We've added MobX State Tree to help with state management.