init
This commit is contained in:
commit
960cea5a25
16
.browserslistrc
Normal file
16
.browserslistrc
Normal file
|
@ -0,0 +1,16 @@
|
|||
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
||||
# For additional information regarding the format and rule options, please see:
|
||||
# https://github.com/browserslist/browserslist#queries
|
||||
|
||||
# For the full list of supported browsers by the Angular framework, please see:
|
||||
# https://angular.io/guide/browser-support
|
||||
|
||||
# You can see what browsers were selected by your queries by running:
|
||||
# npx browserslist
|
||||
|
||||
last 1 Chrome version
|
||||
last 1 Firefox version
|
||||
last 2 Edge major versions
|
||||
last 2 Safari major versions
|
||||
last 2 iOS major versions
|
||||
Firefox ESR
|
16
.editorconfig
Normal file
16
.editorconfig
Normal file
|
@ -0,0 +1,16 @@
|
|||
# Editor configuration, see https://editorconfig.org
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.ts]
|
||||
quote_type = single
|
||||
|
||||
[*.md]
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
42
.gitignore
vendored
Normal file
42
.gitignore
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
# See http://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# Compiled output
|
||||
/dist
|
||||
/tmp
|
||||
/out-tsc
|
||||
/bazel-out
|
||||
|
||||
# Node
|
||||
/node_modules
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
# IDEs and editors
|
||||
.idea/
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
.history/*
|
||||
|
||||
# Miscellaneous
|
||||
/.angular/cache
|
||||
.sass-cache/
|
||||
/connect.lock
|
||||
/coverage
|
||||
/libpeerconnection.log
|
||||
testem.log
|
||||
/typings
|
||||
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
27
README.md
Normal file
27
README.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# B2b
|
||||
|
||||
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.3.9.
|
||||
|
||||
## Development server
|
||||
|
||||
Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
|
||||
|
||||
## Code scaffolding
|
||||
|
||||
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
|
||||
|
||||
## Build
|
||||
|
||||
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
## Running unit tests
|
||||
|
||||
Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
||||
|
||||
## Running end-to-end tests
|
||||
|
||||
Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
|
||||
|
||||
## Further help
|
||||
|
||||
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
114
angular.json
Normal file
114
angular.json
Normal file
|
@ -0,0 +1,114 @@
|
|||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"schematics": {
|
||||
"@schematics/angular": {
|
||||
"component": {
|
||||
"changeDetection": "OnPush"
|
||||
}
|
||||
}
|
||||
},
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"b2b": {
|
||||
"projectType": "application",
|
||||
"schematics": {
|
||||
"@schematics/angular:application": {
|
||||
"strict": true
|
||||
}
|
||||
},
|
||||
"root": "",
|
||||
"sourceRoot": "src",
|
||||
"prefix": "app",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:browser",
|
||||
"options": {
|
||||
"outputPath": "dist/b2b",
|
||||
"index": "src/index.html",
|
||||
"main": "src/main.ts",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
],
|
||||
"webWorkerTsConfig": "tsconfig.worker.json"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"budgets": [
|
||||
{
|
||||
"type": "initial",
|
||||
"maximumWarning": "500kb",
|
||||
"maximumError": "1mb"
|
||||
},
|
||||
{
|
||||
"type": "anyComponentStyle",
|
||||
"maximumWarning": "2kb",
|
||||
"maximumError": "4kb"
|
||||
}
|
||||
],
|
||||
"fileReplacements": [
|
||||
{
|
||||
"replace": "src/environments/environment.ts",
|
||||
"with": "src/environments/environment.prod.ts"
|
||||
}
|
||||
],
|
||||
"outputHashing": "all"
|
||||
},
|
||||
"development": {
|
||||
"buildOptimizer": false,
|
||||
"optimization": false,
|
||||
"vendorChunk": true,
|
||||
"extractLicenses": false,
|
||||
"sourceMap": true,
|
||||
"namedChunks": true
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "production"
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "b2b:build:production"
|
||||
},
|
||||
"development": {
|
||||
"browserTarget": "b2b:build:development"
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": "development"
|
||||
},
|
||||
"extract-i18n": {
|
||||
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||
"options": {
|
||||
"browserTarget": "b2b:build"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"main": "src/test.ts",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"tsConfig": "tsconfig.spec.json",
|
||||
"karmaConfig": "karma.conf.js",
|
||||
"assets": [
|
||||
"src/favicon.ico",
|
||||
"src/assets"
|
||||
],
|
||||
"styles": [
|
||||
"src/styles.css"
|
||||
],
|
||||
"scripts": [],
|
||||
"webWorkerTsConfig": "tsconfig.worker.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultProject": "b2b"
|
||||
}
|
44
karma.conf.js
Normal file
44
karma.conf.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||
|
||||
module.exports = function (config) {
|
||||
config.set({
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-jasmine-html-reporter'),
|
||||
require('karma-coverage'),
|
||||
require('@angular-devkit/build-angular/plugins/karma')
|
||||
],
|
||||
client: {
|
||||
jasmine: {
|
||||
// you can add configuration options for Jasmine here
|
||||
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
||||
// for example, you can disable the random execution with `random: false`
|
||||
// or set a specific seed with `seed: 4321`
|
||||
},
|
||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||
},
|
||||
jasmineHtmlReporter: {
|
||||
suppressAll: true // removes the duplicated traces
|
||||
},
|
||||
coverageReporter: {
|
||||
dir: require('path').join(__dirname, './coverage/b2b'),
|
||||
subdir: '.',
|
||||
reporters: [
|
||||
{ type: 'html' },
|
||||
{ type: 'text-summary' }
|
||||
]
|
||||
},
|
||||
reporters: ['progress', 'kjhtml'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false,
|
||||
restartOnFileChange: true
|
||||
});
|
||||
};
|
21182
package-lock.json
generated
Normal file
21182
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
45
package.json
Normal file
45
package.json
Normal file
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"name": "b2b",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
"build": "ng build",
|
||||
"watch": "ng build --watch --configuration development",
|
||||
"test": "ng test"
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "~13.3.0",
|
||||
"@angular/common": "~13.3.0",
|
||||
"@angular/compiler": "~13.3.0",
|
||||
"@angular/core": "~13.3.0",
|
||||
"@angular/forms": "~13.3.0",
|
||||
"@angular/platform-browser": "~13.3.0",
|
||||
"@angular/platform-browser-dynamic": "~13.3.0",
|
||||
"@angular/router": "~13.3.0",
|
||||
"@types/reflect-metadata": "^0.1.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "~7.5.0",
|
||||
"tslib": "^2.3.0",
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~13.3.9",
|
||||
"@angular/cli": "~13.3.9",
|
||||
"@angular/compiler-cli": "~13.3.0",
|
||||
"@types/jasmine": "~3.10.0",
|
||||
"@types/node": "^12.11.1",
|
||||
"autoprefixer": "^10.4.12",
|
||||
"jasmine-core": "~4.0.0",
|
||||
"karma": "~6.3.0",
|
||||
"karma-chrome-launcher": "~3.1.0",
|
||||
"karma-coverage": "~2.1.0",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
"karma-jasmine-html-reporter": "~1.7.0",
|
||||
"postcss": "^8.4.16",
|
||||
"tailwindcss": "^3.1.8",
|
||||
"typescript": "~4.6.2"
|
||||
}
|
||||
}
|
3
src/app/app.component.css
Normal file
3
src/app/app.component.css
Normal file
|
@ -0,0 +1,3 @@
|
|||
:host {
|
||||
@apply flex w-full h-full justify-center overflow-scroll;
|
||||
}
|
8
src/app/app.component.html
Normal file
8
src/app/app.component.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<main>
|
||||
<header class="p-12 mb-4">
|
||||
<app-form></app-form>
|
||||
</header>
|
||||
<section class="overflow-x-auto relative p-12">
|
||||
<app-table></app-table>
|
||||
</section>
|
||||
</main>
|
10
src/app/app.component.ts
Normal file
10
src/app/app.component.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
templateUrl: './app.component.html',
|
||||
styleUrls: ['./app.component.css'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class AppComponent {
|
||||
}
|
22
src/app/app.module.ts
Normal file
22
src/app/app.module.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import { AppComponent } from './app.component';
|
||||
import { FormComponent } from './form/form.component';
|
||||
import { TableComponent } from './table/table.component';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
AppComponent,
|
||||
TableComponent,
|
||||
FormComponent,
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
ReactiveFormsModule,
|
||||
],
|
||||
providers: [],
|
||||
bootstrap: [AppComponent],
|
||||
})
|
||||
export class AppModule {
|
||||
}
|
23
src/app/app.worker.ts
Normal file
23
src/app/app.worker.ts
Normal file
|
@ -0,0 +1,23 @@
|
|||
/// <reference lib="webworker" />
|
||||
|
||||
import { plainToClass } from 'class-transformer';
|
||||
import { generateArray } from './faker';
|
||||
import { Message, Parent } from './types';
|
||||
|
||||
let intervalId: any;
|
||||
|
||||
addEventListener('message', (message) => {
|
||||
const timer = (message?.data as Message)?.timer ?? 300;
|
||||
const size = (message?.data as Message)?.size ?? 1000;
|
||||
const ids = (message?.data as Message)?.ids ?? [];
|
||||
clearInterval(intervalId);
|
||||
|
||||
intervalId = setInterval(() => {
|
||||
const rawItems = generateArray(size, ids);
|
||||
const transformedItems = rawItems.map(
|
||||
item => plainToClass(Parent, item),
|
||||
)
|
||||
|
||||
postMessage(transformedItems);
|
||||
}, timer);
|
||||
});
|
14
src/app/destroy.service.ts
Normal file
14
src/app/destroy.service.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { Injectable, OnDestroy } from '@angular/core';
|
||||
import { ReplaySubject } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class DestroyService extends ReplaySubject<void> implements OnDestroy {
|
||||
constructor() {
|
||||
super(1);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.next();
|
||||
this.complete();
|
||||
}
|
||||
}
|
31
src/app/faker.ts
Normal file
31
src/app/faker.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { Parent } from './types';
|
||||
|
||||
export const generateArray = (length: number, ids: Array<string> = []): Array<Parent> => {
|
||||
const data = Array(length - ids.length).fill(0).map(
|
||||
(_, id) => ({
|
||||
id: id.toString(),
|
||||
int: Math.floor(Math.random() * 100000),
|
||||
color: `#${Math.floor(Math.random()*16777215).toString(16)}`,
|
||||
float: Math.random().toFixed(18),
|
||||
child: {
|
||||
id: Math.floor(Math.random() * 10000).toString(),
|
||||
color: `#${Math.floor(Math.random()*16777215).toString(16)}`
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
for (const id of ids) {
|
||||
data.push({
|
||||
id: id,
|
||||
int: Math.floor(Math.random() * 100000),
|
||||
color: `#${Math.floor(Math.random()*16777215).toString(16)}`,
|
||||
float: Math.random().toFixed(18),
|
||||
child: {
|
||||
id: Math.floor(Math.random() * 10000).toString(),
|
||||
color: `#${Math.floor(Math.random()*16777215).toString(16)}`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return data;
|
||||
};
|
18
src/app/form/form.component.css
Normal file
18
src/app/form/form.component.css
Normal file
|
@ -0,0 +1,18 @@
|
|||
:host {
|
||||
@apply flex justify-start items-center;
|
||||
}
|
||||
|
||||
.input {
|
||||
@apply
|
||||
bg-gray-50
|
||||
border border-gray-300
|
||||
text-gray-900 text-sm
|
||||
rounded-lg
|
||||
focus:ring-blue-500 focus:border-blue-500
|
||||
block w-full p-2.5;
|
||||
}
|
||||
|
||||
.label {
|
||||
@apply
|
||||
block mb-2 text-sm font-medium text-gray-900;
|
||||
}
|
35
src/app/form/form.component.html
Normal file
35
src/app/form/form.component.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
<ng-container [formGroup]="formGroup">
|
||||
<div class="flex flex-col items-start mr-4">
|
||||
<label for="timer" class="label">
|
||||
Timer, ms
|
||||
</label>
|
||||
<input
|
||||
class="input"
|
||||
id="timer"
|
||||
type="text"
|
||||
formControlName="timer"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col items-start mr-4">
|
||||
<label for="size" class="label">
|
||||
Array size
|
||||
</label>
|
||||
<input
|
||||
id="size"
|
||||
class="input"
|
||||
type="text"
|
||||
formControlName="size"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col items-start">
|
||||
<label for="ids" class="label">
|
||||
Additional array ids
|
||||
</label>
|
||||
<input
|
||||
id="ids"
|
||||
class="input"
|
||||
type="text"
|
||||
formControlName="ids"
|
||||
/>
|
||||
</div>
|
||||
</ng-container>
|
70
src/app/form/form.component.ts
Normal file
70
src/app/form/form.component.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { combineLatest, debounceTime, filter, map, startWith, takeUntil } from 'rxjs';
|
||||
import { DestroyService } from '../destroy.service';
|
||||
import { WorkerService } from '../worker.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-form',
|
||||
templateUrl: './form.component.html',
|
||||
styleUrls: ['./form.component.css'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
providers: [
|
||||
DestroyService,
|
||||
],
|
||||
})
|
||||
export class FormComponent implements OnInit {
|
||||
public formGroup = new FormGroup({
|
||||
timer: new FormControl(300),
|
||||
size: new FormControl(1000),
|
||||
ids: new FormControl('1001, 1002, 1003'),
|
||||
})
|
||||
|
||||
constructor(
|
||||
private readonly destroy$: DestroyService,
|
||||
private readonly workerService: WorkerService,
|
||||
) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
combineLatest([
|
||||
this.formGroup.controls['timer'].valueChanges
|
||||
.pipe(
|
||||
startWith(this.formGroup.controls['timer'].value),
|
||||
filter(value => !isNaN(+value)),
|
||||
debounceTime(300),
|
||||
),
|
||||
this.formGroup.controls['size'].valueChanges
|
||||
.pipe(
|
||||
startWith(this.formGroup.controls['size'].value),
|
||||
filter(value => !isNaN(+value)),
|
||||
debounceTime(300),
|
||||
),
|
||||
this.formGroup.controls['ids'].valueChanges
|
||||
.pipe(
|
||||
filter(value => {
|
||||
const ids: Array<string> = value.replaceAll(/\s/g, '').split(',');
|
||||
|
||||
for (const id of ids) {
|
||||
if (isNaN(+id)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}),
|
||||
startWith(this.formGroup.controls['timer'].value),
|
||||
map(value => value.replaceAll(/\s/g, '').split(',').map((id: string) => +id)),
|
||||
debounceTime(300),
|
||||
),
|
||||
])
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
)
|
||||
.subscribe(
|
||||
([timer, size, ids]) => {
|
||||
this.workerService.postMessage({timer: +timer, size: +size, ids});
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
0
src/app/table/table.component.css
Normal file
0
src/app/table/table.component.css
Normal file
64
src/app/table/table.component.html
Normal file
64
src/app/table/table.component.html
Normal file
|
@ -0,0 +1,64 @@
|
|||
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-fixed">
|
||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
id
|
||||
</th>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
int
|
||||
</th>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
float
|
||||
</th>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
color
|
||||
</th>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
child
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
class="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
|
||||
*ngFor="let item of itemsToShow; trackBy:trackByFn"
|
||||
>
|
||||
<th scope="row" class="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||
{{ item.id }}
|
||||
</th>
|
||||
<td class="py-4 px-6 w-12">
|
||||
{{ item.int }}
|
||||
</td>
|
||||
<td class="py-4 px-6">
|
||||
{{ item.float }}
|
||||
</td>
|
||||
<td class="py-4 px-6" [bgColor]="item.child.color">
|
||||
{{ item.child.color }}
|
||||
</td>
|
||||
<td class="py-4 px-6">
|
||||
<table class="w-full text-sm text-left text-gray-500 dark:text-gray-400 table-fixed">
|
||||
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
id
|
||||
</th>
|
||||
<th scope="col" class="py-3 px-6">
|
||||
color
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700">
|
||||
<th scope="row" class="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
||||
{{ item.child.id }}
|
||||
</th>
|
||||
<td class="py-4 px-6" [bgColor]="item.child.color">
|
||||
{{ item.child.color }}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
52
src/app/table/table.component.ts
Normal file
52
src/app/table/table.component.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import {
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
DoCheck,
|
||||
NgZone,
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
import { Parent } from '../types';
|
||||
import { WorkerService } from '../worker.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-table',
|
||||
templateUrl: './table.component.html',
|
||||
styleUrls: ['./table.component.css'],
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class TableComponent implements OnInit {
|
||||
public itemsToShow: Array<Parent> = [];
|
||||
|
||||
constructor(
|
||||
private readonly workerService: WorkerService,
|
||||
private readonly ngZone: NgZone,
|
||||
private readonly changeDetectorRef: ChangeDetectorRef,
|
||||
) {
|
||||
this.changeDetectorRef.detach();
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
const fn = (event: MessageEvent) => {
|
||||
this.ngZone.runOutsideAngular(
|
||||
() => {
|
||||
const itemsToShow: Array<Parent> = event.data.slice(-10);
|
||||
|
||||
this.ngZone.run(
|
||||
() => {
|
||||
this.itemsToShow = itemsToShow;
|
||||
this.changeDetectorRef.detectChanges();
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
this.workerService.connect(fn.bind(this));
|
||||
}
|
||||
|
||||
// Sort of useless because of too random data :)
|
||||
public trackByFn(index: number, item: Parent) {
|
||||
return `${item.id}${item.int}${item.float}${item.color}${item.child.id}${item.child.color}`;
|
||||
}
|
||||
}
|
21
src/app/types.ts
Normal file
21
src/app/types.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { Type } from 'class-transformer';
|
||||
import 'reflect-metadata';
|
||||
|
||||
export class Child {
|
||||
id: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export class Parent extends Child {
|
||||
int: number;
|
||||
float: string;
|
||||
|
||||
@Type(() => Child)
|
||||
child: Child;
|
||||
}
|
||||
|
||||
export interface Message {
|
||||
timer?: number;
|
||||
size?: number;
|
||||
ids?: Array<string>,
|
||||
}
|
33
src/app/worker.service.ts
Normal file
33
src/app/worker.service.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Message } from './types';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class WorkerService {
|
||||
protected worker: Worker | undefined;
|
||||
|
||||
constructor() {
|
||||
this.initWorker();
|
||||
}
|
||||
|
||||
private initWorker(): void {
|
||||
if (typeof Worker !== 'undefined') {
|
||||
this.worker = new Worker(new URL('./app.worker', import.meta.url));
|
||||
}
|
||||
}
|
||||
|
||||
public connect(
|
||||
fn: (messageEvent: MessageEvent) => void,
|
||||
): void {
|
||||
this.worker!.onmessage = fn;
|
||||
}
|
||||
|
||||
public postMessage(message: Message) {
|
||||
this.worker?.postMessage(message);
|
||||
}
|
||||
|
||||
public terminate(): void {
|
||||
this.worker?.terminate();
|
||||
}
|
||||
}
|
0
src/assets/.gitkeep
Normal file
0
src/assets/.gitkeep
Normal file
3
src/environments/environment.prod.ts
Normal file
3
src/environments/environment.prod.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export const environment = {
|
||||
production: true
|
||||
};
|
16
src/environments/environment.ts
Normal file
16
src/environments/environment.ts
Normal file
|
@ -0,0 +1,16 @@
|
|||
// This file can be replaced during build by using the `fileReplacements` array.
|
||||
// `ng build` replaces `environment.ts` with `environment.prod.ts`.
|
||||
// The list of file replacements can be found in `angular.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
};
|
||||
|
||||
/*
|
||||
* For easier debugging in development mode, you can import the following file
|
||||
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
|
||||
*
|
||||
* This import should be commented out in production mode because it will have a negative impact
|
||||
* on performance if an error is thrown.
|
||||
*/
|
||||
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
BIN
src/favicon.ico
Normal file
BIN
src/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 948 B |
13
src/index.html
Normal file
13
src/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>B2b</title>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
12
src/main.ts
Normal file
12
src/main.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import { enableProdMode } from '@angular/core';
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { AppModule } from './app/app.module';
|
||||
import { environment } from './environments/environment';
|
||||
|
||||
if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||
.catch(err => console.error(err));
|
55
src/polyfills.ts
Normal file
55
src/polyfills.ts
Normal file
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
* This file includes polyfills needed by Angular and is loaded before the app.
|
||||
* You can add your own extra polyfills to this file.
|
||||
*
|
||||
* This file is divided into 2 sections:
|
||||
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
||||
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
||||
* file.
|
||||
*
|
||||
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
||||
* automatically update themselves. This includes recent versions of Safari, Chrome (including
|
||||
* Opera), Edge on the desktop, and iOS and Chrome on mobile.
|
||||
*
|
||||
* Learn more in https://angular.io/guide/browser-support
|
||||
*/
|
||||
|
||||
/***************************************************************************************************
|
||||
* BROWSER POLYFILLS
|
||||
*/
|
||||
|
||||
import 'reflect-metadata';
|
||||
|
||||
/**
|
||||
* By default, zone.js will patch all possible macroTask and DomEvents
|
||||
* user can disable parts of macroTask/DomEvents patch by setting following flags
|
||||
* because those flags need to be set before `zone.js` being loaded, and webpack
|
||||
* will put import in the top of bundle, so user need to create a separate file
|
||||
* in this directory (for example: zone-flags.ts), and put the following flags
|
||||
* into that file, and then add the following code before importing zone.js.
|
||||
* import './zone-flags';
|
||||
*
|
||||
* The flags allowed in zone-flags.ts are listed here.
|
||||
*
|
||||
* The following flags will work for all browsers.
|
||||
*
|
||||
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
|
||||
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
|
||||
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
|
||||
*
|
||||
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
|
||||
* with the following flag, it will bypass `zone.js` patch for IE/Edge
|
||||
*
|
||||
* (window as any).__Zone_enable_cross_context_check = true;
|
||||
*
|
||||
*/
|
||||
|
||||
/***************************************************************************************************
|
||||
* Zone JS is required by default for Angular itself.
|
||||
*/
|
||||
import 'zone.js'; // Included with Angular CLI.
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
* APPLICATION IMPORTS
|
||||
*/
|
8
src/styles.css
Normal file
8
src/styles.css
Normal file
|
@ -0,0 +1,8 @@
|
|||
/* You can add global styles to this file, and also import other style files */
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
body {
|
||||
@apply h-[100vh];
|
||||
}
|
26
src/test.ts
Normal file
26
src/test.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||
|
||||
import 'zone.js/testing';
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting
|
||||
} from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
declare const require: {
|
||||
context(path: string, deep?: boolean, filter?: RegExp): {
|
||||
<T>(id: string): T;
|
||||
keys(): string[];
|
||||
};
|
||||
};
|
||||
|
||||
// First, initialize the Angular testing environment.
|
||||
getTestBed().initTestEnvironment(
|
||||
BrowserDynamicTestingModule,
|
||||
platformBrowserDynamicTesting(),
|
||||
);
|
||||
|
||||
// Then we find all the tests.
|
||||
const context = require.context('./', true, /\.spec\.ts$/);
|
||||
// And load the modules.
|
||||
context.keys().map(context);
|
10
tailwind.config.js
Normal file
10
tailwind.config.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./src/**/*.{html,ts}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
15
tsconfig.app.json
Normal file
15
tsconfig.app.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/app",
|
||||
"types": []
|
||||
},
|
||||
"files": [
|
||||
"src/main.ts",
|
||||
"src/polyfills.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
34
tsconfig.json
Normal file
34
tsconfig.json
Normal file
|
@ -0,0 +1,34 @@
|
|||
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"baseUrl": "./",
|
||||
"outDir": "./dist/out-tsc",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"noImplicitOverride": true,
|
||||
"noPropertyAccessFromIndexSignature": true,
|
||||
"noImplicitReturns": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"sourceMap": true,
|
||||
"declaration": false,
|
||||
"downlevelIteration": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"target": "es2017",
|
||||
"module": "es2020",
|
||||
"lib": [
|
||||
"es2020",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"enableI18nLegacyMessageIdFormat": false,
|
||||
"strictInjectionParameters": true,
|
||||
"strictInputAccessModifiers": true,
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
18
tsconfig.spec.json
Normal file
18
tsconfig.spec.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/spec",
|
||||
"types": [
|
||||
"jasmine"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"src/test.ts",
|
||||
"src/polyfills.ts"
|
||||
],
|
||||
"include": [
|
||||
"src/**/*.spec.ts",
|
||||
"src/**/*.d.ts"
|
||||
]
|
||||
}
|
15
tsconfig.worker.json
Normal file
15
tsconfig.worker.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./out-tsc/worker",
|
||||
"lib": [
|
||||
"es2018",
|
||||
"webworker"
|
||||
],
|
||||
"types": []
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.worker.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in a new issue