Skip to content

Commit

Permalink
import plugin once, store imported module
Browse files Browse the repository at this point in the history
  • Loading branch information
veghdev committed Dec 21, 2023
1 parent 822690e commit 5bf28e0
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/ipyvizzu/templates/ipyvizzu.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (window.IpyVizzu?.version !== '__version__') {
this.events = {}
this.loaded = {}
this.libs = {}
this.plugins = {}
}

static clearInhibitScroll(element) {
Expand All @@ -57,20 +58,25 @@ if (window.IpyVizzu?.version !== '__version__') {

plugin(element, chartId, plugin, options, name, enabled) {
this.charts[chartId] = this.charts[chartId].then((chart) => {
return import(plugin)
.then((pluginModule) => {
const plugin = new pluginModule[name](options)
if (!this.plugins[plugin]) {
this.plugins[plugin] = import(plugin).catch((error) => {
console.error('Error importing plugin:', plugin, error)
return null
})
}

return this.plugins[plugin].then((pluginModule) => {
if (pluginModule) {
const pluginInstance = new pluginModule[name](options)
if (enabled) {
chart.feature(plugin, true)
chart.feature(pluginInstance, true)
} else {
chart.feature(plugin.meta.name, false)
chart.feature(pluginInstance.meta.name, false)
}
return chart
})
.catch((error) => {
console.error('Error importing plugin:', plugin, error)
return chart
})
}

return chart
})
})
}

Expand Down

0 comments on commit 5bf28e0

Please sign in to comment.