Skip to content

Commit

Permalink
perf(module:upload): clear redundant codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ng-nest-moon committed Nov 9, 2021
1 parent 3ddc11e commit 81a7fb8
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 32 deletions.
3 changes: 1 addition & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ module.exports = function (config) {
coverageReporter: {
dir: require('path').join(__dirname, './coverage/ng-nest/site'),
subdir: '.',
reports: ['html', 'text-summary'],
fixWebpackSourcePaths: true
reports: ['html', 'text-summary']
},
reporters: ['progress', 'kjhtml'],
port: 9876,
Expand Down
3 changes: 1 addition & 2 deletions lib/ng-nest/ui/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ module.exports = function (config) {
coverageReporter: {
dir: require('path').join(__dirname, '../../../coverage/ng-nest/ui'),
subdir: '.',
reports: ['html', 'text-summary'],
fixWebpackSourcePaths: true
reports: ['html', 'text-summary']
// thresholds: {
// statements: 70,
// lines: 70,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'ex-default',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'ex-disabled',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component } from '@angular/core';

@Component({
selector: 'ex-disabled',
Expand Down
4 changes: 2 additions & 2 deletions lib/ng-nest/ui/upload/upload-portal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Inject
} from '@angular/core';
import { fromEvent, Subject } from 'rxjs';
import { debounceTime, map, takeUntil, tap } from 'rxjs/operators';
import { takeUntil } from 'rxjs/operators';
import { XClamp } from '@ng-nest/ui/core';
import { XUploadCutType, XUploadNode, XUploadPortalPrefix } from './upload.property';

Expand Down Expand Up @@ -122,7 +122,7 @@ export class XUploadPortalComponent {
});
fromEvent<MouseEvent>(this.doc.documentElement, 'mouseup')
.pipe(takeUntil(_unSub))
.subscribe((x) => {
.subscribe(() => {
this.cutType = '';
this.cdr.detectChanges();
_unSub.next();
Expand Down
2 changes: 1 addition & 1 deletion lib/ng-nest/ui/upload/upload.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ng-container *ngSwitchCase="'img'">
<div class="x-upload-img-item {{ file.state }}" *ngFor="let file of files; index as i; trackBy: trackByItem" [title]="file.name">
<div class="x-upload-img-inner">
<img [src]="file.url" (load)="imgLoad($event, file)" (error)="imgError($event, file)" />
<img [src]="file.url" (load)="imgLoad(file)" (error)="imgError($event, file)" />
<x-icon type="fto-image"></x-icon>
<span *ngIf="file.state == 'uploading'">{{ file.percent }}%</span>
</div>
Expand Down
20 changes: 2 additions & 18 deletions lib/ng-nest/ui/upload/upload.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { XButtonModule } from '@ng-nest/ui/button';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { XUploadComponent } from './upload.component';
import { Component, DebugElement } from '@angular/core';
Expand All @@ -12,7 +12,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { XIconModule } from '@ng-nest/ui/icon';

describe(XUploadPrefix, () => {
beforeEach(async(() => {
beforeEach((() => {
TestBed.configureTestingModule({
imports: [BrowserAnimationsModule, FormsModule, XIconModule, XUploadModule, XButtonModule, XLayoutModule],
declarations: [TestXUploadComponent, TestXUploadDisabledComponent, TestXUploadImgComponent, TestXUploadImgCutComponent]
Expand All @@ -21,14 +21,10 @@ describe(XUploadPrefix, () => {
describe(`default.`, () => {
let fixture: ComponentFixture<TestXUploadComponent>;
let upload: DebugElement;
let testComponent: TestXUploadComponent;
let element: HTMLElement;
beforeEach(() => {
fixture = TestBed.createComponent(TestXUploadComponent);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
upload = fixture.debugElement.query(By.directive(XUploadComponent));
element = upload.nativeElement;
});
it('should create.', () => {
expect(upload).toBeDefined();
Expand All @@ -37,14 +33,10 @@ describe(XUploadPrefix, () => {
describe(`img.`, () => {
let fixture: ComponentFixture<TestXUploadImgComponent>;
let upload: DebugElement;
let testComponent: TestXUploadImgComponent;
let element: HTMLElement;
beforeEach(() => {
fixture = TestBed.createComponent(TestXUploadImgComponent);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
upload = fixture.debugElement.query(By.directive(XUploadComponent));
element = upload.nativeElement;
});
it('should create.', () => {
expect(upload).toBeDefined();
Expand All @@ -53,14 +45,10 @@ describe(XUploadPrefix, () => {
fdescribe(`imgCut.`, () => {
let fixture: ComponentFixture<TestXUploadImgCutComponent>;
let upload: DebugElement;
let testComponent: TestXUploadImgCutComponent;
let element: HTMLElement;
beforeEach(() => {
fixture = TestBed.createComponent(TestXUploadImgCutComponent);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
upload = fixture.debugElement.query(By.directive(XUploadComponent));
element = upload.nativeElement;
});
it('should create.', () => {
expect(upload).toBeDefined();
Expand All @@ -69,14 +57,10 @@ describe(XUploadPrefix, () => {
describe(`disabled.`, () => {
let fixture: ComponentFixture<TestXUploadDisabledComponent>;
let upload: DebugElement;
let testComponent: TestXUploadDisabledComponent;
let element: HTMLElement;
beforeEach(() => {
fixture = TestBed.createComponent(TestXUploadDisabledComponent);
fixture.detectChanges();
testComponent = fixture.debugElement.componentInstance;
upload = fixture.debugElement.query(By.directive(XUploadComponent));
element = upload.nativeElement;
});
it('should create.', () => {
expect(upload).toBeDefined();
Expand Down
9 changes: 5 additions & 4 deletions lib/ng-nest/ui/upload/upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class XUploadComponent extends XUploadProperty {

private _unSubject = new Subject<void>();

writeValue(value: XUploadNode[]) {
override writeValue(value: XUploadNode[]) {
this.value = value;
this.setFiles();
this.cdr.detectChanges();
Expand Down Expand Up @@ -184,7 +184,7 @@ export class XUploadComponent extends XUploadProperty {
return;
}

trackByItem(index: number, item: XUploadNode) {
trackByItem(_index: number, item: XUploadNode) {
return `${item.name}-${item.lastModified}`;
}

Expand Down Expand Up @@ -234,12 +234,13 @@ export class XUploadComponent extends XUploadProperty {
this.portal?.overlayRef?.dispose();
}

imgError(event: Event, file: XUploadNode) {
imgError(event: ErrorEvent, file: XUploadNode) {
file.state = 'error';
console.error(event.error);
this.cdr.detectChanges();
}

imgLoad(event: Event, file: XUploadNode) {
imgLoad(file: XUploadNode) {
file.state = 'success';
this.cdr.detectChanges();
}
Expand Down

0 comments on commit 81a7fb8

Please sign in to comment.