diff --git a/src/components/DashKit/DashKit.tsx b/src/components/DashKit/DashKit.tsx index 0892770..d3a7121 100644 --- a/src/components/DashKit/DashKit.tsx +++ b/src/components/DashKit/DashKit.tsx @@ -119,6 +119,12 @@ export class DashKit extends React.PureComponent { }); } + static reloadPlugins(...plugins: Plugin[]) { + plugins.forEach((plugin) => { + registerManager.reloadPlugin(plugin); + }); + } + static setSettings(settings: Settings) { registerManager.setSettings(settings); } diff --git a/src/components/DashKit/__stories__/DashKit.stories.tsx b/src/components/DashKit/__stories__/DashKit.stories.tsx index 6531763..d2bbad0 100644 --- a/src/components/DashKit/__stories__/DashKit.stories.tsx +++ b/src/components/DashKit/__stories__/DashKit.stories.tsx @@ -47,11 +47,12 @@ if (!getInitialized()) { apiHandler: ({text}) => Promise.resolve({result: text}), }), ); - DashKit.registerPlugins({ + + const customPlugin = { type: 'custom', defaultLayout: { - w: 10, - h: 10, + w: 20, + h: 20, }, renderer: function CustomPlugin() { return ( @@ -62,6 +63,15 @@ if (!getInitialized()) { ); }, + }; + + DashKit.registerPlugins(customPlugin); + DashKit.reloadPlugins({ + ...customPlugin, + defaultLayout: { + w: 10, + h: 10, + }, }); DashKit.setSettings({ diff --git a/src/utils/register-manager.ts b/src/utils/register-manager.ts index 91b78de..dfc129d 100644 --- a/src/utils/register-manager.ts +++ b/src/utils/register-manager.ts @@ -40,13 +40,20 @@ export class RegisterManager { }; registerPlugin(plugin: Plugin) { - const {type, defaultLayout = {}, ...item} = plugin; + const {type} = plugin; if (type in this._items) { throw new Error(`DashKit.registerPlugins: type ${type} уже был зарегистрирован`); } + this.reloadPlugin(plugin); + } + + reloadPlugin(plugin: Plugin) { + const {type, defaultLayout = {}, ...item} = plugin; + if (typeof plugin.renderer !== 'function') { throw new Error('DashKit.registerPlugins: renderer должна быть функцией'); } + this._items[type] = { ...item, type,