Serialize and Deserialize helper function

Summary: This diff adds a helper function to serialize and deserialize javascript Objects

Reviewed By: danielbuechele

Differential Revision: D14101483

fbshipit-source-id: 3e1f37076ccc04b83cf7de5f10900e21e6474c1d
This commit is contained in:
Pritesh Nandgaonkar
2019-02-18 14:41:44 -08:00
committed by Facebook Github Bot
parent 8d134ba89e
commit cab61b0c15
3 changed files with 353 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ import {getInstance} from '../fb-stubs/Logger.js';
import fs from 'fs';
import uuid from 'uuid';
import {remote} from 'electron';
import {serialize, deserialize} from './serialization';
export type ExportType = {|
fileVersion: string,
@@ -197,7 +198,7 @@ export const exportStoreToFile = (
const json = serializeStore(data.getState());
if (json) {
return new Promise((resolve, reject) => {
fs.writeFile(exportFilePath, JSON.stringify(json), err => {
fs.writeFile(exportFilePath, serialize(json), err => {
if (err) {
reject(err);
}
@@ -215,21 +216,15 @@ export const importFileToStore = (file: string, store: Store) => {
console.error(err);
return;
}
const json = JSON.parse(data);
const json = deserialize(data);
const {device, clients} = json;
const {serial, deviceType, title, os, logs} = device;
const updatedLogs = logs
? logs.map(log => {
// During the export, Date is exported as string
return {...log, date: new Date(log.date)};
})
: [];
const archivedDevice = new ArchivedDevice(
serial,
deviceType,
title,
os,
updatedLogs,
logs,
);
const devices = store.getState().connections.devices;
const matchedDevices = devices.filter(