You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2021/09/15 05:05:48 UTC
[echarts-examples] branch dev updated: optimize version switch
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/echarts-examples.git
The following commit(s) were added to refs/heads/dev by this push:
new d67dde2 optimize version switch
d67dde2 is described below
commit d67dde29f20a7dc0e9d1783e7204e1002caa8e34
Author: pissang <bm...@gmail.com>
AuthorDate: Wed Sep 15 13:04:07 2021 +0800
optimize version switch
---
src/common/helper.js | 1 +
src/common/route.js | 2 +-
src/common/store.js | 29 ++++++++++++++++++++++++++++-
src/editor/Editor.vue | 6 +++---
src/editor/Preview.vue | 18 ++++++++++++------
5 files changed, 45 insertions(+), 11 deletions(-)
diff --git a/src/common/helper.js b/src/common/helper.js
index 808e698..4ce38e8 100644
--- a/src/common/helper.js
+++ b/src/common/helper.js
@@ -1,5 +1,6 @@
import { store } from './store';
import { SCRIPT_URLS } from './config';
+
const promisesCache = {};
export function loadScriptsAsync(scripts) {
diff --git a/src/common/route.js b/src/common/route.js
index 4ede915..eeca3be 100644
--- a/src/common/route.js
+++ b/src/common/route.js
@@ -21,7 +21,7 @@ export function getURL(params) {
);
}
-export function goto(params, pushHistory) {
+export function gotoURL(params, pushHistory) {
if (pushHistory) {
history.pushState({}, getURL(params));
} else {
diff --git a/src/common/store.js b/src/common/store.js
index 690476d..20a6d2b 100644
--- a/src/common/store.js
+++ b/src/common/store.js
@@ -4,7 +4,7 @@ import CHART_LIST from '../data/chart-list-data';
import CHART_LIST_GL from '../data/chart-list-data-gl';
export const store = {
- echartsVersion: '5',
+ echartsVersion: URL_PARAMS.version || '5',
cdnRoot: '',
version: '',
@@ -45,7 +45,34 @@ export function isGLExample() {
return CHART_LIST_GL.find(findExample);
}
+export function saveExampleCodeToLocal() {
+ localStorage.setItem(
+ 'echarts-examples-code',
+ JSON.stringify({
+ code: store.sourceCode,
+ lang: store.typeCheck ? 'ts' : 'js'
+ })
+ );
+}
+
+export function loadExampleCodeFromLocal() {
+ try {
+ return JSON.parse(localStorage.getItem('echarts-examples-code'));
+ } catch (e) {
+ return null;
+ }
+}
+
+export function clearLocalExampleCode() {
+ localStorage.removeItem('echarts-examples-code');
+}
+
export function loadExampleCode() {
+ const localCode = loadExampleCodeFromLocal();
+ if (localCode) {
+ clearLocalExampleCode();
+ return Promise.resolve(localCode.code);
+ }
return new Promise((resolve) => {
const glFolder = URL_PARAMS.gl ? 'gl/' : '';
const lang = store.typeCheck ? 'ts' : 'js';
diff --git a/src/editor/Editor.vue b/src/editor/Editor.vue
index 2daf78c..209e864 100644
--- a/src/editor/Editor.vue
+++ b/src/editor/Editor.vue
@@ -160,7 +160,7 @@ import {
getExampleConfig
} from '../common/store';
import { collectDeps, buildExampleCode } from '../../common/buildCode';
-import { goto } from '../common/route';
+import { gotoURL } from '../common/route';
import { mount } from '@lang/object-visualizer';
import './object-visualizer.css';
@@ -339,7 +339,7 @@ export default {
changeLang(lang) {
if ((URL_PARAMS.lang || 'js').toLowerCase() !== lang) {
if (!this.initialCode || store.sourceCode === this.initialCode) {
- goto(
+ gotoURL(
Object.assign({}, URL_PARAMS, {
lang
})
@@ -351,7 +351,7 @@ export default {
type: 'warning'
})
.then(() => {
- goto(
+ gotoURL(
Object.assign({}, URL_PARAMS, {
lang
})
diff --git a/src/editor/Preview.vue b/src/editor/Preview.vue
index 4b9d3d3..ff240c1 100644
--- a/src/editor/Preview.vue
+++ b/src/editor/Preview.vue
@@ -126,6 +126,7 @@
import {
getExampleConfig,
isGLExample,
+ saveExampleCodeToLocal,
store,
updateRunHash
} from '../common/store';
@@ -135,10 +136,13 @@ import { createSandbox } from './sandbox';
import debounce from 'lodash/debounce';
import { addListener } from 'resize-detector';
import { download } from './downloadExample';
+import { gotoURL } from '../common/route';
const example = getExampleConfig();
const isGL = isGLExample();
+const echartsVersions = {};
+
function addDecalIfNecessary(option) {
if (store.enableDecal) {
option.aria = option.aria || {};
@@ -167,7 +171,6 @@ export function ensureECharts() {
'local' in URL_PARAMS
? SCRIPT_URLS.localEChartsMinJS
: SCRIPT_URLS.echartsMinJS.replace('{{version}}', store.echartsVersion),
- echartsDir + '/dist/extension/dataTool.js',
'https://cdn.jsdelivr.net/npm/echarts@4.9.0/map/js/world.js',
SCRIPT_URLS.echartsStatMinJS,
...(URL_PARAMS.gl ? [SCRIPT_URLS.echartsGLMinJS] : []),
@@ -371,11 +374,14 @@ export default {
return this.sandbox && this.sandbox.getOption();
},
changeVersion() {
- if (this.sandbox) {
- this.sandbox.dispose();
- }
- window.echarts = undefined;
- this.loadECharts();
+ saveExampleCodeToLocal();
+ setTimeout(() => {
+ gotoURL(
+ Object.assign({}, URL_PARAMS, {
+ version: store.echartsVersion
+ })
+ );
+ });
}
// hasEditorError() {
// const annotations = this.editor.getSession().getAnnotations();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org