Fix a number of calls to on() for strictFunctions

WIth strictFunctions, the callback can no longer use implicit casts to a subclass for parameter types. This pattern was widely used with `.on` event callbacks in the dom
This commit is contained in:
Matt Bierner 2017-11-06 10:26:11 -08:00
parent e5b4bdce2e
commit 6bcfefedb3
7 changed files with 28 additions and 27 deletions

View file

@ -118,17 +118,18 @@ export class BaseActionItem extends EventEmitter implements IActionItem {
this.builder.on(EventType.Tap, e => this.onClick(e));
this.builder.on(DOM.EventType.MOUSE_DOWN, (e: MouseEvent) => {
this.builder.on(DOM.EventType.MOUSE_DOWN, (e) => {
if (!enableDragging) {
DOM.EventHelper.stop(e, true); // do not run when dragging is on because that would disable it
}
if (this._action.enabled && e.button === 0) {
const mouseEvent = e as MouseEvent;
if (this._action.enabled && mouseEvent.button === 0) {
this.builder.addClass('active');
}
});
this.builder.on(DOM.EventType.CLICK, (e: MouseEvent) => {
this.builder.on(DOM.EventType.CLICK, (e) => {
DOM.EventHelper.stop(e, true);
// See https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard
// > Writing to the clipboard
@ -145,7 +146,7 @@ export class BaseActionItem extends EventEmitter implements IActionItem {
}
});
this.builder.on([DOM.EventType.MOUSE_UP, DOM.EventType.MOUSE_OUT], (e: MouseEvent) => {
this.builder.on([DOM.EventType.MOUSE_UP, DOM.EventType.MOUSE_OUT], (e) => {
DOM.EventHelper.stop(e);
this.builder.removeClass('active');
});
@ -447,8 +448,8 @@ export class ActionBar extends EventEmitter implements IActionRunner {
break;
}
$(this.domNode).on(DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
$(this.domNode).on(DOM.EventType.KEY_DOWN, (e) => {
let event = new StandardKeyboardEvent(e as KeyboardEvent);
let eventHandled = true;
if (event.equals(previousKey)) {
@ -469,8 +470,8 @@ export class ActionBar extends EventEmitter implements IActionRunner {
}
});
$(this.domNode).on(DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
$(this.domNode).on(DOM.EventType.KEY_UP, (e) => {
let event = new StandardKeyboardEvent(e as KeyboardEvent);
// Run action on Enter/Space
if (event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {

View file

@ -67,8 +67,8 @@ export class Button extends EventEmitter {
this.emit(DOM.EventType.CLICK, e);
});
this.$el.on(DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
this.$el.on(DOM.EventType.KEY_DOWN, (e) => {
let event = new StandardKeyboardEvent(e as KeyboardEvent);
let eventHandled = false;
if (this.enabled && event.equals(KeyCode.Enter) || event.equals(KeyCode.Space)) {
this.emit(DOM.EventType.CLICK, e);
@ -83,7 +83,7 @@ export class Button extends EventEmitter {
}
});
this.$el.on(DOM.EventType.MOUSE_OVER, (e: MouseEvent) => {
this.$el.on(DOM.EventType.MOUSE_OVER, (e) => {
if (!this.$el.hasClass('disabled')) {
const hoverBackground = this.buttonHoverBackground ? this.buttonHoverBackground.toString() : null;
if (hoverBackground) {
@ -92,7 +92,7 @@ export class Button extends EventEmitter {
}
});
this.$el.on(DOM.EventType.MOUSE_OUT, (e: MouseEvent) => {
this.$el.on(DOM.EventType.MOUSE_OUT, (e) => {
this.applyStyles(); // restore standard styles
});

View file

@ -69,9 +69,9 @@ export class Sash extends EventEmitter {
this.gesture = new Gesture(this.$e.getHTMLElement());
this.$e.on(DOM.EventType.MOUSE_DOWN, (e: MouseEvent) => { this.onMouseDown(e); });
this.$e.on(DOM.EventType.DBLCLICK, (e: MouseEvent) => { this.emit('reset', e); });
this.$e.on(EventType.Start, (e: GestureEvent) => { this.onTouchStart(e); });
this.$e.on(DOM.EventType.MOUSE_DOWN, (e) => { this.onMouseDown(e as MouseEvent); });
this.$e.on(DOM.EventType.DBLCLICK, (e) => { this.emit('reset', e as MouseEvent); });
this.$e.on(EventType.Start, (e) => { this.onTouchStart(e as GestureEvent); });
this.size = options.baseSize || 5;
@ -144,9 +144,9 @@ export class Sash extends EventEmitter {
let lastCurrentX = startX;
let lastCurrentY = startY;
$window.on('mousemove', (e: MouseEvent) => {
$window.on('mousemove', (e) => {
DOM.EventHelper.stop(e, false);
let mouseMoveEvent = new StandardMouseEvent(e);
let mouseMoveEvent = new StandardMouseEvent(e as MouseEvent);
let event: ISashEvent = {
startX: startX,
@ -159,7 +159,7 @@ export class Sash extends EventEmitter {
lastCurrentY = mouseMoveEvent.posy;
this.emit('change', event);
}).once('mouseup', (e: MouseEvent) => {
}).once('mouseup', (e) => {
DOM.EventHelper.stop(e, false);
this.$e.removeClass('active');
this.emit('end');

View file

@ -493,7 +493,7 @@ function isRelativePattern(obj: any): obj is IRelativePattern {
*/
export function parseToAsync(expression: IExpression, options?: IGlobOptions): ParsedExpression {
const parsedExpression = parse(expression, options);
return (path: string, basename?: string, siblingsFn?: () => TPromise<string[]>): TPromise<string> => {
return (path: string, basename?: string, siblingsFn?: () => string[] | TPromise<string[]>): string | TPromise<string> => {
const result = parsedExpression(path, basename, siblingsFn);
return result instanceof TPromise ? result : TPromise.as(result);
};

View file

@ -786,7 +786,7 @@ export function getLocation(text: string, position: number): Location {
path: segments,
previousNode,
isAtPropertyKey,
matches: (pattern: string[]) => {
matches: (pattern: JSONPath) => {
let k = 0;
for (let i = 0; k < pattern.length && i < segments.length; i++) {
if (pattern[k] === segments[i] || pattern[k] === '*') {

View file

@ -151,8 +151,8 @@ export class QuickOpenWidget implements IModelProvider {
this.builder = $().div((div: Builder) => {
// Eventing
div.on(DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e);
div.on(DOM.EventType.KEY_DOWN, (e) => {
const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e as KeyboardEvent);
if (keyboardEvent.keyCode === KeyCode.Escape) {
DOM.EventHelper.stop(e, true);
@ -261,8 +261,8 @@ export class QuickOpenWidget implements IModelProvider {
}
}));
}).
on(DOM.EventType.KEY_DOWN, (e: KeyboardEvent) => {
const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e);
on(DOM.EventType.KEY_DOWN, (e) => {
const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e as KeyboardEvent);
// Only handle when in quick navigation mode
if (!this.quickNavigateConfiguration) {
@ -276,8 +276,8 @@ export class QuickOpenWidget implements IModelProvider {
this.navigateInTree(keyboardEvent.keyCode);
}
}).
on(DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e);
on(DOM.EventType.KEY_UP, (e) => {
const keyboardEvent: StandardKeyboardEvent = new StandardKeyboardEvent(e as KeyboardEvent);
const keyCode = keyboardEvent.keyCode;
// Only handle when in quick navigation mode

View file

@ -80,7 +80,7 @@ export class ContextMenuHandler {
}
if (container) {
this.$el = $(container);
this.$el.on('mousedown', (e: MouseEvent) => this.onMouseDown(e));
this.$el.on('mousedown', (e: Event) => this.onMouseDown(e as MouseEvent));
}
}