@@ -405,22 +405,30 @@ abstract class ManagerBase<T> {
405
405
/**
406
406
* Set the widget manager state.
407
407
*
408
+ * @param state - a Javascript object conforming to the application/vnd.jupyter.widget-state+json spec.
409
+ *
408
410
* Reconstructs all of the widget models in the state, merges that with the
409
411
* current manager state, and then attempts to redisplay the widgets in the
410
412
* state.
411
413
*/
412
414
set_state ( state , displayOptions ) {
415
+
416
+ // Check to make sure that it's the same version we are parsing.
417
+ if ( ! ( state . version_major && state . version_major < 2 ) ) {
418
+ throw "Unsupported widget state format" ;
419
+ }
420
+ let models = state . state ;
413
421
// Recreate all the widget models for the given widget manager state.
414
422
let all_models = this . _get_comm_info ( ) . then ( live_comms => {
415
- return Promise . all ( Object . keys ( state ) . map ( model_id => {
423
+ return Promise . all ( Object . keys ( models ) . map ( model_id => {
416
424
417
425
// First put back the binary buffers
418
426
let decode = { 'base64' : toByteArray , 'hex' : utils . hexToBuffer } ;
419
- let modelState = state [ model_id ] . state ;
427
+ let modelState = models [ model_id ] . state ;
420
428
if ( modelState . buffers ) {
421
429
let bufferPaths = modelState . buffers . map ( b => b . path ) ;
422
430
let buffers = modelState . buffers . map ( b => decode [ b . encoding ] ( b . data ) ) ;
423
- utils . put_buffers ( modelState , bufferPaths , buffers ) ;
431
+ utils . put_buffers ( modelState . state , bufferPaths , buffers ) ;
424
432
}
425
433
426
434
// If the model has already been created, set its state and then
@@ -439,17 +447,17 @@ abstract class ManagerBase<T> {
439
447
return this . _create_comm ( this . comm_target_name , model_id ) . then ( new_comm => {
440
448
return this . new_model ( {
441
449
comm : new_comm ,
442
- model_name : state [ model_id ] . model_name ,
443
- model_module : state [ model_id ] . model_module ,
444
- model_module_version : state [ model_id ] . model_module_version
450
+ model_name : models [ model_id ] . model_name ,
451
+ model_module : models [ model_id ] . model_module ,
452
+ model_module_version : models [ model_id ] . model_module_version
445
453
} ) ;
446
454
} ) ;
447
455
} else { // dead comm
448
456
return this . new_model ( {
449
457
model_id : model_id ,
450
- model_name : state [ model_id ] . model_name ,
451
- model_module : state [ model_id ] . model_module ,
452
- model_module_version : state [ model_id ] . model_module_version
458
+ model_name : models [ model_id ] . model_name ,
459
+ model_module : models [ model_id ] . model_module ,
460
+ model_module_version : models [ model_id ] . model_module_version
453
461
} , modelState ) ;
454
462
}
455
463
} ) ) ;
0 commit comments