MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / _attachTo

Function _attachTo

packages/feedback/src/core/integration.ts:281–315  ·  view source on GitHub ↗
(el: Element | string, optionOverrides: OverrideFeedbackConfiguration = {})

Source from the content-addressed store, hash-verified

279 };
280
281 const _attachTo = (el: Element | string, optionOverrides: OverrideFeedbackConfiguration = {}): Unsubscribe => {
282 const mergedOptions = mergeOptions(_options, optionOverrides);
283
284 const targetEl =
285 typeof el === 'string' ? DOCUMENT.querySelector(el) : typeof el.addEventListener === 'function' ? el : null;
286
287 if (!targetEl) {
288 DEBUG_BUILD && debug.error('[Feedback] Unable to attach to target element');
289 throw new Error('Unable to attach to target element');
290 }
291
292 let dialog: ReturnType<FeedbackModalIntegration['createDialog']> | null = null;
293 const handleClick = async (): Promise<void> => {
294 if (!dialog) {
295 dialog = await _loadAndRenderDialog({
296 ...mergedOptions,
297 onFormSubmitted: () => {
298 dialog?.removeFromDom();
299 mergedOptions.onFormSubmitted?.();
300 },
301 });
302 }
303 dialog.appendToDom();
304 dialog.open();
305 };
306 targetEl.addEventListener('click', handleClick);
307 const unsubscribe = (): void => {
308 _subscriptions = _subscriptions.filter(sub => sub !== unsubscribe);
309 dialog?.removeFromDom();
310 dialog = null;
311 targetEl.removeEventListener('click', handleClick);
312 };
313 _subscriptions.push(unsubscribe);
314 return unsubscribe;
315 };
316
317 const _createActor = (optionOverrides: OverrideFeedbackConfiguration = {}): ActorComponent => {
318 const mergedOptions = mergeOptions(_options, optionOverrides);

Callers 1

_createActorFunction · 0.85

Calls 4

mergeOptionsFunction · 0.90
pushMethod · 0.80
errorMethod · 0.65
addEventListenerMethod · 0.65

Tested by

no test coverage detected