INNER CODE UNIT · TypeScript

getOrCreateCursor

aws-devtools-labs/aws-blocks · native/swift/Demo/typescript-demo/src/index.ts:338

function getOrCreateCursor(id: string, color: string): HTMLElement {
  let el = cursors.get(id);
  if (!el) {
    el = document.createElement('div');
    el.className = 'cursor-dot';
    el.innerHTML = `${cursorSvg(color)}<span class="label" style="background:${esc(color)};color:#000">${esc(id)}</span>`;
    realtimeArea.appendChild(el);
    cursors.set(id, el);
  }
  return el;
}

const lastSeen = new Map<string, number>();
setInterval(() => {
  const now = Date.now();
  for (const [id, time] of lastSeen) {
    if (now - time > 3000) {
      cursors.get(id)?.remove();

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…