Skip to content

Commit

Permalink
Improve toJSON functionality and remove JSONSerializerReplacer (#4997)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik authored and kraenhansen committed Oct 18, 2022
1 parent 31101c6 commit 0a35045
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 589 deletions.
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))

### 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

0 comments on commit 0a35045

Please sign in to comment.