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

Improve toJSON functionality and remove JSONSerializerReplacer #4997

Merged
merged 9 commits into from
Oct 12, 2022
Merged
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,11 @@ Based on Realm JS v10.21.1: See changelog below for details on enhancements and
```
* A typo was fixed in the `SubscriptionsState` enum, in which `SubscriptionsState.Superseded` now returns `superseded` in place of `Superseded`
* `"discardLocal"` is now the default client reset mode. ([#4382](https://github.com/realm/realm-js/issues/4382))
* Removed `Realm.JsonSerializationReplacer`. Use circular JSON serialization libraries such as [@ungap/structured-clone](https://www.npmjs.com/package/@ungap/structured-clone) and [flatted](https://www.npmjs.com/package/flatted) for stringifying Realm entities that have circular structures. The Realm entities' `toJSON` method returns plain objects and arrays (with circular references if applicable) which makes them compatible with any serialization library that supports stringifying plain JavaScript types. ([#4997](https://github.com/realm/realm-js/pull/4997))
gagik marked this conversation as resolved.
Show resolved Hide resolved

### Enhancements
* Small improvement to performance by caching JSI property String object [#4863](https://github.com/realm/realm-js/pull/4863)
* Small improvement to performance for `toJSON` which should make it useful for cases where a plain representations of Realm entities are needed, e.g. when inspecting them for debugging purposes through `console.log(realmObj.toJSON())`. ([#4997](https://github.com/realm/realm-js/pull/4997))

### Fixed
* None
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/tests/src/tests/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ describe("Dictionary", () => {
"addListener",
"removeListener",
"removeAllListeners",
"toJSON",
];
for (const name of methodNames) {
it(`exposes a method named '${name}'`, function (this: RealmContext) {
Expand Down Expand Up @@ -225,6 +226,7 @@ describe("Dictionary", () => {
// Previously this would throw on JSC, because the Dictionary was still a Proxy,
// so modifying it tried to write to the Realm outside of a write transaction
expect(() => {
// @ts-expect-error We know the field is a dict.
jsonObject.dict.something = "test2";
}).to.not.throw();
});
Expand Down
Loading