diff --git a/{{cookiecutter.github_project_name}}/src/__tests__/utils.ts b/{{cookiecutter.github_project_name}}/src/__tests__/utils.ts index 0a61d63..f784d2f 100644 --- a/{{cookiecutter.github_project_name}}/src/__tests__/utils.ts +++ b/{{cookiecutter.github_project_name}}/src/__tests__/utils.ts @@ -51,18 +51,17 @@ export class DummyManager extends baseManager.ManagerBase { this.el = window.document.createElement('div'); } - display_view( + async display_view: ( msg: services.KernelMessage.IMessage, view: widgets.DOMWidgetView, - options: any - ) { + options: unknown + ): Promise { // TODO: make this a spy // TODO: return an html element - return Promise.resolve(view).then((view) => { - this.el.appendChild(view.el); - view.on('remove', () => console.log('view removed', view)); - return view.el; - }); + const view_1 = await Promise.resolve(view); + this.el.appendChild(view_1.el); + view_1.on('remove', () => console.log('view removed', view_1)); + return view_1.el; } protected loadClass( @@ -87,26 +86,26 @@ export class DummyManager extends baseManager.ManagerBase { } } - _get_comm_info() { + _get_comm_info(): Promise> { return Promise.resolve({}); } - _create_comm() { + _create_comm(): Promise { return Promise.resolve(new MockComm()); } el: HTMLElement; - testClasses: { [key: string]: any } = {}; + testClasses: { [key: string]: unknown } = {}; } export interface Constructor { - new (attributes?: any, options?: any): T; + new (attributes?: unknown, options?: unknown): T; } export function createTestModel( constructor: Constructor, - attributes?: any + attributes?: unknown ): T { const id = widgets.uuid(); const widget_manager = new DummyManager(); diff --git a/{{cookiecutter.github_project_name}}/src/extension.ts b/{{cookiecutter.github_project_name}}/src/extension.ts index 99263fd..ee3b6af 100644 --- a/{{cookiecutter.github_project_name}}/src/extension.ts +++ b/{{cookiecutter.github_project_name}}/src/extension.ts @@ -8,9 +8,10 @@ // Some static assets may be required by the custom widget javascript. The base // url for the notebook is not known at build time and is therefore computed // dynamically. + +const __body = document.querySelector('body'); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -(window as any).__webpack_public_path__ = - document.querySelector('body')!.getAttribute('data-base-url') + - 'nbextensions/{{ cookiecutter.python_package_name }}'; +const __db_url = __body!.getAttribute('data-base-url'); +(window as any).__webpack_public_path__ = __db_url + 'nbextensions/{{ cookiecutter.python_package_name }}'; export * from './index'; diff --git a/{{cookiecutter.github_project_name}}/src/widget.ts b/{{cookiecutter.github_project_name}}/src/widget.ts index a13a818..45369fd 100644 --- a/{{cookiecutter.github_project_name}}/src/widget.ts +++ b/{{cookiecutter.github_project_name}}/src/widget.ts @@ -12,8 +12,19 @@ import { MODULE_NAME, MODULE_VERSION } from './version'; // Import the CSS import '../css/widget.css'; +export interface ModelDefaults { + _model_name: string; + _model_module: string; + _model_module_version: string; + _view_name: string; + _view_module: string; + _view_module_version: string; + value: string; +} + + export class ExampleModel extends DOMWidgetModel { - defaults() { + defaults():ModelDefaults { return { ...super.defaults(), _model_name: ExampleModel.model_name, @@ -40,14 +51,14 @@ export class ExampleModel extends DOMWidgetModel { } export class ExampleView extends DOMWidgetView { - render() { + render():void { this.el.classList.add('custom-widget'); this.value_changed(); this.model.on('change:value', this.value_changed, this); } - value_changed() { + value_changed():void { this.el.textContent = this.model.get('value'); } }