UNPKG

@data-client/core

Version:

Async State Management without the Management. REST, GraphQL, SSE, Websockets, Fetch

41 lines 1.61 kB
import Controller from '../controller/Controller.js'; import type { Manager, Middleware, UnsubscribeAction, SubscribeAction } from '../types.js'; type Actions = UnsubscribeAction | SubscribeAction; /** Interface handling a single resource subscription */ export interface Subscription { add(frequency?: number): void; remove(frequency?: number): boolean; cleanup(): void; } /** The static class that constructs Subscription */ export interface SubscriptionConstructable { new (action: Omit<SubscribeAction, 'type'>, controller: Controller): Subscription; } /** Handles subscription actions -> fetch or set actions * * Constructor takes a SubscriptionConstructable class to control how * subscriptions are handled. (e.g., polling, websockets) * * @see https://dataclient.io/docs/api/SubscriptionManager */ export default class SubscriptionManager<S extends SubscriptionConstructable = SubscriptionConstructable> implements Manager<Actions> { protected subscriptions: { [key: string]: InstanceType<S>; }; protected readonly Subscription: S; protected controller: Controller; constructor(Subscription: S); middleware: Middleware; /** Ensures all subscriptions are cleaned up. */ cleanup(): void; /** Called when middleware intercepts 'rdc/subscribe' action. * */ protected handleSubscribe(action: SubscribeAction): void; /** Called when middleware intercepts 'rdc/unsubscribe' action. * */ protected handleUnsubscribe(action: UnsubscribeAction): void; } export {}; //# sourceMappingURL=SubscriptionManager.d.ts.map