@alauda-fe/common
Version:
Alauda frontend team common codes.
33 lines (32 loc) • 1.06 kB
TypeScript
import { InjectionToken } from '@angular/core';
import { Observable } from 'rxjs';
import * as i0 from "@angular/core";
/**
* 用于跨组件共享状态
*
* 使用示例:
* providers: [{
* provide: CONTEXT_INIT_VALUE_TOKEN,
* useValue: LOG_TIMESTAMP_RANGES[1]
* }, {
* provide: ContextService, // 可以通过不同的token隔离状态或使用具有语意的token来提高可读性等
* useClass: ContextService,
* }],
*
* 与业务无关,简单、纯粹,所以你可以在业务中实现多状态共享,例如
* this.contextService.set({
* ...this.contextService.get(),
* step: 2
* });
*/
export declare const CONTEXT_INIT_VALUE_TOKEN: InjectionToken<unknown>;
export declare class ContextService<T> {
private initValue;
private readonly value$$;
readonly value$: Observable<T>;
set(value?: T): void;
get(): T;
reset(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<ContextService<any>, never>;
static ɵprov: i0.ɵɵInjectableDeclaration<ContextService<any>>;
}