import { Mutator, Datar } from '../particles'; import { AtomType, BaseAtom } from './base.atom'; import type { Vacuo } from '../metas'; import type { DatarOptions, MutatorTransformation } from '../particles'; import type { AtomLike, DataLike, MutationLike, BaseAtomOptions, SubscribeOptions, Subscription, AtomTriggerRegisterOptions, TriggerController, Trigger } from './base.atom'; import type { MutationSubscription } from './mutation.atom'; /****************************************************************************************************** * * Data Predicatess * ******************************************************************************************************/ /** * @param target anything * @return { boolean } whether the target is a Data instance */ export declare function isData(target: Data): target is Data; export declare function isData(target: unknown): target is Data; /****************************************************************************************************** * * Data Classes * ******************************************************************************************************/ /** * */ export interface DataOptions extends BaseAtomOptions, DatarOptions { } export declare const DEFAULT_DATA_OPTIONS: Required; export declare type DatarConsumer = (datar: Datar, data: DataLike) => void; export declare type ValueConsumer = (value: V, data: DataLike) => void; export declare type DataConsumer = DatarConsumer | ValueConsumer; export interface DataSubscription extends Subscription { proxyConsumer: DatarConsumer; } export declare type DataTriggerAccepted = V | Datar; export declare type DataTrigger = Trigger>; /** * */ export declare class Data extends BaseAtom implements AtomLike { private readonly _options; private _datar; private readonly _consumers; private readonly _subscriptions; private readonly _observations; constructor(datar: Datar, options?: DataOptions); get type(): AtomType; get atomType(): AtomType; get particleName(): string; get particle(): Datar; get metaName(): string; get meta(): Datar['value']; get options(): Required; /** * Set Data's options by key. */ setOptions(key: Key, value: Required[Key]): void; /** * @return { true } true */ get isData(): true; get isEmpty(): boolean; /** * @param value can be a Datar or any other value */ static of(value: Datar | V, options?: DataOptions): Data; /** * Same as `Data.of(Datar.of(VACUO, CHAOS, options))` */ static empty(options?: DataOptions): Data; /** * Datar of Data. */ get datar(): Datar; /** * Value of Datar of Data, same as Data.datar.value. */ get value(): Datar['value']; /** * Stream value of Data. * * @param consumer The consumer will be invoked by "trigger" method when there is a adequate value. * @param options * @param [options.isExtracted = false] Whether to extract the value from the datar before it be passed to consumer. */ subscribe(consumer: DatarConsumer): DataSubscription; subscribe(consumer: DatarConsumer, options: SubscribeOptions & { isExtracted: false; }): DataSubscription; subscribe(consumer: ValueConsumer, options: SubscribeOptions & { isExtracted: true; }): DataSubscription; subscribe(consumer: DataConsumer, options?: SubscribeOptions): DataSubscription; /** * Same as `.subscribe(consumer, { ...options, isExtracted: true })`. */ subscribeValue(consumer: ValueConsumer, options?: SubscribeOptions): DataSubscription; /** * Given a consumer, find and return the subscription. */ getSubscriptionByConsumer(consumer: DataConsumer): DataSubscription | undefined; /** * Given a atom, find and return the subscription. */ getSubscriptionByHostAtom(hostAtom: AtomLike): DataSubscription | undefined; /** * Given a consumer or atom, find and return the subscription. */ getSubscription(consumerOrHostAtom: DataConsumer | AtomLike): DataSubscription | undefined; /** * Given a consumer or subscription or atom, unsubscribe it. */ unsubscribe(target: DataConsumer | DataSubscription | AtomLike): boolean; /** * Unsubscribe all subscriptions. */ unsubscribeAll(): boolean; /** * `Empty datar` will not be triggered. * * @param datar datar */ trigger(datar?: Datar): void; /** * Internally call `trigger` method which will not trigger `empty datar`, * so the `Vacuo` value will not be triggered by `triggerValue` method. * * @param value value */ triggerValue(value?: Datar['value']): void; /** * Change the value of Data in a stream manner. * * Given "mutation" will be **upstream** of current Data, which is different from "beObservedBy" method. * * @param mutation (other data ->) mutation -> current data */ observe(mutation: MutationLike): MutationSubscription; unobserve(mutation: MutationLike): boolean; unobserveAll(): boolean; /** * Change the value of Data in a stream manner. * * Given "mutation" will be **downstream** of current Data, which is different from "observe" method. * * @param mutation current data -> mutation (-> other data) */ beObservedBy(mutation: MutationLike): DataSubscription; /** * Change the value of Data in a static manner. * * take mutator-like param(convert to mutator) * -> run mutator with current datar & contexts * -> wrap and save result of mutator.run as new datar * -> trigger consumers with new datar & contexts * * @param mutator Used to produce new value with current datar. * @param mutation Provide to mutator's transformation (function) as execute contexts. * @return { Data } Data(this) */ mutate

(mutator: MutationLike | Mutator | MutatorTransformation | ((...args: any[]) => V), mutation?: MutationLike): this; /** * @param trigger Takes an internalTrigger(Function) as first parameter, * invoke internalTrigger with any value will lead to * Data's trigger method be triggerd with given value. * @param options * @param [options.forceWrap = false] If true, the emitted value of trigger will always be wrapped in Datar. * @return { TriggerController } TriggerController */ registerTrigger(trigger: DataTrigger, options?: AtomTriggerRegisterOptions): TriggerController; } /** * GC, aka. Garbage Clean, used by mediator to release memories. */ export declare const GC_DATA: Data; //# sourceMappingURL=data.atom.d.ts.map