@@ -3,6 +3,7 @@ import type { CanvasWidgetStructure } from "WidgetProvider/types";
33import type BaseWidget from "widgets/BaseWidget" ;
44import WidgetFactory from "." ;
55import { withBaseWidgetHOC } from "widgets/BaseWidgetHOC/withBaseWidgetHOC" ;
6+ import { incrementWidgetConfigsVersion } from "./widgetConfigVersion" ;
67
78/*
89 * Function to create builder for the widgets and register them in widget factory
@@ -11,28 +12,31 @@ import { withBaseWidgetHOC } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
1112 * extracted this into a seperate file to break the circular reference.
1213 *
1314 */
15+
1416export const registerWidgets = ( widgets : ( typeof BaseWidget ) [ ] ) => {
15- const widgetAndBuilders = widgets . map ( ( widget ) => {
16- const { eagerRender = false , needsMeta = false } = widget . getConfig ( ) ;
17+ widgets . forEach ( ( widget ) => {
18+ registerWidget ( widget ) ;
19+ } ) ;
20+ // Increment version to trigger selectors that depend on widget configs
21+ incrementWidgetConfigsVersion ( ) ;
22+ } ;
1723
18- // TODO: Fix this the next time the file is edited
19- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20- const ProfiledWidget : any = withBaseWidgetHOC (
21- widget ,
22- needsMeta ,
23- eagerRender ,
24- ) ;
24+ export const registerWidget = ( widget : typeof BaseWidget ) => {
25+ const { eagerRender = false , needsMeta = false } = widget . getConfig ( ) ;
2526
26- return [
27- widget ,
28- ( widgetProps : CanvasWidgetStructure ) => (
29- < ProfiledWidget { ...widgetProps } key = { widgetProps . widgetId } />
30- ) ,
31- ] as [
32- typeof BaseWidget ,
33- ( widgetProps : CanvasWidgetStructure ) => React . ReactNode ,
34- ] ;
35- } ) ;
27+ // TODO: Fix this the next time the file is edited
28+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29+ const ProfiledWidget : any = withBaseWidgetHOC ( widget , needsMeta , eagerRender ) ;
30+
31+ const widgetAndBuilder : [
32+ typeof BaseWidget ,
33+ ( widgetProps : CanvasWidgetStructure ) => React . ReactNode ,
34+ ] = [
35+ widget ,
36+ ( widgetProps : CanvasWidgetStructure ) => (
37+ < ProfiledWidget { ...widgetProps } key = { widgetProps . widgetId } />
38+ ) ,
39+ ] ;
3640
37- WidgetFactory . initialize ( widgetAndBuilders ) ;
41+ WidgetFactory . initialize ( [ widgetAndBuilder ] ) ;
3842} ;
0 commit comments