refactor options initialization to be more verbose
This commit is contained in:
parent
40a22efd56
commit
fa44300281
7 changed files with 59 additions and 33 deletions
|
|
@ -335,17 +335,25 @@ export default class App {
|
|||
this.revID = this.options.revID
|
||||
this.localStorage = this.options.localStorage ?? window.localStorage
|
||||
this.sessionStorage = this.options.sessionStorage ?? window.sessionStorage
|
||||
this.sanitizer = new Sanitizer(this, options)
|
||||
this.nodes = new Nodes(this.options.node_id, Boolean(options.angularMode))
|
||||
this.observer = new Observer(this, options)
|
||||
this.sanitizer = new Sanitizer({ app: this, options })
|
||||
this.nodes = new Nodes({
|
||||
node_id: this.options.node_id,
|
||||
angularMode: Boolean(options.angularMode),
|
||||
})
|
||||
this.observer = new Observer({ app: this, options })
|
||||
this.ticker = new Ticker(this)
|
||||
this.ticker.attach(() => this.commit())
|
||||
this.debug = new Logger(this.options.__debug__)
|
||||
this.session = new Session(this, this.options)
|
||||
this.attributeSender = new AttributeSender(this, Boolean(this.options.disableStringDict))
|
||||
this.session = new Session({ app: this, options: this.options })
|
||||
this.attributeSender = new AttributeSender({
|
||||
app: this,
|
||||
isDictDisabled: Boolean(this.options.disableStringDict || this.options.crossdomain?.enabled),
|
||||
})
|
||||
this.featureFlags = new FeatureFlags(this)
|
||||
this.tagWatcher = new TagWatcher(this.sessionStorage, this.debug.error, (tag) => {
|
||||
this.send(TagTrigger(tag) as Message)
|
||||
this.tagWatcher = new TagWatcher({
|
||||
sessionStorage: this.sessionStorage,
|
||||
errLog: this.debug.error,
|
||||
onTag: (tag) => this.send(TagTrigger(tag) as Message),
|
||||
})
|
||||
this.session.attachUpdateCallback(({ userID, metadata }) => {
|
||||
if (userID != null) {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ export default class Nodes {
|
|||
private readonly nodeCallbacks: Array<NodeCallback> = []
|
||||
private readonly elementListeners: Map<number, Array<ElementListener>> = new Map()
|
||||
private nextNodeId = 0
|
||||
private readonly node_id: string
|
||||
private readonly angularMode: boolean
|
||||
|
||||
constructor(
|
||||
private readonly node_id: string,
|
||||
private readonly angularMode: boolean,
|
||||
) {}
|
||||
constructor(params: { node_id: string; angularMode: boolean }) {
|
||||
this.node_id = params.node_id
|
||||
this.angularMode = params.angularMode
|
||||
}
|
||||
|
||||
syntheticMode(frameOrder: number) {
|
||||
const maxSafeNumber = Number.MAX_SAFE_INTEGER
|
||||
|
|
@ -36,7 +38,12 @@ export default class Nodes {
|
|||
this.nodes.forEach((node) => cb(node))
|
||||
}
|
||||
|
||||
attachNodeListener = (node: Node, type: string, listener: EventListener, useCapture = true): void => {
|
||||
attachNodeListener = (
|
||||
node: Node,
|
||||
type: string,
|
||||
listener: EventListener,
|
||||
useCapture = true,
|
||||
): void => {
|
||||
const id = this.getID(node)
|
||||
if (id === undefined) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -21,14 +21,16 @@ const attachShadowNativeFn = IN_BROWSER ? Element.prototype.attachShadow : () =>
|
|||
export default class TopObserver extends Observer {
|
||||
private readonly options: Options
|
||||
private readonly iframeOffsets: IFrameOffsets = new IFrameOffsets()
|
||||
readonly app: App
|
||||
|
||||
constructor(app: App, options: Partial<Options>) {
|
||||
super(app, true)
|
||||
constructor(params: { app: App; options: Partial<Options> }) {
|
||||
super(params.app, true)
|
||||
this.app = params.app
|
||||
this.options = Object.assign(
|
||||
{
|
||||
captureIFrames: true,
|
||||
},
|
||||
options,
|
||||
params.options,
|
||||
)
|
||||
|
||||
// IFrames
|
||||
|
|
|
|||
|
|
@ -23,17 +23,16 @@ export default class Sanitizer {
|
|||
private readonly obscured: Set<number> = new Set()
|
||||
private readonly hidden: Set<number> = new Set()
|
||||
private readonly options: Options
|
||||
private readonly app: App
|
||||
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
options: Partial<Options>,
|
||||
) {
|
||||
constructor(params: { app: App; options?: Partial<Options> }) {
|
||||
this.app = params.app
|
||||
this.options = Object.assign(
|
||||
{
|
||||
obscureTextEmails: true,
|
||||
obscureTextNumbers: false,
|
||||
},
|
||||
options,
|
||||
params.options,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,11 +35,13 @@ export default class Session {
|
|||
private tabId: string
|
||||
public userInfo: UserInfo
|
||||
private token: string | undefined
|
||||
private readonly app: App
|
||||
private readonly options: Options
|
||||
|
||||
constructor(params: { app: App; options: Options }) {
|
||||
this.app = params.app
|
||||
this.options = params.options
|
||||
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private readonly options: Options,
|
||||
) {
|
||||
this.createTabId()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,13 @@ export class StringDictionary {
|
|||
|
||||
export default class AttributeSender {
|
||||
private dict = new StringDictionary()
|
||||
private readonly app: App
|
||||
private readonly isDictDisabled: boolean
|
||||
|
||||
constructor(
|
||||
private readonly app: App,
|
||||
private readonly isDictDisabled: boolean,
|
||||
) {}
|
||||
constructor(options: { app: App; isDictDisabled: boolean }) {
|
||||
this.app = options.app
|
||||
this.isDictDisabled = options.isDictDisabled
|
||||
}
|
||||
|
||||
public sendSetAttribute(id: number, name: string, value: string) {
|
||||
if (this.isDictDisabled) {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,18 @@ class TagWatcher {
|
|||
intervals: Record<string, ReturnType<typeof setInterval>> = {}
|
||||
tags: { id: number; selector: string }[] = []
|
||||
observer: IntersectionObserver
|
||||
private readonly sessionStorage: Storage
|
||||
private readonly errLog: (args: any[]) => void
|
||||
private readonly onTag: (tag: number) => void
|
||||
|
||||
constructor(
|
||||
private readonly sessionStorage: Storage,
|
||||
private readonly errLog: (args: any[]) => void,
|
||||
private readonly onTag: (tag: number) => void,
|
||||
) {
|
||||
constructor(params: {
|
||||
sessionStorage: Storage
|
||||
errLog: (args: any[]) => void
|
||||
onTag: (tag: number) => void
|
||||
}) {
|
||||
this.sessionStorage = params.sessionStorage
|
||||
this.errLog = params.errLog
|
||||
this.onTag = params.onTag
|
||||
const tags: { id: number; selector: string }[] = JSON.parse(
|
||||
sessionStorage.getItem(WATCHED_TAGS_KEY) ?? '[]',
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue