mirror of
https://gitee.com/antv/g6.git
synced 2024-11-30 02:38:20 +08:00
refactor(register): adjust getPlugins returns type (#5363)
This commit is contained in:
parent
9f09fa4eef
commit
a4aa09bc41
@ -135,7 +135,7 @@ export default abstract class Item implements IItem {
|
||||
lodLevels: modelLodLevels,
|
||||
enableBalanceShape,
|
||||
} = this.displayModel.data;
|
||||
const RenderExtension = renderExtensions.find((ext) => ext.type === type);
|
||||
const RenderExtension = renderExtensions[type];
|
||||
this.themeStyles = theme.styles;
|
||||
this.lodLevels = modelLodLevels ? formatLodLevels(modelLodLevels) : theme.lodLevels;
|
||||
if (!RenderExtension) {
|
||||
@ -270,7 +270,7 @@ export default abstract class Item implements IItem {
|
||||
Object.values(this.shapeMap).forEach((child) => child.destroy());
|
||||
this.shapeMap = { keyShape: undefined };
|
||||
const { type = this.type === 'node' ? 'circle-node' : 'line-edge' } = displayModel.data;
|
||||
const RenderExtension = this.renderExtensions.find((ext) => ext.type === type);
|
||||
const RenderExtension = this.renderExtensions[type];
|
||||
this.renderExt = new RenderExtension({
|
||||
themeStyles: this.themeStyles.default,
|
||||
lodLevels: this.lodLevels,
|
||||
|
@ -65,7 +65,6 @@ function register<T extends PluginCategory>(category: T, type: string, pluginCla
|
||||
);
|
||||
}
|
||||
|
||||
pluginClass.type = type;
|
||||
pluginRegistry[category].set(type, pluginClass);
|
||||
}
|
||||
|
||||
@ -83,15 +82,15 @@ function getPlugin<T extends PluginCategory>(category: T, type: string): PluginR
|
||||
}
|
||||
|
||||
/**
|
||||
* <zh/> 根据类别获取所有的插件类列表。
|
||||
* <zh/> 根据类别获取所有的插件类。
|
||||
*
|
||||
* <en/> Retrieves a list of all plugin classes for a given category.
|
||||
* <en/> Retrieves all plugin classes for a given category.
|
||||
* @param category - <zh/> 要检索的插件分类 | <en/> Plugin category to retrieve
|
||||
* @returns <zh/> 返回指定类别下所有插件类的数组 | <en/> Returns an array of all plugin classes for the specified category
|
||||
* @returns <zh/> 返回指定类别下所有插件类 | <en/> Returns all plugin classes for the specified category
|
||||
* @internal
|
||||
*/
|
||||
function getPlugins<T extends PluginCategory>(category: T): PluginRegistry[T][string][] {
|
||||
return Array.from(pluginRegistry[category]?.values() || []);
|
||||
function getPlugins<T extends PluginCategory>(category: T) {
|
||||
return Object.fromEntries(pluginRegistry[category]) as PluginRegistry[T];
|
||||
}
|
||||
|
||||
export { getPlugin, getPlugins, register };
|
||||
|
@ -87,9 +87,9 @@ const getWarnMsg = {
|
||||
*/
|
||||
export class ItemController {
|
||||
public graph: Graph;
|
||||
public nodeExtensions: NodeRegistry[string][] = [];
|
||||
public edgeExtensions: EdgeRegistry[string][] = [];
|
||||
public comboExtensions: NodeRegistry[string][] = [];
|
||||
public nodeExtensions: NodeRegistry = {};
|
||||
public edgeExtensions: EdgeRegistry = {};
|
||||
public comboExtensions: NodeRegistry = {};
|
||||
|
||||
public zoom: number;
|
||||
|
||||
|
@ -42,10 +42,7 @@ export class ThemeController {
|
||||
}
|
||||
|
||||
private getThemes(): ThemeRegistry {
|
||||
return getPlugins('theme').reduce((res, acc) => {
|
||||
res[acc.type] = acc;
|
||||
return res;
|
||||
}, {}) as ThemeRegistry;
|
||||
return getPlugins('theme');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,7 +47,7 @@ describe('Plugin Registration', () => {
|
||||
it('should retrieve all plugins for a given category', () => {
|
||||
register(category, type, CustomBehavior);
|
||||
const plugins = getPlugins(category);
|
||||
expect(plugins).toContain(CustomBehavior);
|
||||
expect(plugins[type]).toBe(CustomBehavior);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user