This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch live-example
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-doc.git


The following commit(s) were added to refs/heads/live-example by this push:
     new b24cc66  example: fix callback function lost during stringify
b24cc66 is described below

commit b24cc66e64bd2db763e2ac3e6140f38f951bb857
Author: pissang <bm2736...@gmail.com>
AuthorDate: Thu Jun 18 00:19:12 2020 +0800

    example: fix callback function lost during stringify
---
 src/components/LiveExample.vue | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/components/LiveExample.vue b/src/components/LiveExample.vue
index 581ca24..f19b942 100644
--- a/src/components/LiveExample.vue
+++ b/src/components/LiveExample.vue
@@ -240,11 +240,22 @@ export default {
 
     computed: {
         optionCodeStr() {
-            return `const option = 
${JSON.stringify(this.shared.currentExampleOption)}`;
+            const optStr = JSON.stringify(this.shared.currentExampleOption, 
function (key, value) {
+                if (typeof value === 'function') {
+                    return "__functionstart__" + value.toString() + 
"__functionend__";
+                }
+                return value;
+            });
+            return `const option = ${optStr}`;
         },
 
         formattedOptionCodeStr() {
-            return beautify.js(this.optionCodeStr.replace(/"(\w+)"\s*:/g, 
'$1:'), {
+            return beautify.js(this.optionCodeStr
+                .replace(/"(\w+)"\s*:/g, '$1:')
+                .replace(/"__functionstart__/g, "")
+                .replace(/__functionend__"/g, "")
+                // newline from function
+                .replace(/\\n/g, '\n'), {
                 indent_size: 2
             });
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org
For additional commands, e-mail: commits-h...@echarts.apache.org

Reply via email to