Skip to content

Commit

Permalink
chore: add mobx, wrap model changes with runInAction
Browse files Browse the repository at this point in the history
  • Loading branch information
emcelroy committed Sep 20, 2024
1 parent af75d30 commit 31406d7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^13.5.0",
"iframe-phone": "^1.3.1",
"mobx": "^6.13.2",
"mobx-react-lite": "^4.0.7",
"mobx-state-tree": "^6.0.1",
"react": "^18.3.1",
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useCodapState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
updateAttributePosition,
updateCaseById,
} from "@concord-consortium/codap-plugin-api";
import { runInAction } from "mobx";
import { applySnapshot, unprotect } from "mobx-state-tree";
import { getCases, getDataSetCollections, sortAttribute } from "../utils/apiHelpers";
import { ICollection, IDataSet, IProcessedCaseObj } from "../types";
Expand Down Expand Up @@ -166,7 +167,7 @@ export const useCodapState = () => {
if (selectedDataSet) {
updateCollections();
} else {
collections.clear();
runInAction(() => collections.clear());
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedDataSet]);
Expand Down Expand Up @@ -295,7 +296,7 @@ export const useCodapState = () => {
try {
request = await updateCaseById(selectedDataSetName, caseObj.id, {[attrTitle]: newValue});
if (request.success) {
caseObj.values.set(attrTitle, newValue);
runInAction(() => caseObj.values.set(attrTitle, newValue));
}
} catch (e) {
console.error("Case not updated: ", e);
Expand Down

0 comments on commit 31406d7

Please sign in to comment.