Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions api-goldens/dashboards-ng/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export const provideDashboardToolbarItems: (toolbarItems?: {
secondary?: DashboardToolbarItem[];
}) => Provider;

// @public
// @public (undocumented)
export type SetupComponentFn = <T>(factory: WidgetComponentFactory, componentName: string, host: ViewContainerRef, injector: Injector, envInjector: EnvironmentInjector) => Observable<ComponentRef<T>>;

// @public (undocumented)
Expand Down Expand Up @@ -338,16 +338,6 @@ export interface WidgetConfigStatus {
modified: boolean;
}

// @public (undocumented)
export const widgetFactoryRegistry: {
_factories: {
[key: string]: SetupComponentFn;
};
register(name: string, factoryFn: SetupComponentFn): void;
getFactoryFn(name: string): SetupComponentFn;
hasFactoryFn(name: string): boolean;
};

// @public
export interface WidgetImage {
alt: string;
Expand Down
8 changes: 4 additions & 4 deletions projects/dashboards-ng/src/widget-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ describe('widget-loader', () => {

describe('widgetFactoryRegistry', () => {
it('#hasFactoryFn() should return false for a not existing factory function', () => {
expect(widgetFactoryRegistry.hasFactoryFn('nothing')).toBe(false);
expect(widgetFactoryRegistry.hasFactoryFn('module-federation')).toBe(false);
});

it('#register() should add a factory function to the registry', () => {
const factoryFn = {} as SetupComponentFn;
widgetFactoryRegistry.register('my-function', factoryFn);
expect(widgetFactoryRegistry.hasFactoryFn('my-function')).toBe(true);
expect(widgetFactoryRegistry.getFactoryFn('my-function')).toBe(factoryFn);
widgetFactoryRegistry.register('module-federation', factoryFn);
expect(widgetFactoryRegistry.hasFactoryFn('module-federation')).toBe(true);
expect(widgetFactoryRegistry.getFactoryFn('module-federation')).toBe(factoryFn);
});
});
13 changes: 9 additions & 4 deletions projects/dashboards-ng/src/widget-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import { Observable, ReplaySubject, Subject, throwError } from 'rxjs';
import { SiWebComponentEditorWrapperComponent } from './components/web-component-wrapper/si-web-component-editor-wrapper.component';
import { SiWebComponentWrapperComponent } from './components/web-component-wrapper/si-web-component-wrapper.component';
import {
FederatedBridgeModule,
FederatedModule,
WebComponent,
WidgetComponentFactory,
WidgetComponentTypeFactory,
WidgetInstance,
WidgetInstanceEditor
} from './model/widgets.model';

type WidgetFactoryType = FederatedModule['factoryType'] | FederatedBridgeModule['factoryType'];

export type SetupComponentFn = <T>(
factory: WidgetComponentFactory,
componentName: string,
Expand All @@ -29,18 +33,19 @@ export type SetupComponentFn = <T>(
envInjector: EnvironmentInjector
) => Observable<ComponentRef<T>>;

/** @internal */
export const widgetFactoryRegistry = {
_factories: {} as { [key: string]: SetupComponentFn },
_factories: {} as { [key in WidgetFactoryType]?: SetupComponentFn },

register(name: string, factoryFn: SetupComponentFn) {
register(name: WidgetFactoryType, factoryFn: SetupComponentFn) {
this._factories[name] = factoryFn;
},

getFactoryFn(name: string) {
getFactoryFn(name: WidgetFactoryType) {
return this._factories[name];
},

hasFactoryFn(name: string) {
hasFactoryFn(name: WidgetFactoryType) {
return this._factories[name] !== undefined;
}
};
Expand Down
Loading