UNPKG

@airplane/views

Version:

A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.

43 lines (42 loc) 1.66 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; import { jsx } from "react/jsx-runtime"; import { createContext } from "react"; import { RUNNER_SCALE_SIGNAL_CREATE } from "../../client/endpoints.js"; import { Fetcher } from "../../client/fetcher.js"; class RunnerScaleSignalContextType { constructor() { __publicField(this, "lastSent"); this.lastSent = /* @__PURE__ */ new Map(); this.createScaleSignal = this.createScaleSignal.bind(this); } getMapKey(signal) { return signal.signalKey + "~" + signal.taskSlug; } async createScaleSignal(signal) { const mapKey = this.getMapKey(signal); const lastSentDate = this.lastSent.get(mapKey); const now = /* @__PURE__ */ new Date(); if (!lastSentDate || new Date(now.getTime() - 60 * 1e3) > lastSentDate) { this.lastSent.set(mapKey, now); const fetcher = new Fetcher(); await fetcher.post(RUNNER_SCALE_SIGNAL_CREATE, signal); } } } const RunnerScaleSignalContext = /* @__PURE__ */ createContext(new RunnerScaleSignalContextType()); const RunnerScaleSignalProvider = ({ children }) => { return /* @__PURE__ */ jsx(RunnerScaleSignalContext.Provider, { value: new RunnerScaleSignalContextType(), children }); }; export { RunnerScaleSignalContext, RunnerScaleSignalContextType, RunnerScaleSignalProvider }; //# sourceMappingURL=RunnerScaleSignalProvider.js.map