1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/packages/core/src/common/utils/toJS.ts
Sebastian Malton 1dc177f21c
Replace all internal uses of utilities with new packages
Signed-off-by: Sebastian Malton <sebastian@malton.name>
2023-03-10 09:39:22 +02:00

27 lines
832 B
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
/**
* Wrapper for mobx.toJS() to support partially observable objects as data-input (>= mobx6).
* Otherwise, output result won't be recursively converted to corresponding plain JS-structure.
*
* @example
* mobx.toJS({one: 1, two: observable.array([2])}); // "data.two" == ObservableArray<number>
*/
import * as mobx from "mobx";
import { isObservable, observable } from "mobx";
/**
* @deprecated Switch to doing toJS on each field instead
*/
export function toJS<T>(data: T): T {
// make data observable for recursive toJS()-output
if (typeof data === "object" && !isObservable(data)) {
return mobx.toJS(observable.box(data).get());
}
return mobx.toJS(data);
}