Skip to content

Commit

Permalink
fix eslint errors reported
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektas committed Jan 7, 2020
1 parent 91175f3 commit 5221e4d
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 155 deletions.
16 changes: 7 additions & 9 deletions packages/base/src/manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const PROTOCOL_MAJOR_VERSION = PROTOCOL_VERSION.split('.', 1)[0];
* Either a comm or a model_id must be provided.
*/
export
// tslint:disable-next-line:interface-name
interface ModelOptions {
interface IModelOptions {
/**
* Target name of the widget model to create.
*/
Expand Down Expand Up @@ -78,8 +77,7 @@ interface ModelOptions {
* Either a comm or a model_id must be provided.
*/
export
// tslint:disable-next-line:interface-name
interface WidgetOptions {
interface IWidgetOptions {
/**
* Target name of the widget model to create.
*/
Expand Down Expand Up @@ -240,7 +238,7 @@ abstract class ManagerBase<T> {
* required and additional options are available.
* @param serialized_state - serialized model attributes.
*/
new_widget(options: WidgetOptions, serialized_state: any = {}): Promise<WidgetModel> {
new_widget(options: IWidgetOptions, serialized_state: any = {}): Promise<WidgetModel> {
let commPromise;
// we check to make sure the view information is provided, to help catch
// backwards incompatibility errors.
Expand Down Expand Up @@ -316,7 +314,7 @@ abstract class ManagerBase<T> {
* (err) => {console.error(err)});
*
*/
async new_model(options: ModelOptions, serialized_state: any = {}): Promise<WidgetModel> {
async new_model(options: IModelOptions, serialized_state: any = {}): Promise<WidgetModel> {
let model_id;
if (options.model_id) {
model_id = options.model_id;
Expand All @@ -332,7 +330,7 @@ abstract class ManagerBase<T> {
return await modelPromise;
}

async _make_model(options: ModelOptions, serialized_state: any = {}): Promise<WidgetModel> {
async _make_model(options: IModelOptions, serialized_state: any = {}): Promise<WidgetModel> {
const model_id = options.model_id;
const model_promise = this.loadClass(
options.model_name,
Expand Down Expand Up @@ -443,13 +441,13 @@ abstract class ManagerBase<T> {
});
}

const modelCreate: ModelOptions = {
const modelCreate: IModelOptions = {
model_id: model_id,
model_name: model.model_name,
model_module: model.model_module,
model_module_version: model.model_module_version
};
if (live_comms.hasOwnProperty(model_id)) { // live comm
if (Object.prototype.hasOwnProperty.call(live_comms, 'model_id')) { // live comm
// This connects to an existing comm if it exists, and
// should *not* send a comm open message.
return this._create_comm(this.comm_target_name, model_id).then(comm => {
Expand Down
8 changes: 4 additions & 4 deletions packages/base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ function isEqual(a: any, b: any) {
* This is from code that Typescript 2.4 generates for a polyfill.
*/
export
const assign = (Object as any).assign || function(t: any) {
for (let i = 1; i < arguments.length; i++) {
const s = arguments[i];
const assign = (Object as any).assign || function(t: any, ...args: any[]) {
for (let i = 1; i < args.length; i++) {
const s = args[i];
for (const p in s) {
if (Object.prototype.hasOwnProperty.call(s, p)) {
t[p] = s[p];
Expand Down Expand Up @@ -199,7 +199,7 @@ function remove_buffers(state: any): {state: any; buffers: ArrayBuffer[]; buffer
} else if (isPlainObject(obj)) {
for (const key in obj) {
let is_cloned = false;
if (obj.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
const value = obj[key];
if (value) {
if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
Expand Down
15 changes: 6 additions & 9 deletions packages/base/src/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ class WidgetModel extends Backbone.Model {
_handle_comm_msg(msg: KernelMessage.ICommMsgMsg): Promise<void> {
const data = msg.content.data as any;
const method = data.method;
// tslint:disable-next-line:switch-default
switch (method) {
case 'update':
this.state_change = this.state_change
Expand Down Expand Up @@ -504,10 +503,9 @@ class WidgetModel extends Backbone.Model {
* while the first will call foo only once.
*/
on_some_change(keys: string[], callback: (...args: any[]) => void, context: any) {
const scope = this;
this.on('change', function () {
if (keys.some(scope.hasChanged, scope)) {
callback.apply(context, arguments);
this.on('change', (...args) => {
if (keys.some(this.hasChanged, this)) {
callback.apply(context, args);
}
}, this);
}
Expand Down Expand Up @@ -601,7 +599,7 @@ class WidgetView extends NativeView<WidgetModel> {
/**
* Initializer, called at the end of the constructor.
*/
initialize(parameters: WidgetView.InitializeParameters) {
initialize(parameters: WidgetView.IInitializeParameters) {
this.listenTo(this.model, 'change', () => {
const changed = Object.keys(this.model.changedAttributes() || {});
if (changed[0] === '_view_count' && changed.length === 1) {
Expand Down Expand Up @@ -693,7 +691,7 @@ class WidgetView extends NativeView<WidgetModel> {
}

export namespace WidgetView {
export interface InitializeParameters<T extends WidgetModel = WidgetModel> extends Backbone.ViewOptions<T> {
export interface IInitializeParameters<T extends WidgetModel = WidgetModel> extends Backbone.ViewOptions<T> {
options: any;
}
}
Expand Down Expand Up @@ -789,7 +787,7 @@ class DOMWidgetView extends WidgetView {
/**
* Public constructor
*/
initialize(parameters: WidgetView.InitializeParameters) {
initialize(parameters: WidgetView.IInitializeParameters) {
super.initialize(parameters);

this.listenTo(this.model, 'change:_dom_classes', (model: WidgetModel, new_classes: string[]) => {
Expand Down Expand Up @@ -950,7 +948,6 @@ class DOMWidgetView extends WidgetView {
}

processPhosphorMessage(msg: Message) {
// tslint:disable-next-line:switch-default
switch (msg.type) {
case 'after-attach':
this.trigger('displayed');
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/widget_layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LayoutView extends WidgetView {
/**
* Public constructor
*/
initialize(parameters: WidgetView.InitializeParameters) {
initialize(parameters: WidgetView.IInitializeParameters) {
this._traitNames = [];
super.initialize(parameters);
// Register the traits that live on the Python side
Expand Down
2 changes: 1 addition & 1 deletion packages/base/src/widget_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class StyleView extends WidgetView {
/**
* Public constructor
*/
initialize(parameters: WidgetView.InitializeParameters) {
initialize(parameters: WidgetView.IInitializeParameters) {
this._traitNames = [];
super.initialize(parameters);
// Register the traits that live on the Python side
Expand Down
94 changes: 46 additions & 48 deletions packages/base/test/src/dummy-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,54 +54,6 @@ class MockComm implements widgets.IClassicComm {
_on_close: Function = null;
}

export
class DummyManager extends widgets.ManagerBase<HTMLElement> {
constructor() {
super();
this.el = window.document.createElement('div');
}

display_view(msg: services.KernelMessage.IMessage, view: Backbone.View<Backbone.Model>, options: any) {
// 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;
});
}

protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise<any> {
if (moduleName === '@jupyter-widgets/base') {
if ((widgets as any)[className]) {
return Promise.resolve((widgets as any)[className]);
} else {
return Promise.reject(`Cannot find class ${className}`);
}
} else if (moduleName === 'test-widgets') {
if ((testWidgets as any)[className]) {
return Promise.resolve((testWidgets as any)[className]);
} else {
return Promise.reject(`Cannot find class ${className}`);
}
} else {
return Promise.reject(`Cannot find module ${moduleName}`);
}
}

_get_comm_info() {
return Promise.resolve({});
}

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

el: HTMLElement;
}

// Dummy widget with custom serializer and binary field

const typesToArray: {[key: string]: any} = {
int8: Int8Array,
int16: Int16Array,
Expand Down Expand Up @@ -178,3 +130,49 @@ class BinaryWidgetView extends TestWidgetView {
}

const testWidgets = {TestWidget, TestWidgetView, BinaryWidget, BinaryWidgetView};

export
class DummyManager extends widgets.ManagerBase<HTMLElement> {
constructor() {
super();
this.el = window.document.createElement('div');
}

display_view(msg: services.KernelMessage.IMessage, view: Backbone.View<Backbone.Model>, options: any) {
// 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;
});
}

protected loadClass(className: string, moduleName: string, moduleVersion: string): Promise<any> {
if (moduleName === '@jupyter-widgets/base') {
if ((widgets as any)[className]) {
return Promise.resolve((widgets as any)[className]);
} else {
return Promise.reject(`Cannot find class ${className}`);
}
} else if (moduleName === 'test-widgets') {
if ((testWidgets as any)[className]) {
return Promise.resolve((testWidgets as any)[className]);
} else {
return Promise.reject(`Cannot find class ${className}`);
}
} else {
return Promise.reject(`Cannot find module ${moduleName}`);
}
}

_get_comm_info() {
return Promise.resolve({});
}

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

el: HTMLElement;
}
10 changes: 5 additions & 5 deletions packages/controls/src/typedoc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* TODO: remove the below typings after typedoc understands the lib compiler option
* and the @types typing resolution.
*/
/// <reference types="mathjax"/>
/// <reference types="requirejs"/>
/// <reference path="../node_modules/typescript/lib/lib.es2015.promise.d.ts"/>
/// <reference path="../node_modules/typescript/lib/lib.dom.d.ts"/>
/// <reference path="../node_modules/typescript/lib/lib.es5.d.ts"/>
import "mathjax";
import "requirejs";
import "../node_modules/typescript/lib/lib.es2015.promise.d.ts";
import "../node_modules/typescript/lib/lib.dom.d.ts";
import "../node_modules/typescript/lib/lib.es5.d.ts";
3 changes: 1 addition & 2 deletions packages/controls/src/widget_color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {

import * as _ from 'underscore';

const named_colors: {[key: string]: string} = { aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc', bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00', chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff', darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9', darkgrey: '#a9a9a9', darkgreen: '#006400', darkkhaki: '#bdb76b', darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000', darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f', darkslategrey: '#2f4f4f', darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493', deepskyblue: '#00bfff', dimgray : '#696969', dimgrey : '#696969', dodgerblue: '#1e90ff', firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff', gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080', grey: '#808080', green: '#008000', greenyellow: '#adff2f', honeydew: '#f0fff0', hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa', lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff', lightgoldenrodyellow: '#fafad2', lightgreen: '#90ee90', lightgray: '#d3d3d3', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a', lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899', lightsteelblue: '#b0c4de', lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000', mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee', mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585', midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23', orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98', paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9', peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd', powderblue: '#b0e0e6', purple: '#800080', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1', saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d', silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090', slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f', steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee', wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32', };

export
class ColorPickerModel extends CoreDescriptionModel {
Expand Down Expand Up @@ -126,8 +127,6 @@ class ColorPickerView extends DescriptionView {
private _colorpicker: HTMLInputElement;
}

const named_colors: {[key: string]: string} = { aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff', beige: '#f5f5dc', bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff', blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00', chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c', cyan: '#00ffff', darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9', darkgrey: '#a9a9a9', darkgreen: '#006400', darkkhaki: '#bdb76b', darkmagenta: '#8b008b', darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000', darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f', darkslategrey: '#2f4f4f', darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493', deepskyblue: '#00bfff', dimgray : '#696969', dimgrey : '#696969', dodgerblue: '#1e90ff', firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff', gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080', grey: '#808080', green: '#008000', greenyellow: '#adff2f', honeydew: '#f0fff0', hotpink: '#ff69b4', indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa', lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6', lightcoral: '#f08080', lightcyan: '#e0ffff', lightgoldenrodyellow: '#fafad2', lightgreen: '#90ee90', lightgray: '#d3d3d3', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a', lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899', lightsteelblue: '#b0c4de', lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6', magenta: '#ff00ff', maroon: '#800000', mediumaquamarine: '#66cdaa', mediumblue: '#0000cd', mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee', mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585', midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5', navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23', orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98', paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9', peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd', powderblue: '#b0e0e6', purple: '#800080', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1', saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee', sienna: '#a0522d', silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090', slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f', steelblue: '#4682b4', tan: '#d2b48c', teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee', wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32', };

/*
* From a valid html color (named color, 6-digits or 3-digits hex format)
* return a 6-digits hexadecimal color #rrggbb.
Expand Down
18 changes: 8 additions & 10 deletions packages/controls/src/widget_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,10 @@ class ControllerModel extends CoreDOMWidgetModel {
const index = this.get('index');
const pad = navigator.getGamepads()[index];
if (pad) {
const that = this;
this.setup(pad).then(function(controls) {
that.set(controls);
that.save_changes();
window.requestAnimationFrame(that.update_loop.bind(that));
this.setup(pad).then((controls) => {
this.set(controls);
this.save_changes();
window.requestAnimationFrame(this.update_loop.bind(this));
});
} else {
window.requestAnimationFrame(this.wait_loop.bind(this));
Expand All @@ -217,13 +216,12 @@ class ControllerModel extends CoreDOMWidgetModel {
timestamp: pad.timestamp
});
// Create buttons and axes. When done, start the update loop
const that = this;
return utils.resolvePromisesDict({
buttons: Promise.all(pad.buttons.map(function(btn, index) {
return that._create_button_model(index);
buttons: Promise.all(pad.buttons.map((btn, index) => {
return this._create_button_model(index);
})),
axes: Promise.all(pad.axes.map(function(axis, index) {
return that._create_axis_model(index);
axes: Promise.all(pad.axes.map((axis, index) => {
return this._create_axis_model(index);
})),
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/controls/src/widget_date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function serialize_date(value: Date) {
}
}

export interface SerializedDate {
export interface ISerializedDate {
/**
* Full year
*/
Expand All @@ -46,7 +46,7 @@ export interface SerializedDate {
}

export
function deserialize_date(value: SerializedDate) {
function deserialize_date(value: ISerializedDate) {
if (value === null) {
return null;
} else {
Expand Down
Loading

0 comments on commit 5221e4d

Please sign in to comment.