Skip to content

Commit 3de88c3

Browse files
committed
ref: Split into files
1 parent 8e57c80 commit 3de88c3

File tree

6 files changed

+696
-644
lines changed

6 files changed

+696
-644
lines changed

packages/replay/src/replay.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { handleKeyboardEvent } from './coreHandlers/handleKeyboardEvent';
1818
import { setupPerformanceObserver } from './coreHandlers/performanceObserver';
1919
import { createEventBuffer } from './eventBuffer';
2020
import { clearSession } from './session/clearSession';
21-
import { loadOrCreateSession, maybeRefreshSession } from './session/getSession';
21+
import { loadOrCreateSession } from './session/loadOrCreateSession';
22+
import { maybeRefreshSession } from './session/maybeRefreshSession';
2223
import { saveSession } from './session/saveSession';
2324
import type {
2425
AddEventResult,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Session, SessionOptions, Timeouts } from '../types';
2+
import { logInfoNextTick } from '../util/log';
3+
import { createSession } from './createSession';
4+
import { fetchSession } from './fetchSession';
5+
import { maybeRefreshSession } from './maybeRefreshSession';
6+
7+
/**
8+
* Get or create a session, when initializing the replay.
9+
* Returns a session that may be unsampled.
10+
*/
11+
export function loadOrCreateSession(
12+
currentSession: Session | undefined,
13+
{
14+
timeouts,
15+
traceInternals,
16+
}: {
17+
timeouts: Timeouts;
18+
traceInternals?: boolean;
19+
},
20+
sessionOptions: SessionOptions,
21+
): Session {
22+
// If session exists and is passed, use it instead of always hitting session storage
23+
const existingSession = currentSession || (sessionOptions.stickySession && fetchSession(traceInternals));
24+
25+
// No session exists yet, just create a new one
26+
if (!existingSession) {
27+
logInfoNextTick('[Replay] Created new session', traceInternals);
28+
return createSession(sessionOptions);
29+
}
30+
31+
return maybeRefreshSession(existingSession, { timeouts, traceInternals }, sessionOptions);
32+
}

packages/replay/src/session/getSession.ts renamed to packages/replay/src/session/maybeRefreshSession.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Session, SessionOptions, Timeouts } from '../types';
22
import { isSessionExpired } from '../util/isSessionExpired';
33
import { logInfoNextTick } from '../util/log';
44
import { createSession } from './createSession';
5-
import { fetchSession } from './fetchSession';
65
import { makeSession } from './Session';
76

87
/**
@@ -47,30 +46,3 @@ export function maybeRefreshSession(
4746

4847
return newSession;
4948
}
50-
51-
/**
52-
* Get or create a session, when initializing the replay.
53-
* Returns a session that may be unsampled.
54-
*/
55-
export function loadOrCreateSession(
56-
currentSession: Session | undefined,
57-
{
58-
timeouts,
59-
traceInternals,
60-
}: {
61-
timeouts: Timeouts;
62-
traceInternals?: boolean;
63-
},
64-
sessionOptions: SessionOptions,
65-
): Session {
66-
// If session exists and is passed, use it instead of always hitting session storage
67-
const existingSession = currentSession || (sessionOptions.stickySession && fetchSession(traceInternals));
68-
69-
// No session exists yet, just create a new one
70-
if (!existingSession) {
71-
logInfoNextTick('[Replay] Created new session', traceInternals);
72-
return createSession(sessionOptions);
73-
}
74-
75-
return maybeRefreshSession(existingSession, { timeouts, traceInternals }, sessionOptions);
76-
}

0 commit comments

Comments
 (0)