import { Mutator, Datar } from '../particles'; import { AtomType, BaseAtom } from './base.atom'; import type { Vacuo } from '../metas'; import type { MutatorOptions, TransformationLiftOptions, MutatorTransformation, LiftBothTransformation, LiftLeftTransformation, LiftRightTransformation, MutatorOriginalTransformationUnion } from '../particles'; import type { AtomLike, DataLike, MutationLike, BaseAtomOptions, SubscribeOptions, Subscription, AtomTriggerRegisterOptions, TriggerController, Trigger } from './base.atom'; import type { DataSubscription } from './data.atom'; /****************************************************************************************************** * * Mutation Predicatess * ******************************************************************************************************/ /** * @param target anything * @return { boolean } whether the target is a Mutation instance */ export declare function isMutation
(target: Mutation
): target is Mutation
; export declare function isMutation
(target: unknown): target is Mutation
; /****************************************************************************************************** * * Mutation Classes * ******************************************************************************************************/ /** * */ export interface MutationOptions
extends BaseAtomOptions { lift?: TransformationLiftOptions; mutator?: MutatorOptions; isLifted?: boolean; originalTransformation?: null | MutatorOriginalTransformationUnion
;
}
export declare const DEFAULT_MUTATION_OPTIONS: Required = (mutator: Mutator , mutation: MutationLike ) => void;
export declare type TransformationConsumer = (transformation: (current: Datar ) => void;
export declare type MutationConsumer = MutatorConsumer | TransformationConsumer ;
export interface MutationSubscription extends Subscription {
proxyConsumer: MutatorConsumer ;
}
export declare type MutationTriggerAccepted = Mutator | ((...args: any[]) => C) | C;
export declare type MutationTrigger = Trigger extends BaseAtom implements AtomLike {
private readonly _options;
private _mutator;
private readonly _consumers;
private readonly _subscriptions;
private readonly _observations;
constructor(mutator: Mutator , options?: MutationOptions );
get type(): AtomType;
get atomType(): AtomType;
get particleName(): string;
get particle(): Mutator ;
get metaName(): string;
get meta(): Mutator ['transformation'];
get options(): Required (transformation: MutatorTransformation | Mutator , options?: MutationOptions ): Mutation ;
/**
* Same as `Mutation.of(Mutator.of(VACUO, CHAOS, options.mutator), options)`.
*/
static empty (options?: MutationOptions ;
static ofLift (transformation: MutatorOriginalTransformationUnion , options?: MutationOptions ): Mutation ;
static ofLiftBoth (transformation: LiftBothTransformation , options?: MutationOptions ): Mutation ;
static ofLiftLeft (transformation: LiftLeftTransformation , options?: MutationOptions ): Mutation ;
static ofLiftRight (transformation: LiftRightTransformation , options?: MutationOptions ): Mutation ;
/**
* Mutator of Mutation.
*/
get mutator(): Mutator ;
/**
* Transformation of Mutator of Mutation.
*
* If the transformation is lifted, the original transformation will
* be returned as first choice instead of lifted transformation.
*/
get transformation(): Mutator ['transformation'];
get originalTransformation(): MutatorOriginalTransformationUnion | null;
/**
* Stream value of Mutation.
*
* @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: MutatorConsumer ): MutationSubscription ;
subscribe(consumer: MutatorConsumer , options: SubscribeOptions & {
isExtracted: false;
}): MutationSubscription ;
subscribe(consumer: TransformationConsumer , options: SubscribeOptions & {
isExtracted: true;
}): MutationSubscription ;
subscribe(consumer: MutationConsumer , options?: SubscribeOptions): MutationSubscription ;
/**
* Same as `.subscribe(consumer, { ...options, isExtracted: true })`.
*
* Get a transformation of mutator of mutation, which bind latest
* datar of mutation as first argument.
*/
subscribeTransformation(consumer: TransformationConsumer , options?: SubscribeOptions): MutationSubscription ;
/**
* Given a consumer, find and return the subscription.
*/
getSubscriptionByConsumer(consumer: MutationConsumer ): MutationSubscription | undefined;
/**
* Given a hostAtom, find and return the subscription.
*/
getSubscriptionByHostAtom(hostAtom: AtomLike): MutationSubscription | undefined;
/**
* Given a consumer or atom, find and return the subscription.
*/
getSubscription(consumerOrHostAtom: MutationConsumer | AtomLike): MutationSubscription | undefined;
/**
* Given a consumer or subscription, unsubscribe it.
*/
unsubscribe(target: MutationConsumer | MutationSubscription | AtomLike): boolean;
/**
* Unsubscribe all subscriptions.
*/
unsubscribeAll(): boolean;
/**
* `Empty mutator` will not be triggered.
*
* @param mutator mutator
*/
trigger(mutator?: Mutator ): void;
/**
* Internally call `trigger` method which will not trigger `empty mutator`,
* so the `Vacuo` value will not be triggered by `triggerTransformation` method.
*
* @param transformation transformation
*/
triggerTransformation(transformation?: Mutator ['transformation']): void;
/**
* Change the value of Mutation in a stream manner.
*
* Given "data" will be **upstream** of current Mutation, which is different from "beObservedBy" method.
*
* @param mutation data -> current mutation (-> other data)
*/
observe(data: DataLike ): DataSubscription ;
unobserve(data: DataLike ): boolean;
unobserveAll(): boolean;
/**
* Change the value of Mutation in a stream manner.
*
* Given "data" will be **downstream** of current Mutation, which is different from "observe" method.
*
* @param mutation (other data ->) current mutation -> data
*/
beObservedBy(data: DataLike ;
/**
* Change the value of Mutation in a static manner.
*
* take datar-like param(convert to datar)
* -> run datar with current mutator & contexts
* -> wrap and save result of datar.run as new mutator
* -> trigger consumers with new mutator & contexts
*
* @param datar Will be the 2nd param of mutator's operation.
* @param data
* @return { Mutation } Mutation(this)
*/
mutate(datar: DataLike | Datar | P, data?: DataLike ): this;
/**
* @param trigger Which Take an internalTrigger(Function) as first parameter,
* invoke internalTrigger with any value will lead to
* Mutation's trigger method be triggerd with that value.
* @param options
* @param [options.forceWrap = false] If true, the emitted value of trigger will always be wrapped in Mutator.
* @return { TriggerController } TriggerController
*/
registerTrigger(trigger: MutationTrigger , options?: AtomTriggerRegisterOptions): TriggerController;
}
/**
* GC, aka. Garbage Clean, used by mediator to release memories.
*/
export declare const GC_MUTATION: Mutation