UNPKG

piral-tracker

Version:

Plugin for registering always-on components in Piral.

33 lines 1.14 kB
import * as actions from './actions'; import { buildName, withApi } from 'piral-core'; /** * Creates the Pilet API extension for activating tracker support. */ export function createTrackerApi(config = {}) { return (context) => { context.defineActions(actions); return (api, target) => { const pilet = target.name; let next = 0; return { registerTracker(name, arg) { if (typeof name !== 'string') { arg = name; name = next++; } const id = buildName(pilet, name); context.registerTracker(id, { pilet, component: withApi(context, arg, api, 'tracker'), }); return () => api.unregisterTracker(name); }, unregisterTracker(name) { const id = buildName(pilet, name); context.unregisterTracker(id); }, }; }; }; } //# sourceMappingURL=create.js.map