Skip to main content
Version: Next

SnapshotStore <T>

A time-pruning, time-windowed store for LoadSnapshot values. Signals compose with this instead of inheriting from a base class.

Index

Constructors

constructor

Methods

getAll

  • getAll(): T[]
  • Direct access to the underlying array (for backward-compat getters).


    Returns T[]

getSample

  • getSample(sampleDurationMillis): T[]
  • Return all snapshots, or only those within the given time window.


    Parameters

    • optionalsampleDurationMillis: number

    Returns T[]

push

  • push(snapshot, now): void
  • Add a snapshot and prune entries older than the history window.


    Parameters

    • snapshot: T
    • now: Date = snapshot.createdAt

    Returns void

staticfromEvent

  • fromEvent<T, E>(options): Omit<LoadSignal, getSample> & { handle: (payload) => void; store: SnapshotStore<T>; getSample: any }
  • Create a LoadSignal that snapshots in response to an EventManager event.

    The handler receives the event payload and the store. It should call store.push() to record a snapshot.


    Parameters

    • options: { event: EventTypeName; events: EventManager; handler: (store, payload) => void; name: string; overloadedRatio: number; snapshotHistoryMillis?: number }
      • event: EventTypeName
      • events: EventManager
      • handler: (store, payload) => void
      • name: string
      • overloadedRatio: number
      • optionalsnapshotHistoryMillis: number

    Returns Omit<LoadSignal, getSample> & { handle: (payload) => void; store: SnapshotStore<T>; getSample: any }

staticfromInterval

  • fromInterval<T>(options): Omit<LoadSignal, getSample> & { handle: (cb) => void; store: SnapshotStore<T>; getSample: any }
  • Create a LoadSignal that snapshots on a betterSetInterval tick.

    The handler receives the store (to read previous snapshots) and the interval callback (which it must call when done). It should call store.push() to record a snapshot.


    Parameters

    • options: { handler: (store, intervalCallback) => void; intervalMillis: number; name: string; overloadedRatio: number; snapshotHistoryMillis?: number }
      • handler: (store, intervalCallback) => void
      • intervalMillis: number
      • name: string
      • overloadedRatio: number
      • optionalsnapshotHistoryMillis: number

    Returns Omit<LoadSignal, getSample> & { handle: (cb) => void; store: SnapshotStore<T>; getSample: any }