Skip to content
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

Use JSON.parse(JSON.stringify(propertyData)) instead of toJS(propertyData) #103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"---------- Linting ----------------------------------------------------": "",
"ts": "tsc --noEmit",
"---------- helper commands --------------------------------------------": "",
"prettier": "npx prettier --write \"./**/*.{ts,tsx,js,jsx,json,md}\"",
"prettier": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md}\"",
"up": "yarn upgrade-interactive --latest",
"-----------------------------------------------------------------------": ""
},
Expand All @@ -64,6 +64,7 @@
"jest-mock-console": "^2.0.0",
"milliseconds": "^1.0.3",
"mobx": "^6.3.0",
"prettier": "^2.8.4",
"ts-jest": "^28.0.4",
"typescript": "^4.2.4"
},
Expand Down
13 changes: 3 additions & 10 deletions src/PersistStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,10 @@ export class PersistStore<T, P extends keyof T> {
actionPersistWarningIf(isActionProperty, String(property.key));

if (!isComputedProperty && !isActionProperty) {
let propertyData = property.serialize(target[property.key]);

if (propertyData instanceof ObservableMap) {
const mapArray: any = [];
propertyData.forEach((v, k) => {
mapArray.push([k, toJS(v)]);
});
propertyData = mapArray;
}
const propertyData = property.serialize(target[property.key]);

propertiesToWatch[property.key] = toJS(propertyData);
propertiesToWatch[property.key] =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's about Map/Set. Does it work correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷 I am not sure. I won't be able to test this out for a few weeks. When using Map/Set should you always use serialize and deserialize?

typeof propertyData === 'undefined' ? undefined : JSON.parse(JSON.stringify(propertyData));
}
});

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3261,6 +3261,11 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==

prettier@^2.8.4:
version "2.8.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==

pretty-format@^27.0.0, pretty-format@^27.5.1:
version "27.5.1"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-27.5.1.tgz#2181879fdea51a7a5851fb39d920faa63f01d88e"
Expand Down