Convert serialization.js to TS
Summary: Convert serialization to typescript. I tried to type the deserialize function but don't know enough about the expected format to be able to tell what the types should be. Reviewed By: passy Differential Revision: D16785945 fbshipit-source-id: 45de7ee1c8972314a52abcf20d428ba44f031a00
This commit is contained in:
committed by
Facebook Github Bot
parent
d0da0d66a5
commit
ce3f69c249
@@ -22,7 +22,7 @@ import {listDevices} from '../src/utils/listDevices.tsx';
|
||||
import setup from '../static/setup.js';
|
||||
import type {Store} from '../src/reducers/index.tsx';
|
||||
import {getPersistentPlugins} from '../src/utils/pluginUtils.tsx';
|
||||
import {serialize} from '../src/utils/serialization';
|
||||
import {serialize} from '../src/utils/serialization.tsx';
|
||||
import type BaseDevice from '../src/devices/BaseDevice.tsx';
|
||||
|
||||
import {getStringFromErrorLike} from '../src/utils/index.tsx';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {makeObjectSerializable, deserializeObject} from '../serialization';
|
||||
import {makeObjectSerializable, deserializeObject} from '../serialization.tsx';
|
||||
|
||||
class TestObject extends Object {
|
||||
constructor(title: Object, map: ?Map<any, any>, set: ?Set<any>) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {Idler} from './Idler.tsx';
|
||||
import {Idler} from './Idler';
|
||||
export async function serialize(
|
||||
obj: Object,
|
||||
idler?: Idler,
|
||||
@@ -16,16 +16,16 @@ export async function serialize(
|
||||
);
|
||||
}
|
||||
|
||||
export function deserialize(str: string): Object {
|
||||
export function deserialize(str: string): any {
|
||||
return deserializeObject(JSON.parse(str));
|
||||
}
|
||||
|
||||
function processArray(
|
||||
element: any,
|
||||
array: [any],
|
||||
array: Array<any>,
|
||||
stack: Array<any>,
|
||||
dict: Map<any, any>,
|
||||
): {childNeedsIteration: boolean, outputArr: Array<any>} {
|
||||
): {childNeedsIteration: boolean; outputArr: Array<any>} {
|
||||
// Adds the array item to the stack if it needs to undergo iteration to serialise it. Otherwise it adds the serialized version of the item to the memoization dict
|
||||
const outputArr = [];
|
||||
let childNeedsIteration = false;
|
||||
@@ -74,7 +74,7 @@ export function processMapElement(
|
||||
obj: Map<any, any>,
|
||||
dict: Map<any, any>,
|
||||
stack: Array<any>,
|
||||
): {childNeedsIteration: boolean, outputArray: Array<any>} {
|
||||
): {childNeedsIteration: boolean; outputArray: Array<any>} {
|
||||
const arr = [];
|
||||
let childNeedsIteration = false;
|
||||
for (const item of [...obj]) {
|
||||
@@ -95,7 +95,7 @@ export function processObjectToBeSerialized(
|
||||
element: Object,
|
||||
dict: Map<any, any>,
|
||||
stack: Array<any>,
|
||||
): {childNeedsIteration: boolean, outputObject: Object} {
|
||||
): {childNeedsIteration: boolean; outputObject: Object} {
|
||||
const array = Object.entries(element);
|
||||
let obj = {};
|
||||
let childNeedsIteration = false;
|
||||
@@ -122,7 +122,7 @@ export async function makeObjectSerializable(
|
||||
obj: any,
|
||||
idler?: Idler,
|
||||
statusUpdate?: (msg: string) => void,
|
||||
): any {
|
||||
): Promise<any> {
|
||||
if (!(obj instanceof Object)) {
|
||||
return obj;
|
||||
}
|
||||
@@ -213,6 +213,7 @@ export function deserializeObject(obj: any): any {
|
||||
switch (type) {
|
||||
case 'Map': {
|
||||
return new Map(
|
||||
// @ts-ignore
|
||||
[...obj.data].map(item => [...item].map(deserializeObject)),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user