mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 11:44:09 -05:00
Use Hub and EventHub types in codebase (#3482)
This commit is contained in:
@@ -22,11 +22,12 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import _ from 'underscore';
|
||||
import TomSelect from 'tom-select';
|
||||
|
||||
import { ga } from './analytics';
|
||||
import * as local from './local';
|
||||
import { EventHub } from './event-hub';
|
||||
import { Hub } from './hub';
|
||||
|
||||
type Favourites = {
|
||||
[compilerId: string]: boolean
|
||||
@@ -38,7 +39,7 @@ export class CompilerPicker {
|
||||
static nextSelectorId = 1;
|
||||
domRoot: JQuery;
|
||||
domNode: HTMLSelectElement;
|
||||
eventHub: any /* ReturnType<typeof hub.createEventHub> */;
|
||||
eventHub: EventHub;
|
||||
id: number;
|
||||
compilerService: any;
|
||||
onCompilerChange: (x: string) => any;
|
||||
@@ -46,8 +47,14 @@ export class CompilerPicker {
|
||||
lastLangId: string;
|
||||
lastCompilerId: string;
|
||||
compilerIsVisible: (any) => any; // TODO => bool probably
|
||||
constructor(domRoot: JQuery, hub: any /* Hub */, langId: string, compilerId: string,
|
||||
onCompilerChange: (x: string) => any, compilerIsVisible?: (x: any) => any) {
|
||||
constructor(
|
||||
domRoot: JQuery,
|
||||
hub: Hub,
|
||||
langId: string,
|
||||
compilerId: string,
|
||||
onCompilerChange: (x: string) => any,
|
||||
compilerIsVisible?: (x: any) => any
|
||||
) {
|
||||
this.eventHub = hub.createEventHub();
|
||||
this.id = CompilerPicker.nextSelectorId++;
|
||||
const compilerPicker = domRoot.find('.compiler-picker')[0];
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
import GoldenLayout from 'golden-layout';
|
||||
import Sentry from '@sentry/browser';
|
||||
|
||||
import { Hub } from './hub';
|
||||
|
||||
export type EventHubCallback<T extends unknown[]> = (...args: T) => void;
|
||||
|
||||
export interface DependencyProxies<T1 extends unknown[], T2 extends unknown[] = T1> {
|
||||
@@ -35,7 +37,7 @@ export interface DependencyProxies<T1 extends unknown[], T2 extends unknown[] =
|
||||
export interface Event<T extends unknown[], C = any> {
|
||||
evt: string;
|
||||
fn: EventHubCallback<T>;
|
||||
ctx: C;
|
||||
ctx?: C;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +45,7 @@ export interface Event<T extends unknown[], C = any> {
|
||||
* deferred execution based on the parent Hub.
|
||||
*/
|
||||
export class EventHub {
|
||||
private readonly hub: any; /* typeof Hub */
|
||||
private readonly hub: Hub;
|
||||
private readonly layoutEventHub: GoldenLayout.EventEmitter;
|
||||
private subscriptions: Event<any>[] = [];
|
||||
|
||||
@@ -68,7 +70,7 @@ export class EventHub {
|
||||
}
|
||||
|
||||
/** Attach a listener to the layout event hub. */
|
||||
public on<T extends unknown[], C = any>(event: string, callback: EventHubCallback<T>, context: C): void {
|
||||
public on<T extends unknown[], C = any>(event: string, callback: EventHubCallback<T>, context?: C): void {
|
||||
this.layoutEventHub.on(event, callback, context);
|
||||
this.subscriptions.push({ evt: event, fn: callback, ctx: context });
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class Hub {
|
||||
public readonly compilerService: any; // typeof CompilerService
|
||||
|
||||
public deferred = true;
|
||||
public deferredEmissions: string[][] = [];
|
||||
public deferredEmissions: unknown[][] = [];
|
||||
|
||||
public lastOpenedLangId: string | null;
|
||||
public subdomainLangId: string | undefined;
|
||||
@@ -149,8 +149,8 @@ export class Hub {
|
||||
public undefer(): void {
|
||||
this.deferred = false;
|
||||
const eventHub = this.layout.eventHub;
|
||||
const compilerEmissions: string[][] = [];
|
||||
const nonCompilerEmissions: string[][] = [];
|
||||
const compilerEmissions: unknown[][] = [];
|
||||
const nonCompilerEmissions: unknown[][] = [];
|
||||
|
||||
for (const [eventName, ...args] of this.deferredEmissions) {
|
||||
if (eventName === 'compiler') {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
import _ from 'underscore';
|
||||
import path from 'path';
|
||||
import JSZip from 'jszip';
|
||||
import { Hub } from './hub';
|
||||
const options = require('./options').options;
|
||||
const languages = options.languages;
|
||||
|
||||
@@ -55,7 +56,7 @@ export class MultifileService {
|
||||
private files: Array<MultifileFile>;
|
||||
private compilerLanguageId: string;
|
||||
private isCMakeProject: boolean;
|
||||
private hub: any;
|
||||
private hub: Hub;
|
||||
private newFileId: number;
|
||||
private alertSystem: any;
|
||||
private validExtraFilenameExtensions: string[];
|
||||
@@ -64,7 +65,7 @@ export class MultifileService {
|
||||
private readonly cmakeMainSourceFilename: string;
|
||||
private readonly maxFilesize: number;
|
||||
|
||||
constructor(hub, alertSystem, state: MultifileServiceState) {
|
||||
constructor(hub: Hub, alertSystem, state: MultifileServiceState) {
|
||||
this.hub = hub;
|
||||
this.alertSystem = alertSystem;
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import * as colour from '../colour';
|
||||
import * as monacoConfig from '../monaco-config';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
type DecorationEntry = {
|
||||
linkedCode: any[];
|
||||
@@ -58,7 +59,7 @@ export class Ast extends MonacoPane<monaco.editor.IStandaloneCodeEditor, AstStat
|
||||
astCode: AstCodeEntry[] = [];
|
||||
linkedFadeTimeoutId?: NodeJS.Timeout = undefined;
|
||||
|
||||
constructor(hub: any, container: Container, state: AstState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: AstState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
|
||||
if (state && state.astOutput) {
|
||||
|
||||
@@ -30,6 +30,7 @@ import TomSelect from 'tom-select';
|
||||
import { Container } from 'golden-layout';
|
||||
import { CfgState } from './cfg-view.interfaces';
|
||||
import { PaneRenaming } from '../widgets/pane-renaming';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
interface NodeInfo {
|
||||
edges: string[],
|
||||
@@ -71,7 +72,7 @@ export class Cfg {
|
||||
paneName: string;
|
||||
paneRenaming: PaneRenaming;
|
||||
|
||||
constructor(hub: any, container: Container, state: CfgState) {
|
||||
constructor(hub: Hub, container: Container, state: CfgState) {
|
||||
this.container = container;
|
||||
this.eventHub = hub.createEventHub();
|
||||
this.domRoot = container.getElement();
|
||||
|
||||
@@ -32,9 +32,10 @@ import { MonacoPaneState } from './pane.interfaces';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { extendConfig } from '../monaco-config';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class GnatDebug extends MonacoPane<monaco.editor.IStandaloneCodeEditor, GnatDebugState> {
|
||||
constructor(hub: any, container: Container, state: GnatDebugState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: GnatDebugState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.gnatDebugOutput) {
|
||||
this.showGnatDebugResults(state.gnatDebugOutput);
|
||||
|
||||
@@ -32,9 +32,10 @@ import { MonacoPaneState } from './pane.interfaces';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { extendConfig } from '../monaco-config';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class GnatDebugTree extends MonacoPane<monaco.editor.IStandaloneCodeEditor, GnatDebugTreeState> {
|
||||
constructor(hub: any, container: Container, state: GnatDebugTreeState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: GnatDebugTreeState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.gnatDebugTreeOutput) {
|
||||
this.showGnatDebugTreeResults(state.gnatDebugTreeOutput);
|
||||
|
||||
@@ -35,6 +35,7 @@ import { extendConfig } from '../monaco-config';
|
||||
import { applyColours } from '../colour';
|
||||
|
||||
import { PaneRenaming } from '../widgets/pane-renaming';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class Ir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState> {
|
||||
linkedFadeTimeoutId = -1;
|
||||
@@ -43,7 +44,7 @@ export class Ir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState>
|
||||
decorations: any = {};
|
||||
previousDecorations: string[] = [];
|
||||
|
||||
constructor(hub: any, container: Container, state: IrState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: IrState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.irOutput) {
|
||||
this.showIrResults(state.irOutput);
|
||||
|
||||
@@ -32,6 +32,7 @@ import { MonacoPaneState } from './pane.interfaces';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { extendConfig } from '../monaco-config';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
type SourceLocation = {
|
||||
File: string;
|
||||
@@ -55,7 +56,7 @@ export class Opt extends MonacoPane<monaco.editor.IStandaloneCodeEditor, OptStat
|
||||
// Note: bool | undef here instead of just bool because of an issue with field initialization order
|
||||
isCompilerSupported?: boolean;
|
||||
|
||||
constructor(hub: any, container: Container, state: OptState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: OptState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.optOutput) {
|
||||
this.showOptResults(state.optOutput);
|
||||
|
||||
@@ -33,6 +33,8 @@ import { SiteSettings } from '../settings';
|
||||
import * as utils from '../utils';
|
||||
|
||||
import { PaneRenaming } from '../widgets/pane-renaming';
|
||||
import { EventHub } from '../event-hub';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
|
||||
class PaneCompilerState {
|
||||
@@ -53,7 +55,7 @@ export abstract class Pane<S> {
|
||||
domRoot: JQuery;
|
||||
topBar: JQuery;
|
||||
hideable: JQuery;
|
||||
eventHub: any /* typeof hub.createEventHub() */;
|
||||
eventHub: EventHub;
|
||||
isAwaitingInitialResults = false;
|
||||
settings: SiteSettings | Record<string, never> = {};
|
||||
paneName: string;
|
||||
@@ -65,7 +67,7 @@ export abstract class Pane<S> {
|
||||
*
|
||||
* Overridable for implementors
|
||||
*/
|
||||
protected constructor(hub: any /* Hub */, container: Container, state: S & PaneState) {
|
||||
protected constructor(hub: Hub, container: Container, state: S & PaneState) {
|
||||
this.container = container;
|
||||
this.eventHub = hub.createEventHub();
|
||||
this.domRoot = container.getElement();
|
||||
|
||||
@@ -34,11 +34,12 @@ import * as monacoConfig from '../monaco-config';
|
||||
import { PPViewState } from './pp-view.interfaces';
|
||||
import { Container } from 'golden-layout';
|
||||
import { MonacoPaneState } from './pane.interfaces';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class PP extends MonacoPane<monaco.editor.IStandaloneCodeEditor, PPViewState> {
|
||||
options: any;
|
||||
|
||||
constructor(hub: any, container: Container, state: PPViewState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: PPViewState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
this.eventHub.emit('ppViewOpened', this.compilerInfo.compilerId);
|
||||
this.eventHub.emit('requestSettings');
|
||||
|
||||
@@ -32,9 +32,10 @@ import { RustHirState } from './rusthir-view.interfaces';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { extendConfig } from '../monaco-config';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class RustHir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, RustHirState> {
|
||||
constructor(hub: any, container: Container, state: RustHirState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: RustHirState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.rustHirOutput) {
|
||||
this.showRustHirResults(state.rustHirOutput);
|
||||
|
||||
@@ -32,9 +32,10 @@ import { RustMacroExpState } from './rustmacroexp-view.interfaces';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { extendConfig } from '../monaco-config';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class RustMacroExp extends MonacoPane<monaco.editor.IStandaloneCodeEditor, RustMacroExpState> {
|
||||
constructor(hub: any, container: Container, state: RustMacroExpState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: RustMacroExpState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.rustMacroExpOutput) {
|
||||
this.showRustMacroExpResults(state.rustMacroExpOutput);
|
||||
|
||||
@@ -32,9 +32,10 @@ import { RustMirState } from './rustmir-view.interfaces';
|
||||
|
||||
import { ga } from '../analytics';
|
||||
import { extendConfig } from '../monaco-config';
|
||||
import { Hub } from '../hub';
|
||||
|
||||
export class RustMir extends MonacoPane<monaco.editor.IStandaloneCodeEditor, RustMirState> {
|
||||
constructor(hub: any, container: Container, state: RustMirState & MonacoPaneState) {
|
||||
constructor(hub: Hub, container: Container, state: RustMirState & MonacoPaneState) {
|
||||
super(hub, container, state);
|
||||
if (state && state.rustMirOutput) {
|
||||
this.showRustMirResults(state.rustMirOutput);
|
||||
|
||||
@@ -27,6 +27,8 @@ import {LineColouring} from '../line-colouring';
|
||||
import * as utils from '../utils';
|
||||
import { Settings } from '../settings';
|
||||
import { PaneRenaming } from '../widgets/pane-renaming';
|
||||
import { Hub } from '../hub';
|
||||
import { EventHub } from '../event-hub';
|
||||
|
||||
const _ = require('underscore');
|
||||
const $ = require('jquery');
|
||||
@@ -49,8 +51,8 @@ export class Tree {
|
||||
public readonly id: number;
|
||||
private container: any;
|
||||
private domRoot: any;
|
||||
private readonly hub: any;
|
||||
private eventHub: any;
|
||||
private readonly hub: Hub;
|
||||
private eventHub: EventHub;
|
||||
private readonly settings: any;
|
||||
private httpRoot: any;
|
||||
private readonly alertSystem: any;
|
||||
@@ -76,7 +78,7 @@ export class Tree {
|
||||
private paneRenaming: PaneRenaming;
|
||||
|
||||
// TODO(supergrecko): swap argument order of state and container
|
||||
constructor(hub, state: TreeState, container) {
|
||||
constructor(hub: Hub, state: TreeState, container) {
|
||||
this.id = state.id || hub.nextTreeId();
|
||||
this.container = container;
|
||||
this.domRoot = container.getElement();
|
||||
|
||||
Reference in New Issue
Block a user