MCPcopy
hub / github.com/jupyter-widgets/ipywidgets / new_model

Function new_model

packages/base-manager/src/manager-base.ts:355–373  ·  view source on GitHub ↗

* 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 = {}
  )

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

_make_modelMethod · 0.80
register_modelMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…