Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
What is the best way to fully clear a DOM element for use in a pool?

I am considering using object pooling of DOM nodes. When a DOM node is done being used, it would be put into a pool. I have something like this currently.

function removeNativeElement(virtualElement, store) {
  let stack = [virtualElement]
  let els = []
  while (stack.length) {
    const node = stack.shift()
    const el = node.nativeElement
    // remove from parent
    el.parentNode.removeChild(el)
    // remove event listeners
    node.handlers.forEach(({ type, handler }) => {
      el.removeEventListener(type, handler)
    })
    el.children.forEach(child => {
      stack.push(child)
    })
    els.push(el)
  }
  els.forEach(el => {
    // clear out any remaining text
    el.innerHTML = ''
    addNativeElementToPool(el)
  })
}

function addNativeElementToPool(el, store) {
  const pool = store.pool[el.tagName] = store.pool[el.tagName] || []
  if (pool.length > store.maxPoolSize) {
    return
  }
  pool.push(el)
}

But what about resetting the attributes and style properties, in an efficient way, how do you do that? The goal is to make putting object into a pool not be overburdeningly expensive.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda