@adpt/cloud
Version:
AdaptJS cloud component library
72 lines • 2.3 kB
TypeScript
import { BuildData, ChangeType, FinalDomElement, PrimitiveComponent } from "@adpt/core";
import { MessageLogger } from "@adpt/utils";
/**
* Detailed information on why an action should be taken.
* @public
*/
export interface ShouldActDetail {
/**
* True if the action should be performed.
*/
act: boolean;
/**
* Explanation of why the action should be performed.
*/
detail: string;
}
/**
* Return type for {@link action.Action.shouldAct} that describes whether an
* action should be taken and why.
* @public
*/
export declare type ShouldAct = false | ShouldActDetail;
/**
* Type guard for {@link action.ShouldActDetail}.
* @public
*/
export declare function isShouldActDetail(val: any): val is ShouldActDetail;
/**
* Transforms a {@link action.ShouldAct} into an {@link action.ShouldActDetail}.
* @internal
*/
export declare function toDetail(val: ShouldAct): {
act: boolean;
detail: string;
};
/**
* Helper information for an {@link action.Action} component.
* @public
*/
export interface ActionContext {
/** Various pieces of data about the current element and build cycle */
buildData: BuildData;
/** A location to put files that need to be persisted as state */
dataDir: string;
/** Interface to use for logging messages. Prefer to using stderr or stdout */
logger: MessageLogger;
}
/**
* Component that can be inherited to perform actions during deploy
*
* @public
*/
export declare class Action<P extends object = {}, S extends object = {}> extends PrimitiveComponent<P, S> {
/**
* Calculates whether or not any action is needed based on state/props/observation
*
* @returns false if no action needed, `{ act: true, detail: <user-facing description of action> }`.
*/
shouldAct(_op: ChangeType, _ctx: ActionContext): ShouldAct | Promise<ShouldAct>;
action(_op: ChangeType, _ctx: ActionContext): void | Promise<void>;
}
/**
* Type guard for Action FinalDomElements.
* @internal
*/
export declare function isActionFinalElement(val: any): val is FinalDomElement;
/**
* Returns the component instance for an {@link action.Action} component.
* @internal
*/
export declare function getActionInstance(el: FinalDomElement): Action | null;
//# sourceMappingURL=Action.d.ts.map