mirror of https://github.com/abpframework/abp.git
committed by
GitHub
17 changed files with 190 additions and 177 deletions
@ -1,39 +1,45 @@ |
|||||
import { Component, OnDestroy, OnInit, Type } from '@angular/core'; |
import { Component, OnInit, Type } from '@angular/core'; |
||||
import { ActivatedRoute } from '@angular/router'; |
import { ActivatedRoute } from '@angular/router'; |
||||
import { Store } from '@ngxs/store'; |
import { Store } from '@ngxs/store'; |
||||
import { distinctUntilChanged } from 'rxjs/operators'; |
import { distinctUntilChanged } from 'rxjs/operators'; |
||||
import { ABP } from '../models/common'; |
|
||||
import { ReplaceableComponents } from '../models/replaceable-components'; |
import { ReplaceableComponents } from '../models/replaceable-components'; |
||||
|
import { SubscriptionService } from '../services/subscription.service'; |
||||
import { ReplaceableComponentsState } from '../states/replaceable-components.state'; |
import { ReplaceableComponentsState } from '../states/replaceable-components.state'; |
||||
import { takeUntilDestroy } from '../utils/rxjs-utils'; |
|
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-replaceable-route-container', |
selector: 'abp-replaceable-route-container', |
||||
template: ` |
template: ` |
||||
<ng-container *ngComponentOutlet="externalComponent || defaultComponent"></ng-container> |
<ng-container *ngComponentOutlet="externalComponent || defaultComponent"></ng-container> |
||||
`,
|
`,
|
||||
|
providers: [SubscriptionService], |
||||
}) |
}) |
||||
export class ReplaceableRouteContainerComponent implements OnInit, OnDestroy { |
export class ReplaceableRouteContainerComponent implements OnInit { |
||||
defaultComponent: Type<any>; |
defaultComponent: Type<any>; |
||||
|
|
||||
componentKey: string; |
componentKey: string; |
||||
|
|
||||
externalComponent: Type<any>; |
externalComponent: Type<any>; |
||||
|
|
||||
constructor(private route: ActivatedRoute, private store: Store) {} |
constructor( |
||||
|
private route: ActivatedRoute, |
||||
|
private store: Store, |
||||
|
private subscription: SubscriptionService, |
||||
|
) {} |
||||
|
|
||||
ngOnInit() { |
ngOnInit() { |
||||
this.defaultComponent = this.route.snapshot.data.replaceableComponent.defaultComponent; |
this.defaultComponent = this.route.snapshot.data.replaceableComponent.defaultComponent; |
||||
this.componentKey = (this.route.snapshot.data |
this.componentKey = (this.route.snapshot.data |
||||
.replaceableComponent as ReplaceableComponents.RouteData).key; |
.replaceableComponent as ReplaceableComponents.RouteData).key; |
||||
|
|
||||
this.store |
const component$ = this.store |
||||
.select(ReplaceableComponentsState.getComponent(this.componentKey)) |
.select(ReplaceableComponentsState.getComponent(this.componentKey)) |
||||
.pipe(takeUntilDestroy(this), distinctUntilChanged()) |
.pipe(distinctUntilChanged()); |
||||
.subscribe((res = {} as ReplaceableComponents.ReplaceableComponent) => { |
|
||||
|
this.subscription.addOne( |
||||
|
component$, |
||||
|
(res = {} as ReplaceableComponents.ReplaceableComponent) => { |
||||
this.externalComponent = res.component; |
this.externalComponent = res.component; |
||||
}); |
}, |
||||
|
); |
||||
} |
} |
||||
|
|
||||
ngOnDestroy() {} |
|
||||
} |
} |
||||
|
|||||
@ -1,34 +1,25 @@ |
|||||
import { |
import { Directive, ElementRef, EventEmitter, Input, OnInit, Output } from '@angular/core'; |
||||
Directive, |
|
||||
ElementRef, |
|
||||
EventEmitter, |
|
||||
Input, |
|
||||
OnDestroy, |
|
||||
OnInit, |
|
||||
Output, |
|
||||
} from '@angular/core'; |
|
||||
import { takeUntilDestroy } from '../utils/rxjs-utils'; |
|
||||
import { fromEvent } from 'rxjs'; |
import { fromEvent } from 'rxjs'; |
||||
import { debounceTime } from 'rxjs/operators'; |
import { debounceTime } from 'rxjs/operators'; |
||||
|
import { SubscriptionService } from '../services/subscription.service'; |
||||
|
|
||||
@Directive({ |
@Directive({ |
||||
// tslint:disable-next-line: directive-selector
|
// tslint:disable-next-line: directive-selector
|
||||
selector: '[input.debounce]', |
selector: '[input.debounce]', |
||||
|
providers: [SubscriptionService], |
||||
}) |
}) |
||||
export class InputEventDebounceDirective implements OnInit, OnDestroy { |
export class InputEventDebounceDirective implements OnInit { |
||||
@Input() debounce = 300; |
@Input() debounce = 300; |
||||
|
|
||||
@Output('input.debounce') readonly debounceEvent = new EventEmitter<Event>(); |
@Output('input.debounce') readonly debounceEvent = new EventEmitter<Event>(); |
||||
|
|
||||
constructor(private el: ElementRef) {} |
constructor(private el: ElementRef, private subscription: SubscriptionService) {} |
||||
|
|
||||
ngOnInit(): void { |
ngOnInit(): void { |
||||
fromEvent(this.el.nativeElement, 'input') |
const input$ = fromEvent(this.el.nativeElement, 'input').pipe(debounceTime(this.debounce)); |
||||
.pipe(debounceTime(this.debounce), takeUntilDestroy(this)) |
|
||||
.subscribe((event: Event) => { |
|
||||
this.debounceEvent.emit(event); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
ngOnDestroy(): void {} |
this.subscription.addOne(input$, (event: Event) => { |
||||
|
this.debounceEvent.emit(event); |
||||
|
}); |
||||
|
} |
||||
} |
} |
||||
|
|||||
@ -1,24 +1,21 @@ |
|||||
import { Directive, ElementRef, EventEmitter, OnInit, Output, OnDestroy } from '@angular/core'; |
import { Directive, ElementRef, EventEmitter, OnInit, Output } from '@angular/core'; |
||||
import { fromEvent } from 'rxjs'; |
import { fromEvent } from 'rxjs'; |
||||
import { takeUntilDestroy } from '../utils/rxjs-utils'; |
import { SubscriptionService } from '../services/subscription.service'; |
||||
|
|
||||
@Directive({ |
@Directive({ |
||||
// tslint:disable-next-line: directive-selector
|
// tslint:disable-next-line: directive-selector
|
||||
selector: '[click.stop]', |
selector: '[click.stop]', |
||||
|
providers: [SubscriptionService], |
||||
}) |
}) |
||||
export class StopPropagationDirective implements OnInit, OnDestroy { |
export class StopPropagationDirective implements OnInit { |
||||
@Output('click.stop') readonly stopPropEvent = new EventEmitter<MouseEvent>(); |
@Output('click.stop') readonly stopPropEvent = new EventEmitter<MouseEvent>(); |
||||
|
|
||||
constructor(private el: ElementRef) {} |
constructor(private el: ElementRef, private subscription: SubscriptionService) {} |
||||
|
|
||||
ngOnInit(): void { |
ngOnInit(): void { |
||||
fromEvent(this.el.nativeElement, 'click') |
this.subscription.addOne(fromEvent(this.el.nativeElement, 'click'), (event: MouseEvent) => { |
||||
.pipe(takeUntilDestroy(this)) |
event.stopPropagation(); |
||||
.subscribe((event: MouseEvent) => { |
this.stopPropEvent.emit(event); |
||||
event.stopPropagation(); |
}); |
||||
this.stopPropEvent.emit(event); |
|
||||
}); |
|
||||
} |
} |
||||
|
|
||||
ngOnDestroy(): void {} |
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue