@evan.network/ui-angular-core
Version:
The angular-core operates as an global and central library for the evan.network Angular 5 frontend development. Using this project you will be able to to the following things:
103 lines (102 loc) • 3.71 kB
TypeScript
import { OnInit, OnDestroy, // ionic-angular
ChangeDetectorRef } from 'angular-libs';
/**************************************************************************************************/
/**
* Use for Components that implements asynchronious ngOnInit functions. The ngOnInit function will
* be called and processed. If the App is switched very fast, the ngOnDestroy is called before the
* ngOnInit was resolved. As a result of this, watcher can be bound after ngOnDestroy and will never
* be detached again. Also, this.ref.detectChanges(); functions are called after the ngOnInit was
* resolved. If the view is already detached, this will trigger more errors. Extend your component
* with this class and change your ngOnInit and ngOnDestroy functions into _ngOnInit and
* _ngOnDestroy. The ref is automatically detached, and the loading attribute is set, until the
* ngOnInit was resolved. At the end, if the view wasnt destroyed before, the loading will be
* removed and the functions will be called "this.ref.detectChanges();"
*
* Usage:
*
* export class DAppsRootComponent extends AsyncComponent {
* private watchRouteChange: Function;
*
* constructor(
* private core: EvanCoreService,
* private bcc: EvanBCCService,
* private ref: ChangeDetectorRef,
* private routingService: EvanRoutingService
* ) {
* super(ref);
* }
*
* async _ngOnInit() {
* this.watchRouteChange = this.routingService.subscribeRouteChange(() => this.ref.detectChanges());
* await this.bcc.initialize((accountId) => this.bcc.globalPasswordDialog(accountId));
* await this.core.utils.timeout(1000);
* }
*
* _ngOnDestroy() {
* this.watchRouteChange();
* }
* }
*/
export declare class AsyncComponent implements OnInit, OnDestroy {
/**
* the Angular ChangeDetectorRef to detach the automatic change detection and optimize performance
*/
private _ref;
/**
* disable initial detectChanges
*/
detachRef: boolean;
/**
* promise that waits to wait for ngOnInit to be resolved
*/
awaitOnInit: Promise<any>;
/**
* used to show a loading symbol in components
*/
loading: boolean;
/**
* set, when the ngOnDestroy function was called
*/
wasDestroyed: boolean;
/**
* Take service from component super call.
*/
constructor(ref: ChangeDetectorRef, detachRef?: boolean);
/**
* Detach the ref, awaits the _ngOnInit and remove loading if the dapp wasnt destroyed before
*
* @return {Promise<void>} resolved when done
*/
ngOnInit(): Promise<void>;
/**
* Is called by the ngOnInit function. Should be overwritten by the inherting component.
*
* @return {Promise<void>} resolved when done
*/
_ngOnInit(): Promise<void>;
/**
* Runs the _ngOnViewInit function if the dapp wasnt destroyed before
*
* @return {Promise<void>} resolved when done
*/
ngAfterViewInit(): Promise<void>;
/**
* Is called by the ngAfterViewInit function. Should be overwritten by the inherting component.
*
* @return {Promise<void>} resolved when done
*/
_ngAfterViewInit(): Promise<void>;
/**
* Set the wasDestroyed variable and await the "awaitOnInit" Promise to run the ngOnDestroy
* function.
*
* @return {Promise<void>} resolved when done
*/
ngOnDestroy(): Promise<void>;
/**
* Is called by the ngOnDestroy function. Should be overwritten by the inherting component.
*
* @return {Promise<void>} resolved when done
*/
_ngOnDestroy(): Promise<void>;
}