@traxjs/trax
Version:
Reactive state management
50 lines (49 loc) • 2.55 kB
TypeScript
import { LinkedList } from "./linkedlist";
import { ProcessingContext, TraxComputeFn, TraxEvent, TraxLogTraxProcessingCtxt, TraxProcessor, TraxObjectComputeFn } from "./types";
/**
* Extend the public API with internal APIs
*/
export interface TraxInternalProcessor extends TraxProcessor {
/**
* Target object - only used by lazy processors attached to an object (the target)
*/
readonly target: any | null;
/**
* Tell when the processor was last called for reconciliation
* Negative if never reconciled
*/
readonly reconciliationId: number;
/**
* Notify a property change on one of the objects that the processors
* registered in its object dependency set
* @param objId
* @param propName
* @returns true if the processor turned dirty
*/
notifyChange(objId: string, propName: string): boolean;
/**
* Register a dependency on this processor
* (Call will be ignored if the processor is not processing)
* @param object
* @param objectID
* @param propName
*/
registerDependency(object: any, objectID: string, propName: string): void;
/**
* Re-execute the processor compute function if necessary (i.e. dirty)
* @param trigger the reason that triggered the call to process
* - Init = processor creation
* - Reconcialiation = call made by trax at the end of each cycle (cf. processChanges)
* - TargetRead = (for processors associated to an object cf. store.add) call made when a property from the target is being read
* - DirectCall = explicit call (usually made by processors that are not auto-computed)
*/
compute(forceExecution?: boolean, trigger?: "Init" | "Reconciliation" | "TargetRead" | "DirectCall", reconciliationIdx?: number): void;
/**
* Update the compute function associated to a processor (allows to get access to different closure variables)
* @param fn
*/
updateComputeFn(fn: TraxComputeFn | TraxObjectComputeFn<any>): void;
}
export declare function createTraxProcessor<T>(processorId: string, processorName: string, priority: number, compute: TraxComputeFn | TraxObjectComputeFn<T>, processorStack: LinkedList<TraxInternalProcessor>, getDataObject: (id: string) => any, logTraxEvent: (e: TraxEvent) => void, startProcessingContext: (event: TraxLogTraxProcessingCtxt) => ProcessingContext,
/** Object associated to this processor */
target: T | null, onDispose?: (id: string) => void, autoCompute?: boolean, isRenderer?: boolean): TraxInternalProcessor;