Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
Concatenating arrays in a Alpine.data objects returns proxies

I'm working with a Alpine.data global and I'm looking to concatenate arrays when my loadJobs method fires. I'm not familiar to proxies in JS and I don't really understand why my data property returns a Proxy object instead of a simple array.

Here's the piece of code I'm working with :

jobState = {
    low: 5,
    high: 10,
    isLoaded: false
}

document.addEventListener("alpine:init", () => {
    Alpine.data("loadMoreJobs", () => ({
        data: [],
        loadJobs() {
            // Update jobState
            jobState.low = jobState.high
            jobState.high += 5
            const requestParams = {
                dataType: 'json',
                method: 'GET'
            }
            fetch(`http://127.0.0.1:3000/jobs/list/${jobState.low}/${jobState.high}`, requestParams)
                .then((data) => {
                    return data.json()
                })
                .then((data) => {
                    this.data = [...this.data, data]
                })
        }
    }))
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

data logs out as Proxy because that's how Alpine.js' reactivity works: it wraps all relevant objects in Proxy in order to hook into changes into said objects.

The Proxies should work the same as the underlying data structures, the only difference is Alpine can hook into operations on the proxy (re-assignment, mutation etc.).

As mentioned in the comments thread. One way to unwrap the Proxy and get a copy of the original data structure is to use JSON.parse(JSON.stringify(data)) (or another deep-cloning approach eg. structuredClone which isn't widely available yet).

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda