Files
2nd/10_Wiki/Topics/Domain_Programming/Frontend/Events.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

5.4 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-events Events 10_Wiki/Topics verified self
DOM Events
Event Handling
JavaScript Events
none A 0.9 applied
frontend
dom
events
javascript
2026-05-10 pending
language framework
javascript dom

Events

매 한 줄

"매 DOM event 는 capture → target → bubble 3-phase 의 propagation". Events 는 user/system action (click, input, scroll, ...) 을 JS handler 에 dispatch 하는 mechanism. 매 modern app 의 React SyntheticEvent / addEventListener / passive listener 의 mix 의 사용.

매 핵심

매 Event Phases

  • Capture phase: root → target (top-down). { capture: true } 의 trigger.
  • Target phase: target element 의 listener.
  • Bubble phase: target → root (default). e.stopPropagation() 의 중단.

매 Event Types

  • Mouse: click, dblclick, mousedown/up, mousemove, mouseenter/leave (no bubble), mouseover/out (bubble).
  • Keyboard: keydown, keyup (NOT keypress — deprecated).
  • Touch/Pointer: pointerdown/up/move (unified mouse+touch), touchstart/move/end.
  • Form: input (every keystroke), change (commit), submit, focus/blur (no bubble), focusin/out (bubble).
  • Lifecycle: DOMContentLoaded, load, beforeunload, visibilitychange.
  • Custom: new CustomEvent('foo', { detail: {...} }).

매 응용

  1. UI interaction (button click, form submit).
  2. Event delegation (single listener for many children).
  3. Drag-and-drop (pointer events).
  4. Keyboard shortcuts / accessibility.

💻 패턴

Basic addEventListener

button.addEventListener('click', (e) => {
  console.log('clicked', e.target);
});

// removeEventListener requires same fn reference
const handler = (e) => console.log(e);
el.addEventListener('click', handler);
el.removeEventListener('click', handler);

Event Delegation

// Single listener on parent — handles all child clicks
document.querySelector('#list').addEventListener('click', (e) => {
  const item = e.target.closest('[data-id]');
  if (!item) return;
  console.log('item:', item.dataset.id);
});

Passive Listener (Scroll Performance)

// Tells browser handler won't preventDefault → no scroll-blocking
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('touchmove', onTouchMove, { passive: true });

AbortController (modern cleanup)

const ctrl = new AbortController();
el.addEventListener('click', handler, { signal: ctrl.signal });
el.addEventListener('mouseover', other, { signal: ctrl.signal });
// Remove all at once
ctrl.abort();

Stop Propagation vs Prevent Default

form.addEventListener('submit', (e) => {
  e.preventDefault();   // cancel default (form GET/POST)
  e.stopPropagation();  // don't bubble to ancestors
});

Custom Events

const evt = new CustomEvent('user:login', {
  detail: { userId: 42 },
  bubbles: true,
});
element.dispatchEvent(evt);

document.addEventListener('user:login', (e) => {
  console.log(e.detail.userId);
});

React SyntheticEvent

function Button() {
  // React pools events; e.persist() no longer needed (React 17+)
  const onClick = (e) => {
    console.log(e.nativeEvent); // underlying DOM event
    console.log(e.currentTarget);
  };
  return <button onClick={onClick}>Click</button>;
}

Pointer Events (drag)

let dragging = false;
el.addEventListener('pointerdown', (e) => {
  el.setPointerCapture(e.pointerId);
  dragging = true;
});
el.addEventListener('pointermove', (e) => {
  if (!dragging) return;
  el.style.transform = `translate(${e.clientX}px, ${e.clientY}px)`;
});
el.addEventListener('pointerup', (e) => {
  el.releasePointerCapture(e.pointerId);
  dragging = false;
});

Debounce / Throttle

function debounce(fn, ms) {
  let t;
  return (...args) => {
    clearTimeout(t);
    t = setTimeout(() => fn(...args), ms);
  };
}
input.addEventListener('input', debounce(search, 300));

매 결정 기준

상황 Approach
다수 child 의 listener Delegation (single parent listener)
Scroll/touch handler { passive: true }
다수 listener cleanup AbortController
Mouse + touch unified Pointer events
Cross-component coordination CustomEvent or state library

기본값: addEventListener + delegation + AbortController for cleanup.

🔗 Graph

🤖 LLM 활용

언제: event listener pattern 의 question, propagation 의 debug, delegation 의 implement. 언제 X: framework-specific event system 의 deep dive (React/Vue 의 own docs 의 참조).

안티패턴

  • Inline onclick="" attribute: HTML/JS 의 mix, CSP 의 violation.
  • No cleanup in SPA: memory leak. 매 unmount 의 removeEventListener 의 호출.
  • scroll without passive: 60fps scroll 의 block.
  • stopPropagation() overuse: delegation pattern 의 break.
  • Listener on every list item: N 의 listener 대신 delegation 의 사용.

🧪 검증 / 중복

  • Verified (MDN Web Docs — Event reference, WHATWG DOM spec).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — DOM event handling full content