@@ -308,7 +308,7 @@ define([
308308 return this . new_model ( options ) ;
309309 }
310310
311- WidgetManager . prototype . new_model = function ( options , create_comm ) {
311+ WidgetManager . prototype . new_model = function ( options ) {
312312 /**
313313 * Create and return a promise for a new widget model
314314 *
@@ -336,7 +336,9 @@ define([
336336 * widget_class: (optional) string
337337 * Target name of the widget in the back-end.
338338 * comm: (optional) Comm
339+ * Comm object associated with the widget.
339340 * model_id: (optional) string
341+ * If not provided, the comm id is used.
340342 *
341343 * Either a comm or a model_id must be provided.
342344 */
@@ -439,32 +441,30 @@ define([
439441 // Recreate all the widget models for the given notebook state.
440442 var all_models = that . _get_comm_info ( kernel ) . then ( function ( live_comms ) {
441443 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 ) ;
447446 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 ) {
458452 return model . request_state ( ) . then ( function ( ) {
459453 return model ;
460454 } ) ;
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 ) {
463463 model . set_state ( state ) ;
464464 return model ;
465465 } ) ;
466- }
467- } ) ;
466+ } ) ;
467+ }
468468 } ) ) ;
469469 } ) ;
470470
0 commit comments