@koordinates/xstate-tree 5.2.2 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/utils.js +8 -1
  2. package/package.json +1 -1
package/lib/utils.js CHANGED
@@ -161,9 +161,16 @@ function getCircularReplacer(stripKeys) {
161
161
  return value;
162
162
  };
163
163
  }
164
+ function hasToJSON(value) {
165
+ return (typeof value === "object" &&
166
+ value !== null &&
167
+ typeof value.toJSON === "function");
168
+ }
164
169
  function toJSON(value, stripKeys = []) {
165
170
  const start = performance.now();
166
- const result = JSON.parse(JSON.stringify(value, getCircularReplacer(stripKeys)));
171
+ const result = hasToJSON(value)
172
+ ? value.toJSON()
173
+ : JSON.parse(JSON.stringify(value, getCircularReplacer(stripKeys)));
167
174
  const elapsed = performance.now() - start;
168
175
  if (typeof result === "object" && result !== null) {
169
176
  result.__toJSON_ms = Math.round(elapsed * 100) / 100;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@koordinates/xstate-tree",
3
3
  "main": "lib/index.js",
4
4
  "types": "lib/xstate-tree.d.ts",
5
- "version": "5.2.2",
5
+ "version": "5.2.3",
6
6
  "license": "MIT",
7
7
  "description": "Build UIs with Actors using xstate and React",
8
8
  "keywords": [