From f921850e1045da86a129e445964fea488e050cbf Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 23 Jun 2022 17:00:33 -0400 Subject: [PATCH] ref(hub): Reduce hub bundle size Move field initializers inside constructor to reduce bundle size. --- packages/hub/src/scope.ts | 45 +++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/packages/hub/src/scope.ts b/packages/hub/src/scope.ts index a469695ffe45..34e9057d6cc9 100644 --- a/packages/hub/src/scope.ts +++ b/packages/hub/src/scope.ts @@ -44,28 +44,37 @@ const MAX_BREADCRUMBS = 100; */ export class Scope implements ScopeInterface { /** Flag if notifying is happening. */ - protected _notifyingListeners: boolean = false; + protected _notifyingListeners: boolean; /** Callback for client to receive scope changes. */ - protected _scopeListeners: Array<(scope: Scope) => void> = []; + protected _scopeListeners: Array<(scope: Scope) => void>; /** Callback list that will be called after {@link applyToEvent}. */ - protected _eventProcessors: EventProcessor[] = []; + protected _eventProcessors: EventProcessor[]; /** Array of breadcrumbs. */ - protected _breadcrumbs: Breadcrumb[] = []; + protected _breadcrumbs: Breadcrumb[]; /** User */ - protected _user: User = {}; + protected _user: User; /** Tags */ - protected _tags: { [key: string]: Primitive } = {}; + protected _tags: { [key: string]: Primitive }; /** Extra */ - protected _extra: Extras = {}; + protected _extra: Extras; /** Contexts */ - protected _contexts: Contexts = {}; + protected _contexts: Contexts; + + /** Attachments */ + protected _attachments: Attachment[]; + + /** + * A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get + * sent to Sentry + */ + protected _sdkProcessingMetadata: { [key: string]: unknown }; /** Fingerprint */ protected _fingerprint?: string[]; @@ -86,14 +95,18 @@ export class Scope implements ScopeInterface { /** Request Mode Session Status */ protected _requestSession?: RequestSession; - /** Attachments */ - protected _attachments: Attachment[] = []; - - /** - * A place to stash data which is needed at some point in the SDK's event processing pipeline but which shouldn't get - * sent to Sentry - */ - protected _sdkProcessingMetadata?: { [key: string]: unknown } = {}; + public constructor() { + this._notifyingListeners = false; + this._scopeListeners = []; + this._eventProcessors = []; + this._breadcrumbs = []; + this._attachments = []; + this._user = {}; + this._tags = {}; + this._extra = {}; + this._contexts = {}; + this._sdkProcessingMetadata = {}; + } /** * Inherit values from the parent scope.