Get rid of var

This commit is contained in:
Tyler Long
2017-09-14 21:12:35 +08:00
parent 20b43d8ad1
commit 6cd5ffe637
2 changed files with 18 additions and 18 deletions

View File

@@ -8,7 +8,7 @@ import mermaidAPI from './mermaidAPI'
import { logger } from './logger' import { logger } from './logger'
import pkg from '../package.json' import pkg from '../package.json'
var nextId = 0 let nextId = 0
/** /**
* ## init * ## init
@@ -31,10 +31,10 @@ var nextId = 0
* Renders the mermaid diagrams * Renders the mermaid diagrams
* @param nodes a css selector or an array of nodes * @param nodes a css selector or an array of nodes
*/ */
var init = function () { const init = function () {
var conf = mermaidAPI.getConfig() const conf = mermaidAPI.getConfig()
logger.debug('Starting rendering diagrams') logger.debug('Starting rendering diagrams')
var nodes let nodes
if (arguments.length >= 2) { if (arguments.length >= 2) {
/*! sequence config was passed as #1 */ /*! sequence config was passed as #1 */
if (typeof arguments[0] !== 'undefined') { if (typeof arguments[0] !== 'undefined') {
@@ -47,7 +47,7 @@ var init = function () {
} }
// if last argument is a function this is the callback function // if last argument is a function this is the callback function
var callback let callback
if (typeof arguments[arguments.length - 1] === 'function') { if (typeof arguments[arguments.length - 1] === 'function') {
callback = arguments[arguments.length - 1] callback = arguments[arguments.length - 1]
logger.debug('Callback function found') logger.debug('Callback function found')
@@ -79,17 +79,10 @@ var init = function () {
mermaidAPI.initialize({ gantt: mermaid.ganttConfig }) mermaidAPI.initialize({ gantt: mermaid.ganttConfig })
} }
var txt let txt
var insertSvg = function (svgCode, bindFunctions) {
element.innerHTML = svgCode
if (typeof callback !== 'undefined') {
callback(id)
}
bindFunctions(element)
}
for (var i = 0; i < nodes.length; i++) { for (let i = 0; i < nodes.length; i++) {
var element = nodes[i] const element = nodes[i]
/*! Check if previously processed */ /*! Check if previously processed */
if (!element.getAttribute('data-processed')) { if (!element.getAttribute('data-processed')) {
@@ -98,7 +91,7 @@ var init = function () {
continue continue
} }
var id = 'mermaidChart' + nextId++ const id = 'mermaidChart' + nextId++
// Fetch the graph definition including tags // Fetch the graph definition including tags
txt = element.innerHTML txt = element.innerHTML
@@ -106,7 +99,13 @@ var init = function () {
// transforms the html to pure text // transforms the html to pure text
txt = he.decode(txt).trim() txt = he.decode(txt).trim()
mermaidAPI.render(id, txt, insertSvg, element) mermaidAPI.render(id, txt, (svgCode, bindFunctions) => {
element.innerHTML = svgCode
if (typeof callback !== 'undefined') {
callback(id)
}
bindFunctions(element)
}, element)
} }
} }
@@ -133,7 +132,7 @@ const initialize = function (config) {
* calls init for rendering the mermaid diagrams on the page. * calls init for rendering the mermaid diagrams on the page.
*/ */
const contentLoaded = function () { const contentLoaded = function () {
var config let config
// Check state of start config mermaid namespace // Check state of start config mermaid namespace
if (typeof global.mermaid_config !== 'undefined') { if (typeof global.mermaid_config !== 'undefined') {
if (global.mermaid_config.htmlLabels === false) { if (global.mermaid_config.htmlLabels === false) {

View File

@@ -12,6 +12,7 @@
- https://github.com/lodash/babel-plugin-lodash - https://github.com/lodash/babel-plugin-lodash
- https://www.npmjs.com/package/lodash-webpack-plugin - https://www.npmjs.com/package/lodash-webpack-plugin
- Replace var with const/let - Replace var with const/let
- flowchart/flowrenderer
- global.mermaid_config - global.mermaid_config
- rewrite logger - rewrite logger
- rewrite less code - rewrite less code