UNPKG

@tanstack/query-core

Version:

The framework agnostic core that powers TanStack Query

99 lines (98 loc) 2.6 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/notifyManager.ts var notifyManager_exports = {}; __export(notifyManager_exports, { createNotifyManager: () => createNotifyManager, notifyManager: () => notifyManager }); module.exports = __toCommonJS(notifyManager_exports); var import_utils = require("./utils.cjs"); function createNotifyManager() { let queue = []; let transactions = 0; let notifyFn = (callback) => { callback(); }; let batchNotifyFn = (callback) => { callback(); }; const batch = (callback) => { let result; transactions++; try { result = callback(); } finally { transactions--; if (!transactions) { flush(); } } return result; }; const schedule = (callback) => { if (transactions) { queue.push(callback); } else { (0, import_utils.scheduleMicrotask)(() => { notifyFn(callback); }); } }; const batchCalls = (callback) => { return (...args) => { schedule(() => { callback(...args); }); }; }; const flush = () => { const originalQueue = queue; queue = []; if (originalQueue.length) { (0, import_utils.scheduleMicrotask)(() => { batchNotifyFn(() => { originalQueue.forEach((callback) => { notifyFn(callback); }); }); }); } }; const setNotifyFunction = (fn) => { notifyFn = fn; }; const setBatchNotifyFunction = (fn) => { batchNotifyFn = fn; }; return { batch, batchCalls, schedule, setNotifyFunction, setBatchNotifyFunction }; } var notifyManager = createNotifyManager(); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createNotifyManager, notifyManager }); //# sourceMappingURL=notifyManager.cjs.map