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

Upgrade to Prettier v2 and apply fixes. #1214

Merged
merged 2 commits into from
Nov 5, 2024
Merged
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
20 changes: 12 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"less": "4.1.2",
"less-loader": "10.1.0",
"lodash": "4.17.21",
"prettier": "^1.19.1",
"prettier": "^2.8.8",
"prettier-check": "^2.0.0",
"puppeteer": "^23",
"source-map-loader": "^5.0.0",
Expand Down Expand Up @@ -130,9 +130,12 @@
"jest": {
"preset": "jest-puppeteer",
"transform": {
"^.+\\.tsx?$": ["ts-jest", {
"diagnostics": true
}]
"^.+\\.tsx?$": [
"ts-jest",
{
"diagnostics": true
}
]
},
"testPathIgnorePatterns": [
"/node_modules/"
Expand Down
207 changes: 104 additions & 103 deletions src/BaseContentHandler.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,104 @@
import { IContentHandler } from "./IContentHandler";
import { IUVOptions } from "./UniversalViewer";
import { UVAdapter } from "./UVAdapter";
import { Events } from "./Events";
import { merge } from "./Utils";

export type EventListener = {
name: string;
cb: Function;
ctx?: any;
};

type EventListenerDictionaryItem = Pick<EventListener, "cb" | "ctx">;

export default class BaseContentHandler<IUVData>
implements IContentHandler<IUVData> {
protected _el: HTMLElement;
private _eventListeners: {
[key: string]: EventListenerDictionaryItem[];
};

constructor(
public options: IUVOptions,
public adapter?: UVAdapter,
eventListeners?: EventListener[]
) {
// console.log("create YouTubeContentHandler");
this._el = this.options.target;
// this._assignedContentHandler.adapter = this.adapter; // set adapter

// add event listeners
if (eventListeners) {
eventListeners.forEach(({ name, cb }) => {
this.on(name, cb);
});
}
}

public set(data: IUVData, initial?: boolean): void {}

public on(name: string, cb: Function, ctx?: any): void {
var e = this._eventListeners || (this._eventListeners = {});

(e[name] || (e[name] = [])).push({
cb,
ctx,
});
}

public fire(name: string, ...args: any[]): void {
var data = [].slice.call(arguments, 1);
var evtArr = (
(this._eventListeners || (this._eventListeners = {}))[name] || []
).slice();
var i = 0;
var len = evtArr.length;

for (i; i < len; i++) {
evtArr[i].cb.apply(evtArr[i].ctx, data);
}
}

public showSpinner(): void {
this._el.parentElement?.classList.remove("loaded");
}

public hideSpinner(): void {
this._el.parentElement?.classList.add("loaded");
}

public async configure(config: any): Promise<any> {
let promises: Promise<any>[] = [] as any;

this.fire(Events.CONFIGURE, {
config,
cb: (promise) => {
promises.push(promise);
},
});

if (promises.length) {
const configs = await Promise.all(promises);

const mergedConfigs = configs.reduce((previous, current) => {
return merge(previous, current);
});

config = merge(config, mergedConfigs);
}

return config;
}

public exitFullScreen(): void {}

public resize(): void {}

public dispose(): void {
this._el.innerHTML = "";
this._el.className = "";
this.adapter?.dispose();
}
}
import { IContentHandler } from "./IContentHandler";
import { IUVOptions } from "./UniversalViewer";
import { UVAdapter } from "./UVAdapter";
import { Events } from "./Events";
import { merge } from "./Utils";

export type EventListener = {
name: string;
cb: Function;
ctx?: any;
};

type EventListenerDictionaryItem = Pick<EventListener, "cb" | "ctx">;

export default class BaseContentHandler<IUVData>
implements IContentHandler<IUVData>
{
protected _el: HTMLElement;
private _eventListeners: {
[key: string]: EventListenerDictionaryItem[];
};

constructor(
public options: IUVOptions,
public adapter?: UVAdapter,
eventListeners?: EventListener[]
) {
// console.log("create YouTubeContentHandler");
this._el = this.options.target;
// this._assignedContentHandler.adapter = this.adapter; // set adapter

// add event listeners
if (eventListeners) {
eventListeners.forEach(({ name, cb }) => {
this.on(name, cb);
});
}
}

public set(data: IUVData, initial?: boolean): void {}

public on(name: string, cb: Function, ctx?: any): void {
var e = this._eventListeners || (this._eventListeners = {});

(e[name] || (e[name] = [])).push({
cb,
ctx,
});
}

public fire(name: string, ...args: any[]): void {
var data = [].slice.call(arguments, 1);
var evtArr = (
(this._eventListeners || (this._eventListeners = {}))[name] || []
).slice();
var i = 0;
var len = evtArr.length;

for (i; i < len; i++) {
evtArr[i].cb.apply(evtArr[i].ctx, data);
}
}

public showSpinner(): void {
this._el.parentElement?.classList.remove("loaded");
}

public hideSpinner(): void {
this._el.parentElement?.classList.add("loaded");
}

public async configure(config: any): Promise<any> {
let promises: Promise<any>[] = [] as any;

this.fire(Events.CONFIGURE, {
config,
cb: (promise) => {
promises.push(promise);
},
});

if (promises.length) {
const configs = await Promise.all(promises);

const mergedConfigs = configs.reduce((previous, current) => {
return merge(previous, current);
});

config = merge(config, mergedConfigs);
}

return config;
}

public exitFullScreen(): void {}

public resize(): void {}

public dispose(): void {
this._el.innerHTML = "";
this._el.className = "";
this.adapter?.dispose();
}
}
26 changes: 13 additions & 13 deletions src/Events.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export class Events {
static CONFIGURE: string = "configure";
static CREATED: string = "created";
static DROP: string = "drop";
static ERROR: string = "error";
static EXIT_FULLSCREEN: string = "exitFullScreen";
static EXTERNAL_RESOURCE_OPENED: string = "externalResourceOpened";
static LOAD: string = "load";
static LOAD_FAILED: string = "loadFailed";
static RELOAD: string = "reload";
static RESIZE: string = "resize";
static TOGGLE_FULLSCREEN: string = "toggleFullScreen";
}
export class Events {
static CONFIGURE: string = "configure";
static CREATED: string = "created";
static DROP: string = "drop";
static ERROR: string = "error";
static EXIT_FULLSCREEN: string = "exitFullScreen";
static EXTERNAL_RESOURCE_OPENED: string = "externalResourceOpened";
static LOAD: string = "load";
static LOAD_FAILED: string = "loadFailed";
static RELOAD: string = "reload";
static RESIZE: string = "resize";
static TOGGLE_FULLSCREEN: string = "toggleFullScreen";
}
24 changes: 12 additions & 12 deletions src/IContentHandler.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { UVAdapter } from "./UVAdapter";
export interface IContentHandler<IUVData> {
// adapter.bindTo() sets this.
// when the content handler is disposed, it also disposes the adapter.
adapter?: UVAdapter | undefined;
set(data: IUVData, initial?: boolean): void;
dispose(): void;
on(name: string, callback: Function, ctx?: any): void;
resize(): void;
exitFullScreen(): void;
}
import { UVAdapter } from "./UVAdapter";

export interface IContentHandler<IUVData> {
// adapter.bindTo() sets this.
// when the content handler is disposed, it also disposes the adapter.
adapter?: UVAdapter | undefined;
set(data: IUVData, initial?: boolean): void;
dispose(): void;
on(name: string, callback: Function, ctx?: any): void;
resize(): void;
exitFullScreen(): void;
}
Loading