32 lines
925 B
JavaScript
32 lines
925 B
JavaScript
export function createSessionLiveState() {
|
|||
|
|
return {
|
||
|
|
dirtySessions: new Set(),
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
export const sessionLiveState = createSessionLiveState();
|
||
|
|
|
||
|
|
export function noteSessionUpdated(live, sessionId, currentSessionId = null) {
|
||
|
|
if (!sessionId) return { reload: false, sessionId: null };
|
||
|
|
if (sessionId === currentSessionId) {
|
||
|
|
live.dirtySessions.delete(sessionId);
|
||
|
|
return { reload: true, sessionId };
|
||
|
|
}
|
||
|
|
live.dirtySessions.add(sessionId);
|
||
|
|
return { reload: false, sessionId };
|
||
|
|
}
|
||
|
|
|
||
|
|
export function clearSessionDirty(sessionId, live = sessionLiveState) {
|
||
|
|
if (sessionId) live.dirtySessions.delete(sessionId);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function consumeSessionDirty(live, sessionId) {
|
||
|
|
if (!sessionId || !live.dirtySessions.has(sessionId)) return false;
|
||
|
|
live.dirtySessions.delete(sessionId);
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function consumeGlobalSessionDirty(sessionId) {
|
||
|
|
return consumeSessionDirty(sessionLiveState, sessionId);
|
||
|
|
}
|