From 2b6caba3dfe244670e9466141b8c1e6e60d7b67b Mon Sep 17 00:00:00 2001 From: jos Date: Wed, 24 Jul 2019 15:19:45 +0200 Subject: [PATCH] Parse directly after setText --- HISTORY.md | 4 ++-- src/js/previewmode.js | 21 ++++++++++++--------- src/js/showTransformModal.js | 4 ---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 7834cec..a045243 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,16 +2,16 @@ https://github.com/josdejong/jsoneditor - ## not yet published, version 6.2.0 -- Implemented new mode `preview`, capable of working with JSON documents +- Implemented new mode `preview`, capable of working with large JSON documents up to 500 MiB. - Fixed #730: in `code` mode, there was an initial undo action which clears the content. - Upgraded dependencies `vanilla-picker@2.9.1`, `mobius1-selectr@2.4.13`, `ajv@6.10.2`. + ## 2019-06-22, version 6.1.0 - Implemented menu options `sort` and `transform` for modes `code` and `text`. diff --git a/src/js/previewmode.js b/src/js/previewmode.js index 5c277f8..1d6116d 100644 --- a/src/js/previewmode.js +++ b/src/js/previewmode.js @@ -525,9 +525,7 @@ previewmode.get = function() { var text = this.getText(); try { - console.time('parse') // TODO: cleanup this.json = util.parse(text); // this can throw an error - console.timeEnd('parse') // TODO: cleanup } catch (err) { // try to sanitize json, replace JavaScript notation with JSON notation @@ -547,14 +545,10 @@ previewmode.get = function() { */ previewmode.getText = function() { if (this.text === undefined) { - console.time('stringify') // TODO: cleanup this.text = JSON.stringify(this.json, null, this.indentation); - console.timeEnd('stringify') // TODO: cleanup if (this.options.escapeUnicode === true) { - console.time('escape') // TODO: cleanup this.text = util.escapeUnicodeChars(this.text); - console.timeEnd('escape') // TODO: cleanup } } @@ -594,9 +588,7 @@ previewmode.updateText = function(jsonText) { */ previewmode._setText = function(jsonText, json) { if (this.options.escapeUnicode === true) { - console.time('escape') // TODO: cleanup this.text = util.escapeUnicodeChars(jsonText); - console.timeEnd('escape') // TODO: cleanup } else { this.text = jsonText; @@ -605,7 +597,18 @@ previewmode._setText = function(jsonText, json) { this._renderPreview(); - this._pushHistory(); + if (this.json === undefined) { + var me = this; + this.executeWithBusyMessage(function () { + // force parsing the json now, else it will be done in validate without feedback + me.json = me.get(); + me._renderPreview(); + me._pushHistory(); + }, 'parsing...'); + } + else { + this._pushHistory(); + } this._debouncedValidate(); }; diff --git a/src/js/showTransformModal.js b/src/js/showTransformModal.js index 4b411e7..d5e907d 100644 --- a/src/js/showTransformModal.js +++ b/src/js/showTransformModal.js @@ -252,14 +252,10 @@ function showTransformModal (container, json, onTransform) { function updatePreview() { try { - console.time('transform') // TODO: cleanup var transformed = jmespath.search(value, query.value); - console.timeEnd('transform') // TODO: cleanup - console.time('stringify') // TODO: cleanup preview.className = 'jsoneditor-transform-preview'; preview.value = stringifyPartial(transformed, 2, MAX_PREVIEW_CHARACTERS); - console.timeEnd('stringify') // TODO: cleanup ok.disabled = false; }