Skip to content

Commit

Permalink
Warn in toJS docs about deep cloning partial observables (#3239)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobelchior committed Jan 4, 2022
1 parent f43ae70 commit bf5da6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thin-adults-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx": patch
---

Improved `toJS` jsdoc
5 changes: 4 additions & 1 deletion packages/mobx/src/api/tojs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ function toJSHelper(source, __alreadySeen: Map<any, any>) {
}

/**
* Basically, a deep clone, so that no reactive property will exist anymore.
* Recursively converts an observable to it's non-observable native counterpart.
* It does NOT recurse into non-observables, these are left as they are, even if they contain observables.
* Computed and other non-enumerable properties are completely ignored.
* Complex scenarios require custom solution, eg implementing `toJSON` or using `serializr` lib.
*/
export function toJS<T>(source: T, options?: any): T {
if (__DEV__ && options) die("toJS no longer supports options")
Expand Down

0 comments on commit bf5da6b

Please sign in to comment.