This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"extends": "./tsconfig.json", | |
"compilerOptions": { | |
"outDir": "./out-tsc/worker", | |
"lib": [ | |
"es2018", | |
"webworker" | |
], | |
"types": [] | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference lib="webworker" /> | |
addEventListener('message', ({ data }) => { | |
const response = `worker response to ${data}`; | |
postMessage(response); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
// ... | |
}) | |
export class CalculationComponent implements OnDestroy { | |
// ... | |
ngOnDestroy(): void { | |
this.terminateRunningWorker(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
// ... | |
}) | |
export class CalculationComponent { | |
// ... | |
private currentWorker: Worker; | |
public modelChange(newValue: number): void { | |
const start = performance.now(); | |
this.value = newValue; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
// ... | |
}) | |
export class CalculationComponent { | |
public value: number; | |
public result: string | null; | |
public isCalculating: boolean = false; | |
public modelChange(newValue: number): void { | |
const start = performance.now(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<input | |
placeholder="Type a number" | |
type="number" | |
[ngModel]="value" | |
(ngModelChange)="modelChange($event)" | |
/> | |
<small *ngIf="isCalculating">Calculating...</small> | |
<div *ngIf="result != null"> | |
{{ result }}... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference lib="webworker" /> | |
import { calculate } from "./calculation"; | |
addEventListener('message', ({ data }) => { | |
const response = { result: calculate(data.value) }; | |
postMessage(response); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function calculate(value: number): string | null { | |
const start = Date.now(); | |
// Loop until the required amount of time has passed. | |
// Imagine this is the computation causing a major latency. | |
while ((Date.now() - start) / 1000 < value); | |
return value !== null ? `Some result for value ${value}` : null; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export declare class ElementRef<T = any> { | |
nativeElement: T; | |
constructor(nativeElement: T); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ng-container *ngTemplateOutlet="myTemplate"></ng-container> | |
<ng-template #myTemplate> | |
<p>I'm an embedded view! Yay!</p> | |
</ng-template> |