@@ -58,8 +58,31 @@ import '@jupyter-widgets/controls/css/widgets-base.css';
58
58
import { KernelMessage } from '@jupyterlab/services' ;
59
59
import { ITranslator , nullTranslator } from '@jupyterlab/translation' ;
60
60
import { ISessionContext } from '@jupyterlab/apputils' ;
61
+ import { ISignal , Signal } from '@lumino/signaling' ;
61
62
62
- const WIDGET_REGISTRY : base . IWidgetRegistryData [ ] = [ ] ;
63
+ class WidgetRegistry {
64
+ get widgets ( ) : base . IWidgetRegistryData [ ] {
65
+ return [ ...this . _registry ] ;
66
+ }
67
+
68
+ push ( data : base . IWidgetRegistryData ) {
69
+ this . _registry . push ( data ) ;
70
+ this . _widgetRegistered . emit ( data ) ;
71
+ }
72
+
73
+ get widgetRegistered ( ) : ISignal < WidgetRegistry , base . IWidgetRegistryData > {
74
+ return this . _widgetRegistered ;
75
+ }
76
+
77
+ private _widgetRegistered = new Signal <
78
+ WidgetRegistry ,
79
+ base . IWidgetRegistryData
80
+ > ( this ) ;
81
+
82
+ private _registry : base . IWidgetRegistryData [ ] = [ ] ;
83
+ }
84
+
85
+ const WIDGET_REGISTRY = new WidgetRegistry ( ) ;
63
86
64
87
/**
65
88
* The cached settings.
@@ -178,7 +201,10 @@ async function registerWidgetHandler(
178
201
179
202
if ( ! wManager ) {
180
203
wManager = widgetManagerFactory ( ) ;
181
- WIDGET_REGISTRY . forEach ( ( data ) => wManager ! . register ( data ) ) ;
204
+ WIDGET_REGISTRY . widgets . forEach ( ( data ) => wManager ! . register ( data ) ) ;
205
+ WIDGET_REGISTRY . widgetRegistered . connect ( ( _ , data ) => {
206
+ wManager ! . register ( data ) ;
207
+ } ) ;
182
208
Private . widgetManagerProperty . set ( wManagerOwner , wManager ) ;
183
209
currentOwner = wManagerOwner ;
184
210
content . disposed . connect ( ( _ ) => {
@@ -241,7 +267,10 @@ export function registerWidgetManager(
241
267
) as WidgetManager ;
242
268
if ( ! currentManager ) {
243
269
wManager = new WidgetManager ( context , rendermime , SETTINGS ) ;
244
- WIDGET_REGISTRY . forEach ( ( data ) => wManager ! . register ( data ) ) ;
270
+ WIDGET_REGISTRY . widgets . forEach ( ( data ) => wManager ! . register ( data ) ) ;
271
+ WIDGET_REGISTRY . widgetRegistered . connect ( ( _ , data ) => {
272
+ wManager ! . register ( data ) ;
273
+ } ) ;
245
274
Private . widgetManagerProperty . set ( wManagerOwner , wManager ) ;
246
275
} else {
247
276
wManager = currentManager ;
0 commit comments