// Metro module 593 (f594). import { Logger } from "./log"; import { serialize } from "./Module594"; let c536_2 = new Logger("Flux"); let batchEmitChanges2 = (a0) => a0(); class Emitter { constructor() { const r8 = { __proto__: new.target.prototype, changedStores: new Set(), reactChangedStores: null, changeSentinel: 0, isBatchEmitting: false, isDispatching: false, isPaused: false, pauseTimer: null }; r8.reactChangedStores = new Set(); return r8; } destroy() { this.changedStores.clear(); this.reactChangedStores.clear(); batchEmitChanges2 = (a0) => a0(); } injectBatchEmitChanges(a0) { batchEmitChanges2 = a0; } pause(r5 = null) { this.isPaused = true; if (this.pauseTimer !== null) { clearTimeout(this.pauseTimer); } if (r5 !== null) { this.pauseTimer = setTimeout(() => { this.pauseTimer = null; this.resume(); }, r5); } } resume(r5 = true) { clearTimeout(this.pauseTimer); this.pauseTimer = null; if (this.isPaused) { this.isPaused = false; if (r5) { r5 = this.changedStores.size > 0; } if (r5) { setImmediate(() => this.emit()); } } } batched(a0) { let r7; if (this.isPaused) { return a0(); } try { this.isPaused = true; r7 = a0(); } catch (r11) { this.resume(false); this.emit(); throw r11; } this.resume(false); this.emit(); return r7; } emit() { if (!(this.isBatchEmitting || this.isPaused)) { batchEmitChanges2(() => { let r1, r32, r42; try { r1 = this; this.isBatchEmitting = true; this.changeSentinel = this.changeSentinel + 1; let r18 = 0; const set = new Set(); const set2 = new Set(); if (this.changedStores.size > 0) { do { const r31 = r18 + 1; r18 = r31; if (100 < r31) { c536_2.error("LastFewActions", serialize()); throw Error("change emit loop detected, aborting"); } r32 = this; r1 = r32; r32.emitNonReactOnce(set, set2); } while (r32.changedStores.size > 0); } if (r1.reactChangedStores.size > 0) { do { const r41 = r18 + 1; r18 = r41; if (100 < r41) { c536_2.error("LastFewActions", serialize()); throw Error("react change emit loop detected, aborting"); } r42 = this; r1 = r42; r42.emitReactOnce(); } while (r42.reactChangedStores.size > 0); } } catch (r77) { this.isBatchEmitting = false; throw r77; } r1.isBatchEmitting = false; }); } } getChangeSentinel() { return this.changeSentinel; } getIsPaused() { return this.isPaused; } markChanged(a0) { if (a0._changeCallbacks.hasAny() || a0._syncWiths.length > 0) { this.changedStores.add(a0); } if (a0._reactChangeCallbacks.hasAny()) { this.reactChangedStores.add(a0); } if (!(this.isBatchEmitting || this.isDispatching || this.isPaused)) { this.emit(); } } emitNonReactOnce(c12394_1, c12394_0) { const r7 = Date.now(); const changedStores = this.changedStores; this.changedStores = new Set(); changedStores.forEach((changedStore) => { c12394_0.add(changedStore); changedStore._changeCallbacks.invokeAll(); this.changedStores.delete(changedStore); }); changedStores.forEach((changedStore) => { changedStore._syncWiths.forEach(({ func, store }) => { if (!c12394_1.has(func)) { c12394_1.add(func); if (func() !== false) { if (!c12394_0.has(store)) { c12394_0.add(store); this.markChanged(store); } } } }); }); const r26 = Date.now(); if (r26 - r7 > 100) { c536_2.verbose(`Slow batch emitChanges took ${r26 - r7}ms recentActions:`, serialize()); } } emitReactOnce() { const r7 = Date.now(); const reactChangedStores = this.reactChangedStores; this.reactChangedStores = new Set(); reactChangedStores.forEach((reactChangedStore) => { reactChangedStore._reactChangeCallbacks.invokeAll(); this.reactChangedStores.delete(reactChangedStore); }); const r21 = Date.now(); if (r21 - r7 > 100) { c536_2.verbose(`Slow batch emitReactChanges took ${r21 - r7}ms recentActions:`, serialize()); } } } const r54 = { __proto__: Emitter.prototype, changedStores: new Set(), reactChangedStores: null, changeSentinel: 0, isBatchEmitting: false, isDispatching: false, isPaused: false, pauseTimer: null }; r54.reactChangedStores = new Set(); export default r54;