@@ -58,8 +58,29 @@ 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
+
65
+ get widgets ( ) : base . IWidgetRegistryData [ ] {
66
+ return [ ...this . _registry ] ;
67
+ }
68
+
69
+ push ( data : base . IWidgetRegistryData ) {
70
+ this . _registry . push ( data ) ;
71
+ this . _registeredWidget . emit ( data ) ;
72
+ }
73
+
74
+ get registeredWidget ( ) : ISignal < WidgetRegistry , base . IWidgetRegistryData > {
75
+ return this . _registeredWidget ;
76
+ }
77
+
78
+ private _registeredWidget = new Signal < WidgetRegistry , base . IWidgetRegistryData > ( this ) ;
79
+
80
+ private _registry : base . IWidgetRegistryData [ ] = [ ] ;
81
+ }
82
+
83
+ const WIDGET_REGISTRY = new WidgetRegistry ( ) ;
63
84
64
85
/**
65
86
* The cached settings.
@@ -178,7 +199,10 @@ async function registerWidgetHandler(
178
199
179
200
if ( ! wManager ) {
180
201
wManager = widgetManagerFactory ( ) ;
181
- WIDGET_REGISTRY . forEach ( ( data ) => wManager ! . register ( data ) ) ;
202
+ WIDGET_REGISTRY . widgets . forEach ( ( data ) => wManager ! . register ( data ) ) ;
203
+ WIDGET_REGISTRY . registeredWidget . connect ( ( _ , data ) => {
204
+ wManager ! . register ( data ) ;
205
+ } ) ;
182
206
Private . widgetManagerProperty . set ( wManagerOwner , wManager ) ;
183
207
currentOwner = wManagerOwner ;
184
208
content . disposed . connect ( ( _ ) => {
@@ -241,7 +265,10 @@ export function registerWidgetManager(
241
265
) as WidgetManager ;
242
266
if ( ! currentManager ) {
243
267
wManager = new WidgetManager ( context , rendermime , SETTINGS ) ;
244
- WIDGET_REGISTRY . forEach ( ( data ) => wManager ! . register ( data ) ) ;
268
+ WIDGET_REGISTRY . widgets . forEach ( ( data ) => wManager ! . register ( data ) ) ;
269
+ WIDGET_REGISTRY . registeredWidget . connect ( ( _ , data ) => {
270
+ wManager ! . register ( data ) ;
271
+ } ) ;
245
272
Private . widgetManagerProperty . set ( wManagerOwner , wManager ) ;
246
273
} else {
247
274
wManager = currentManager ;
0 commit comments