also store app version in data object

This commit is contained in:
casperlamboo 2018-02-15 12:24:27 +01:00
parent 02a7f64d5f
commit 9996728f9c
6 changed files with 10 additions and 11 deletions

View File

@ -56,8 +56,7 @@ window.addEventListener('keydown', (event) => {
// add model to store
import modelData from './models/circle_error.d3sketch';
import JSONToSketchData from './src/shape/JSONToSketchData.js';
const { data, appVersion } = JSON.parse(modelData);
JSONToSketchData({ data }, appVersion).then(sketch => {
JSONToSketchData(JSON.parse(modelData)).then(sketch => {
store.dispatch(actions.openSketch(sketch));
});

View File

@ -99,8 +99,8 @@ class App extends React.Component {
case 'D3SKETCH':
case 'JSON':
const url = URL.createObjectURL(file);
const { data, appVersion } = await fetch(url).then(result => result.json());
const sketchData = await JSONToSketchData(data, appVersion);
const data = await fetch(url).then(result => result.json());
const sketchData = await JSONToSketchData(data);
openSketch(sketchData);
break;
case 'JPG':

View File

@ -48,7 +48,7 @@ class DoodlePreview extends React.Component {
async componentDidMount() {
let { docData, sketchData } = this.props;
if (docData) sketchData = await JSONToSketchData(docData.data, docData.appVersion);
if (docData) sketchData = await JSONToSketchData(docData);
const { canvas } = this.refs;

View File

@ -68,12 +68,12 @@ function revive(appVersion, key, value) {
return value;
}
export default async function JSONToSketchData(data, appVersion) {
export default async function JSONToSketchData({ data, appVersion }) {
let sketchData;
if (semver.gt(appVersion, '0.17.4')) {
sketchData = reviveObject(data, (key, value) => revive(appVersion, key, value));
} else {
sketchData = JSON.parse(data.data, (key, value) => revive(appVersion, key, value));
sketchData = JSON.parse(data, (key, value) => revive(appVersion, key, value));
}
sketchData = await recursivePromiseApply(sketchData);

View File

@ -9,8 +9,7 @@ export default async function docToFile(db, doc, { image = false, sketch = false
author: doc.author,
id: doc._id,
createdOn: doc.createdOn,
updatedOn: doc.updatedOn,
appVersion: doc.appVersion
updatedOn: doc.updatedOn
};
if (doc.class) response.class = doc.class;
@ -28,7 +27,7 @@ export default async function docToFile(db, doc, { image = false, sketch = false
}
const data = await blobToJSON(doc._attachments.sketch.data);
response.data = await JSONToSketchData(data, appVersion);
response.data = await JSONToSketchData(data);
} else {
const data = { data: doc.data, appVersion };
response.data = await JSONToSketchData(data);

View File

@ -1,4 +1,5 @@
import { vectorArrayToBase64, imageToBase64 } from '../utils/binaryUtils.js';
import { VERSION } from '../constants/general.js';
function createShapeData(shape) {
shape = { ...shape };
@ -59,5 +60,5 @@ export default function sketchDataToJSON({ objectsById, spaces }) {
}
}
return data;
return { data, appVersion: VERSION };
}