-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Collect user data telemetry Refacto common context
- Loading branch information
1 parent
68befc3
commit 35ec6d7
Showing
34 changed files
with
647 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,60 @@ | ||
import { deepClone } from './utils' | ||
|
||
import { computeBytesCount, deepClone, jsonStringify } from './utils' | ||
import type { Context, ContextValue } from './context' | ||
|
||
export function createContextManager() { | ||
export type ContextManager = ReturnType<typeof createContextManager> | ||
|
||
export function createContextManager(computeBytesCountImpl = computeBytesCount) { | ||
let context: Context = {} | ||
let bytesCountCache: number | undefined | ||
|
||
return { | ||
getBytesCount: () => { | ||
if (bytesCountCache === undefined) { | ||
bytesCountCache = computeBytesCountImpl(jsonStringify(context)!) | ||
} | ||
return bytesCountCache | ||
}, | ||
/** @deprecated use getContext instead */ | ||
get: () => context, | ||
|
||
/** @deprecated use setContextProperty instead */ | ||
add: (key: string, value: any) => { | ||
context[key] = value as ContextValue | ||
bytesCountCache = undefined | ||
}, | ||
|
||
/** @deprecated renamed to removeContextProperty */ | ||
remove: (key: string) => { | ||
delete context[key] | ||
bytesCountCache = undefined | ||
}, | ||
|
||
/** @deprecated use setContext instead */ | ||
set: (newContext: object) => { | ||
context = newContext as Context | ||
bytesCountCache = undefined | ||
}, | ||
|
||
getContext: () => deepClone(context), | ||
|
||
setContext: (newContext: Context) => { | ||
context = deepClone(newContext) | ||
bytesCountCache = undefined | ||
}, | ||
|
||
setContextProperty: (key: string, property: any) => { | ||
context[key] = deepClone(property) | ||
bytesCountCache = undefined | ||
}, | ||
|
||
removeContextProperty: (key: string) => { | ||
delete context[key] | ||
bytesCountCache = undefined | ||
}, | ||
|
||
clearContext: () => { | ||
context = {} | ||
bytesCountCache = undefined | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { HttpRequest, createHttpRequest, Payload, RetryInfo } from './httpRequest' | ||
export { Batch } from './batch' | ||
export { Batch, BatchFlushEvent } from './batch' | ||
export { canUseEventBridge, getEventBridge, BrowserWindowWithEventBridge } from './eventBridge' | ||
export { startBatchWithReplica } from './startBatchWithReplica' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.