import CompositeClosureHelper from 'paraviewweb/src/Common/Core/CompositeClosureHelper';
function busyMonitor(publicAPI, model) { model.busyCounter = 0;
const checkNotifyStatus = (delta) => { const lastCount = model.busyCounter; model.busyCounter += delta; if (model.busyCounter <= 0) { publicAPI.fireBusyStatusChanged(false); model.busyCounter = 0; } else if (lastCount === 0 && model.busyCounter > 0) { publicAPI.fireBusyStatusChanged(true); } };
const success = (args) => { checkNotifyStatus(-1); return Promise.resolve(args); };
const error = (args) => { checkNotifyStatus(-1); return Promise.reject(args); };
publicAPI.busy = (promise) => { checkNotifyStatus(1); return promise.then(success, error); };
publicAPI.busyWrapFunction = (fn) => (...args) => publicAPI.busy(fn(...args));
publicAPI.isBusy = () => model.busyCounter > 0; }
const DEFAULT_VALUES = {};
export function extend(publicAPI, model, initialValues = {}) { Object.assign(model, DEFAULT_VALUES, initialValues);
CompositeClosureHelper.destroy(publicAPI, model); CompositeClosureHelper.event(publicAPI, model, 'busyStatusChanged');
busyMonitor(publicAPI, model); }
export const newInstance = CompositeClosureHelper.newInstance(extend);
export default { newInstance, extend };
|