* Create and return a promise for a new widget model * * @param options - the options for creating the model. * @param serialized_state - attribute values for the model. * * @example * widget_manager.new_model({ * model_name: 'IntSlider', * model_module: '@jupyter-w
(
options: IModelOptions,
serialized_state: any = {}
)
| 353 | * |
| 354 | */ |
| 355 | async new_model( |
| 356 | options: IModelOptions, |
| 357 | serialized_state: any = {} |
| 358 | ): Promise<WidgetModel> { |
| 359 | const model_id = options.model_id ?? options.comm?.comm_id; |
| 360 | if (!model_id) { |
| 361 | throw new Error( |
| 362 | 'Neither comm nor model_id provided in options object. At least one must exist.' |
| 363 | ); |
| 364 | } |
| 365 | options.model_id = model_id; |
| 366 | const modelPromise = this._make_model( |
| 367 | options as RequiredSome<IModelOptions, 'model_id'>, |
| 368 | serialized_state |
| 369 | ); |
| 370 | // this call needs to happen before the first `await`, see note in `set_state`: |
| 371 | this.register_model(model_id, modelPromise); |
| 372 | return await modelPromise; |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Fetch all widgets states from the kernel using the control comm channel |
nothing calls this directly
no test coverage detected
searching dependent graphs…