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 2020/09/03 06:10:19 UTC
[incubator-echarts-doc] branch next updated: formatter: optimize
key generation
This is an automated email from the ASF dual-hosted git repository.
shenyi pushed a commit to branch next
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-doc.git
The following commit(s) were added to refs/heads/next by this push:
new f5fefd0 formatter: optimize key generation
f5fefd0 is described below
commit f5fefd08ae90cfe811df25a15c6c31d3c8c90bac
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Sep 3 14:10:09 2020 +0800
formatter: optimize key generation
---
editor/common/blockHelper.js | 47 +++++++++++++++++++++-----------------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/editor/common/blockHelper.js b/editor/common/blockHelper.js
index 7e8d32e..d79aa37 100644
--- a/editor/common/blockHelper.js
+++ b/editor/common/blockHelper.js
@@ -138,6 +138,7 @@ module.exports.updateBlocksLevels = function (blocks, targetsMap) {
case 'endif':
case 'for':
case 'endfor':
+ case 'uicontrol':
// Indent description content by default
block.level = currentLevel + 1;
break;
@@ -178,14 +179,25 @@ module.exports.updateBlocksKeys = function (blocks) {
const stacks = ['top'];
- let duplicateKeyCount = 0;
+ let scopeKey = stacks.join('.');
- const keyMap = {};
+ function keyNoDuplicate() {
+ const keyCount = {};
+ const keyMap = {};
+ return function (baseKey) {
+ let keyNoDuplicate = baseKey;
+ keyCount[baseKey] = keyCount[baseKey] || 1;
+ while (keyMap[keyNoDuplicate]) {
+ keyNoDuplicate = baseKey + '-' + keyCount[baseKey]++;
+ }
+ keyMap[keyNoDuplicate] = true;
+ return keyNoDuplicate;
+ }
+ }
- const contentKeyCountMap = {};
- const uiControlKeyCountMap = {};
-
- let scopeKey = stacks.join('.');
+ const contentKeyNoDuplicate = keyNoDuplicate();
+ const uiControlKeyNoDuplicate = keyNoDuplicate();
+ const allKeyNoDuplicate = keyNoDuplicate();
for (const block of blocks) {
let baseKey = '';
@@ -207,12 +219,7 @@ module.exports.updateBlocksKeys = function (blocks) {
break;
// Content and use command following header has same level.
case 'content':
- baseKey = `content:${scopeKey}`;
- contentKeyCountMap[baseKey] = contentKeyCountMap[baseKey] || 0;
- if (contentKeyCountMap[baseKey]) {
- baseKey += '-' + contentKeyCountMap[baseKey];
- }
- contentKeyCountMap[baseKey]++;
+ baseKey = contentKeyNoDuplicate(`content:${scopeKey}`);
break;
case 'use':
case 'import':
@@ -229,21 +236,11 @@ module.exports.updateBlocksKeys = function (blocks) {
baseKey = `${baseKey}:${block.expr}`
}
break;
- case 'exampleuicontrol':
- baseKey = `uicontrol:${scopeKey}`;
- uiControlKeyCountMap[baseKey] = uiControlKeyCountMap[baseKey] || 0;
- if (uiControlKeyCountMap[baseKey]) {
- baseKey += '-' + uiControlKeyCountMap[baseKey];
- }
- uiControlKeyCountMap[baseKey]++;
- }
- let keyNoDuplicate = baseKey;
- while (keyMap[keyNoDuplicate]) {
- keyNoDuplicate = baseKey + '-' + (duplicateKeyCount++);
+ case 'uicontrol':
+ baseKey = uiControlKeyNoDuplicate(`uicontrol:${scopeKey}`);
}
- keyMap[keyNoDuplicate] = true;
- block.key = keyNoDuplicate;
+ block.key = allKeyNoDuplicate(baseKey) ;
}
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org