Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
validide committed May 4, 2020
1 parent 118b769 commit 5dad305
Show file tree
Hide file tree
Showing 69 changed files with 630 additions and 504 deletions.
16 changes: 8 additions & 8 deletions .build/minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ function writeMinifiedFileSync(path, content, encding) {
}


// _glob
// .sync('./dist/bundle/**/*.js', [])
// .forEach(f => {
// console.log(_uglifyJS.minify(_fs.readFileSync(f, 'utf8'), {}))
// writeMinifiedFileSync(f, _uglifyJS.minify(_fs.readFileSync(f, 'utf8'), {
_glob
.sync('./dist/bundle/**/*.js', [])
.forEach(f => {
// console.log(_uglifyJS.minify(_fs.readFileSync(f, 'utf8'), {}))
writeMinifiedFileSync(f, _uglifyJS.minify(_fs.readFileSync(f, 'utf8'), {

// }).code, 'utf8');
// console.log(`Minified "${f}"`);
// });
}).code, 'utf8');
console.log(`Minified "${f}"`);
});
4 changes: 2 additions & 2 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ recursive: true
require:
- ts-node/register # replace with ts-node/register/transpile-only if you have custom types
- source-map-support/register
bail: true
bail: false
color: true
full-trace: true
full-trace: false
reporter: spec
spec: test/**/*.spec.ts
56 changes: 56 additions & 0 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
"rollup": "2.3.3",
"source-map-support": "0.5.16",
"ts-node": "8.8.2",
"tslint": "6.1.2",
"typescript": "3.8.3",
"uglify-js": "3.8.1"
},
"scripts": {
"clean": "node ./.build/clean.js",
"prebuild": "npm run clean",
"build": "tsc --module es2015 && rollup --config ./rollup.config.js && node ./.build/minify.js",
"test": "nyc mocha",
"test": "npm run lint && nyc mocha",
"predocs": "npm run test && npm run build",
"docs": "rollup --config ./rollup.config.js --dir ./docs/demo/lib/bundle/",
"predocs_dev": "npm run build",
"docs_dev": "rollup --config ./rollup.config.js --dir ./docs/demo/lib/bundle/"
"docs_dev": "rollup --config ./rollup.config.js --dir ./docs/demo/lib/bundle/",
"lint": "tslint --config ./tslint.json --project ./tsconfig.json --format stylish"
},
"repository": {
"type": "git",
Expand Down
16 changes: 8 additions & 8 deletions src/core/children/childComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export abstract class ChildComponent extends Component {
* Get the child component options.
*/
protected getOptions(): ChildComponentOptions {
return <ChildComponentOptions>super.getOptions();
return super.getOptions() as ChildComponentOptions;
}

/**
Expand All @@ -64,7 +64,7 @@ export abstract class ChildComponent extends Component {

this.setContentDisposePromise();
// Inform parent the content is beeing disposed.
(<RootComponentFacade>this.rootFacade).signalDisposed(this);
(this.rootFacade as RootComponentFacade).signalDisposed(this);
}

/**
Expand All @@ -77,7 +77,7 @@ export abstract class ChildComponent extends Component {
this.setContentDisposePromise();

// This should trigger the child component dispose.
(<ContainerCommunicationHandler>this.communicationHandler).requestContentDispose();
(this.communicationHandler as ContainerCommunicationHandler).requestContentDispose();
}

/**
Expand All @@ -93,12 +93,12 @@ export abstract class ChildComponent extends Component {
this
.getWindow()
.setTimeout(
() => rejectTimeout(new Error(`Child dispose timeout.`)),
() => rejectTimeout(new Error('Child dispose timeout.')),
this.getOptions().contentDisposeTimeout
);
})
])
.catch((err) => {
.catch(err => {
this.callErrorHandler(err);
});
}
Expand All @@ -110,7 +110,7 @@ export abstract class ChildComponent extends Component {
if (this.contentDisposePromiseResolver === null) {
// For some reason we got the disposed call without getting the 'beginDispose' call.
this.contentDisposePromise = Promise.resolve();
(<RootComponentFacade>this.rootFacade).signalDisposed(this);
(this.rootFacade as RootComponentFacade).signalDisposed(this);
} else {
this.contentDisposePromiseResolver();
}
Expand All @@ -132,9 +132,9 @@ export abstract class ChildComponent extends Component {
*/
protected async disposeCore(): Promise<void> {
this.startDisposingContent();
await (<Promise<void>>this.contentDisposePromise);
await (this.contentDisposePromise as Promise<void>);

(<ContainerCommunicationHandler>this.communicationHandler).dispose();
(this.communicationHandler as ContainerCommunicationHandler).dispose();
this.communicationHandler = null;
this.contentDisposePromiseResolver = null;
this.contentDisposePromise = null;
Expand Down
4 changes: 2 additions & 2 deletions src/core/children/childComponentFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export class ChildComponentFactory {
case ChildComponentType.InWindow:
return new InWindowChildComponent(window, options, rootFacade);
case ChildComponentType.CrossWindow:
return new CrossWindowChildComponent(window, <CrossWindowChildComponentOptions>options, rootFacade);
return new CrossWindowChildComponent(window, options as CrossWindowChildComponentOptions, rootFacade);
default:
throw new Error(`The "${options.type}" is not configured.`)
throw new Error(`The "${options.type}" is not configured.`);
}
}
}
1 change: 1 addition & 0 deletions src/core/children/communications/contentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export abstract class ContentCommunicationHandler {
* Core dispose function.
* Any component derived should override this to add clean-up after itself.
*/
// tslint:disable-next-line: no-empty
protected disposeCore(): void { }

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/children/communications/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CommunicationsEvent {
*/
constructor(kind: CommunicationsEventKind) {
this.kind = kind;
this.uuid = getUuidV4()
this.uuid = getUuidV4();
this.timestamp = new Date().getTime();
this.contentId = '';
}
Expand Down
6 changes: 4 additions & 2 deletions src/core/children/communications/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ export abstract class CommunicationsManager {
/**
* Initialize the manager.
*/
// tslint:disable-next-line: no-empty
protected initializeCore(): void { }

/**
* Clean any resources before the manager is disposed.
*/
// tslint:disable-next-line: no-empty
protected disposeCore(): void { }

/**
Expand Down Expand Up @@ -87,7 +89,7 @@ export abstract class CommunicationsManagerOf<TEndpoint> extends CommunicationsM
this.outboundEndpoint = outboundEndpoint;
this.outboundEventType = outboundEventType;
this.onEventReceived = null;
this.eventHandler = (e: Event) => { this.handleEvent(e); }
this.eventHandler = (e: Event) => { this.handleEvent(e); };
}

/**
Expand All @@ -111,7 +113,7 @@ export abstract class CommunicationsManagerOf<TEndpoint> extends CommunicationsM
if (this.inboundEndpoint && this.eventHandler) {
this.startReceiving(this.inboundEndpoint, this.eventHandler);
}
super.initializeCore()
super.initializeCore();
}

/**
Expand Down
29 changes: 15 additions & 14 deletions src/core/children/crossWindow/childComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export class CrossWindowChildComponent extends ChildComponent {
*/
protected disposeCore(): Promise<void> {
const embed = this.embededId
? (<HTMLElement>this.rootElement).querySelector<HTMLIFrameElement>(`#${this.embededId}`)
? (this.rootElement as HTMLElement).querySelector<HTMLIFrameElement>(`#${this.embededId}`)
: null;
if (embed) {
embed.removeEventListener('load', <() => void>this.embededLoadHandlerRef);
embed.removeEventListener('error', <(e: ErrorEvent) => void>this.embededErrorHandlerRef);
embed.removeEventListener('load', this.embededLoadHandlerRef as () => void);
embed.removeEventListener('error', this.embededErrorHandlerRef as (e: ErrorEvent) => void);

// Do not remove the embeded element now as we still need it to comunicate with the content.
// The parent "rootElement" will be removed latter anyhow.
Expand All @@ -64,7 +64,7 @@ export class CrossWindowChildComponent extends ChildComponent {
* Get the CrossWindowChildComponentOptions
*/
protected getOptions(): CrossWindowChildComponentOptions {
return <CrossWindowChildComponentOptions>super.getOptions();
return super.getOptions() as CrossWindowChildComponentOptions;
}

/**
Expand All @@ -74,7 +74,7 @@ export class CrossWindowChildComponent extends ChildComponent {
const createEmbedElementFn = this.getOptions().createEmbedElement;
let embed: HTMLElement | null = null;
if (createEmbedElementFn) {
embed = createEmbedElementFn(<HTMLElement>this.rootElement);
embed = createEmbedElementFn(this.rootElement as HTMLElement);
} else {
embed = this.createEmbedElement();
}
Expand All @@ -85,12 +85,12 @@ export class CrossWindowChildComponent extends ChildComponent {
embed.id = embedId;
this.embededId = embedId;

embed.addEventListener('load', <() => void>this.embededLoadHandlerRef);
embed.addEventListener('error', <(e: ErrorEvent) => void>this.embededErrorHandlerRef);
embed.addEventListener('load', this.embededLoadHandlerRef as () => void);
embed.addEventListener('error', this.embededErrorHandlerRef as (e: ErrorEvent) => void);

(<HTMLDivElement>this.rootElement).appendChild(embed);
(this.rootElement as HTMLDivElement).appendChild(embed);

await (<Promise<void>>(this.embededLoadPromise));
await ((this.embededLoadPromise) as Promise<void>);

return await super.mountCore();
}
Expand All @@ -102,7 +102,7 @@ export class CrossWindowChildComponent extends ChildComponent {
protected getCommunicationHandlerCore(methods: ContainerCommunicationHandlerMethods): ContainerCommunicationHandler {
const document = this.getDocument();
const manager = new CrossWindowCommunicationsManager(
<Window>(document).defaultView,
(document).defaultView as Window,
CommunicationsEvent.CONTENT_EVENT_TYPE,
this.outboundEndpointAccesor(),
CommunicationsEvent.CONTAINER_EVENT_TYPE,
Expand All @@ -121,15 +121,15 @@ export class CrossWindowChildComponent extends ChildComponent {
* @param e The load event.
*/
private embededLoadHandler(e: Event): void {
(<() => void>this.embededLoadResolver)();
(this.embededLoadResolver as () => void)();
}

/**
* Handle the errir of the embeded element.
* @param e The error event.
*/
private embededErrorHandler(e: ErrorEvent): void {
(<(e: Error) => void>this.embededErrorRejecter)(new Error(`Failed to load embeded element.\nError details:\n${JSON.stringify(e)}`));
(this.embededErrorRejecter as (e: Error) => void)(new Error(`Failed to load embeded element.\nError details:\n${JSON.stringify(e)}`));
}

/**
Expand All @@ -140,9 +140,10 @@ export class CrossWindowChildComponent extends ChildComponent {
const opt = this.getOptions();
if (opt.embededAttributes) {
const keys = Object.keys(opt.embededAttributes);
// tslint:disable-next-line: prefer-for-of
for (let index = 0; index < keys.length; index++) {
const key = keys[index];
embed.setAttribute(key, opt.embededAttributes[key])
embed.setAttribute(key, opt.embededAttributes[key]);
}
}

Expand All @@ -155,7 +156,7 @@ export class CrossWindowChildComponent extends ChildComponent {
*/
private outboundEndpointAccesor(): Window {
const embed = this.embededId
? (<HTMLElement>this.rootElement).querySelector<HTMLIFrameElement>(`#${this.embededId}`)
? (this.rootElement as HTMLElement).querySelector<HTMLIFrameElement>(`#${this.embededId}`)
: null;

if (!embed)
Expand Down
2 changes: 1 addition & 1 deletion src/core/children/crossWindow/childComponentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ChildComponentType } from '../childComponentType';
export class CrossWindowChildComponentOptions extends ChildComponentOptions {
url: string = 'about:blank';
createEmbedElement?: (el: HTMLElement) => HTMLElement;
embededAttributes?: { [key: string]: string; };
embededAttributes?: { [key: string]: string };

/**
* Constructor.
Expand Down
3 changes: 2 additions & 1 deletion src/core/children/crossWindow/contentComunicationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CrossWindowCommunicationsManager } from '../communications/crossWindowM
*/
export class CrossWindowContentCommunicationHandler extends ContentCommunicationHandler {
private iframeId: string;
private messageQueue: Array<CommunicationsEvent>;
private messageQueue: CommunicationsEvent[];

/**
* Constructor.
Expand Down Expand Up @@ -87,6 +87,7 @@ export class CrossWindowContentCommunicationHandler extends ContentCommunication
* Flush all the messages that were enqueues before the handhake.
*/
private flushMessages(): void {
// tslint:disable-next-line: prefer-for-of
for (let index = 0; index < this.messageQueue.length; index++) {
const msg = this.messageQueue[index];
msg.contentId = this.iframeId;
Expand Down
6 changes: 3 additions & 3 deletions src/core/children/inWindow/childComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class InWindowChildComponent extends ChildComponent {
* @inheritdoc
*/
protected getCommunicationHandlerCore(methods: ContainerCommunicationHandlerMethods): ContainerCommunicationHandler {
const endpoint = <HTMLElement>this.rootElement;
const endpoint = this.rootElement as HTMLElement;
const manager = new HTMLElementCommunicationsManager(
endpoint,
CommunicationsEvent.CONTENT_EVENT_TYPE,
Expand All @@ -37,7 +37,7 @@ export class InWindowChildComponent extends ChildComponent {
* Get the InWindowChildComponentOptions
*/
protected getOptions(): InWindowChildComponentOptions {
return <InWindowChildComponentOptions>super.getOptions();
return super.getOptions() as InWindowChildComponentOptions;
}

/**
Expand All @@ -48,7 +48,7 @@ export class InWindowChildComponent extends ChildComponent {
if (!injectionFunction) {
throw new Error('Inject method not defined!');
}
injectionFunction(<HTMLElement>this.rootElement);
injectionFunction(this.rootElement as HTMLElement);
await super.mountCore();
}
}
Loading

0 comments on commit 5dad305

Please sign in to comment.