@@ -308,7 +308,7 @@ define([
308
308
return this . new_model ( options ) ;
309
309
}
310
310
311
- WidgetManager . prototype . new_model = function ( options , create_comm ) {
311
+ WidgetManager . prototype . new_model = function ( options ) {
312
312
/**
313
313
* Create and return a promise for a new widget model
314
314
*
@@ -336,7 +336,9 @@ define([
336
336
* widget_class: (optional) string
337
337
* Target name of the widget in the back-end.
338
338
* comm: (optional) Comm
339
+ * Comm object associated with the widget.
339
340
* model_id: (optional) string
341
+ * If not provided, the comm id is used.
340
342
*
341
343
* Either a comm or a model_id must be provided.
342
344
*/
@@ -439,32 +441,30 @@ define([
439
441
// Recreate all the widget models for the given notebook state.
440
442
var all_models = that . _get_comm_info ( kernel ) . then ( function ( live_comms ) {
441
443
return Promise . all ( _ . map ( Object . keys ( state ) , function ( model_id ) {
442
- // Creates a comm using the widget's model id.
443
- var live = live_comms . hasOwnProperty ( model_id ) ;
444
- var new_comm ;
445
- if ( live ) {
446
- new_comm = new comm . Comm ( kernel . widget_manager . comm_target_name , model_id ) ;
444
+ if ( live_comms . hasOwnProperty ( model_id ) ) { // live comm
445
+ var new_comm = new comm . Comm ( kernel . widget_manager . comm_target_name , model_id ) ;
447
446
kernel . comm_manager . register_comm ( new_comm ) ;
448
- } else {
449
- new_comm = void 0 ;
450
- }
451
- return kernel . widget_manager . new_model ( {
452
- comm : new_comm ,
453
- model_name : state [ model_id ] . model_name ,
454
- model_module : state [ model_id ] . model_module ,
455
- model_id : model_id ,
456
- } ) . then ( function ( model ) {
457
- if ( live ) {
447
+ return kernel . widget_manager . new_model ( {
448
+ comm : new_comm ,
449
+ model_name : state [ model_id ] . model_name ,
450
+ model_module : state [ model_id ] . model_module ,
451
+ } ) . then ( function ( model ) {
458
452
return model . request_state ( ) . then ( function ( ) {
459
453
return model ;
460
454
} ) ;
461
- } else {
462
- return model . _deserialize_state ( state [ model . id ] . state ) . then ( function ( state ) {
455
+ } ) ;
456
+ } else { // dead comm
457
+ return kernel . widget_manager . new_model ( {
458
+ model_id : model_id ,
459
+ model_name : state [ model_id ] . model_name ,
460
+ model_module : state [ model_id ] . model_module ,
461
+ } ) . then ( function ( model ) {
462
+ return model . _deserialize_state ( state [ model_id ] . state ) . then ( function ( state ) {
463
463
model . set_state ( state ) ;
464
464
return model ;
465
465
} ) ;
466
- }
467
- } ) ;
466
+ } ) ;
467
+ }
468
468
} ) ) ;
469
469
} ) ;
470
470
0 commit comments