Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to prevent linting errors at build time #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions {{cookiecutter.github_project_name}}/src/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLElement> {
// 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(
Expand All @@ -87,26 +86,26 @@ export class DummyManager extends baseManager.ManagerBase {
}
}

_get_comm_info() {
_get_comm_info(): Promise<Record<string, unknown>> {
return Promise.resolve({});
}

_create_comm() {
_create_comm(): Promise<MockComm> {
return Promise.resolve(new MockComm());
}

el: HTMLElement;

testClasses: { [key: string]: any } = {};
testClasses: { [key: string]: unknown } = {};
}

export interface Constructor<T> {
new (attributes?: any, options?: any): T;
new (attributes?: unknown, options?: unknown): T;
}

export function createTestModel<T extends widgets.WidgetModel>(
constructor: Constructor<T>,
attributes?: any
attributes?: unknown
): T {
const id = widgets.uuid();
const widget_manager = new DummyManager();
Expand Down
7 changes: 4 additions & 3 deletions {{cookiecutter.github_project_name}}/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
17 changes: 14 additions & 3 deletions {{cookiecutter.github_project_name}}/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
}
}