-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscope.ts
More file actions
50 lines (43 loc) · 1.23 KB
/
scope.ts
File metadata and controls
50 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { BugSplat, BugSplatAttachment } from 'bugsplat';
/**
* Builds the componentStack attachment for ErrorBoundary posts.
*/
export type CreateComponentStackAttachment = (
componentStack: string
) => BugSplatAttachment;
/**
* Default builder — wraps the stack in a `text/plain` `Blob`.
*/
export const defaultCreateComponentStackAttachment: CreateComponentStackAttachment = (
componentStack
) => ({
filename: 'componentStack.txt',
data: new Blob([componentStack], { type: 'text/plain' }),
});
/**
* Encapsulate BugSplat client instance and scope-level overrides.
*/
export class Scope {
constructor(
private client: BugSplat | null = null,
private createComponentStackAttachment: CreateComponentStackAttachment = defaultCreateComponentStackAttachment
) {}
/**
* @returns BugSplat client instance or null if unset
*/
getClient() {
return this.client;
}
setClient(client: BugSplat) {
this.client = client;
}
/**
* @returns the current componentStack attachment builder
*/
getCreateComponentStackAttachment() {
return this.createComponentStackAttachment;
}
setCreateComponentStackAttachment(fn: CreateComponentStackAttachment) {
this.createComponentStackAttachment = fn;
}
}