Skip to main content

@c-a-f/core — Public API

The @c-a-f/core package exports domain-agnostic primitives and interfaces.

Exports overview

ExportKindDescription
UseCaseInterfaceContract for application use cases
PlocClassPresentation logic container with reactive state
PulseClassObservable value container
pulseFunctionFactory for creating a Pulse instance
ApiRequestClassWraps an async request with loading/data/error state
RouteManagerClassCoordinates routing; optional auth via RouteManagerAuthOptions
RouteManagerAuthOptionsInterfaceOptional auth config for login redirect
RouteRepositoryInterfaceAbstraction for the routing system
RequestResultTypeShape of loading/data/error for use cases
IRequest, IRequestHandlerType / InterfaceAsync request types
IApiClient, ApiRequestConfig, ApiResponse, ApiErrorInterfaceAPI client and response types
extractApiData, normalizeApiErrorFunctionHelpers for API responses and errors
PromiseRequestHandler, toRequestHandlerClass / FunctionAdapters for request handlers

UseCase

interface UseCase<A extends any[], T> {
execute: (...args: A) => Promise<RequestResult<T>>;
}

Ploc

abstract class Ploc<S> {
constructor(initialState: S);
get state(): S;
changeState(state: S): void;
subscribe(listener: (state: S) => void): void;
unsubscribe(listener: (state: S) => void): void;
}

Pulse and pulse

function pulse<T>(initialValue: T): Pulse<T> & { value: T };
// Pulse: .value, .subscribe(), .unsubscribe()

RequestResult

type RequestResult<T> = {
loading: Pulse<boolean> & { value: boolean };
data: Pulse<T> & { value: T };
error: Pulse<Error> & { value: Error };
};

RouteRepository and RouteManager

interface RouteRepository {
currentRoute: string;
change(route: string): void;
}

class RouteManager {
constructor(routingSystem: RouteRepository, authOptions?: RouteManagerAuthOptions);
checkForLoginRoute(): void;
isUserLoggedIn(): boolean;
changeRoute(route: string): void;
}

For the full API with examples, see the API.md file in the repository.