Options
All
  • Public
  • Public/Protected
  • All
Menu

@paychex/collector-batch

Provides a customizable batch collector that can be used with @paychex/core Tracker.

esm

import { batch } from '@paychex/collector-batch';

cjs

const { batch } = require('@paychex/collector-batch');

amd

define(['@paychex/collector-batch'], function({ batch }) { ... });
require(['@paychex/collector-batch'], function({ batch }) { ... });

iife

const { batch } = window['@paychex/collector-batch'];

Index

Functions

  • Provides a collector for use with @paychex/core's createTracker method that can batch TrackingInfo instances using a custom coalesce method.

    example
    // sending JSON-Patch entries to an endpoint

    import { createRequest, fetch } from '~/path/to/data/layer.js';

    const operation = {
    method: 'PATCH',
    base: 'my-endpoint',
    path: '/analytics/tracking',
    ignore: {
    tracking: true,
    traceability: true,
    }
    };

    async function send(payload) {
    await fetch(createRequest(operation, null, payload));
    }

    const collector = batch(send, utils.toPatch);
    export const tracker = trackers.create(collector);
    example
    // collect all items received within 5-second intervals

    async function send(payload) { ... }

    const signal = signals.autoReset(false);
    const collector = functions.buffer(batch(send), [signal]);

    setInterval(signal.set, 5000);

    export const tracker = trackers.create(collector);

    Type parameters

    • T = TrackingInfo

      The type of object in the array passed to your send method.

    Parameters

    • send: SendFunction<T>

      A method to invoke with the batch payload.

    • coalesce: CoalesceFunction<T> = identity

      An optional method to invoke to convert an Array of TrackingInfo instances into a payload to pass to the send method.

    Returns TrackingSubscriber

    A collector that batches all TrackingInfo instances passed to the collector within a particular stack frame.