UNPKG

@data-client/core

Version:

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

46 lines (45 loc) 1.98 kB
import { EndpointInterface } from '@data-client/normalizr'; import ConnectionListener from './ConnectionListener.js'; import { Subscription } from './SubscriptionManager.js'; import Controller from '../controller/Controller.js'; import { SubscribeAction } from '../types.js'; /** * PollingSubscription keeps a given resource updated by * dispatching a fetch at a rate equal to the minimum update * interval requested. * * @see https://dataclient.io/docs/api/PollingSubscription */ export default class PollingSubscription implements Subscription { protected readonly endpoint: EndpointInterface; protected readonly args: readonly any[]; protected readonly key: string; protected frequency: number; protected frequencyHistogram: Map<number, number>; protected controller: Controller; protected intervalId?: ReturnType<typeof setInterval>; protected lastIntervalId?: ReturnType<typeof setInterval>; protected startId?: ReturnType<typeof setTimeout>; private connectionListener; constructor(action: Pick<SubscribeAction, Exclude<keyof SubscribeAction, 'type'>>, controller: Controller, connectionListener?: ConnectionListener); /** Subscribe to a frequency */ add(frequency?: number): void; /** Unsubscribe from a frequency */ remove(frequency?: number): boolean; /** Cleanup means clearing out background interval. */ cleanup(): void; /** Trigger request for latest resource */ protected update(): void; /** What happens when browser goes offline */ protected offlineListener: () => void; /** What happens when browser comes online */ protected onlineListener: () => void; /** Run polling process with current frequency * * Will clean up old poll interval on next run */ protected run(): void; /** Last fetch time */ protected lastFetchTime(): number; } //# sourceMappingURL=PollingSubscription.d.ts.map