Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
¿El segundo operador `scan' de RxJS no continúa desde el anterior?

Tengo el siguiente código RxJS: ejemplo de código /* The result is: 4 9 15 4 9 15 */ ... ¿por qué el segundo scan comienza desde el principio (4,9,15) y no continúa desde el scan anterior? (mostrando 19,24,30). ¿Es la misma corriente después de todo?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

observables no funciona así. Tienes que verlos como un flujo de agua, donde puedes cambiar el agua con operadores. Cada vez que haces algo con números$ estás iniciando un nuevo flujo de agua. Entonces, la primera tubería no tiene nada que ver con la otra tubería y viceversa.

Si desea tener un valor de retorno sobre el primer escaneo, debe guardar el valor de retorno de la tubería y extenderlo con una tubería adicional.

 // 'scan' test let numbers$ = from([4, 5, 6]); let val1 = numbers$ .pipe( // Get the sum of the numbers coming in. scan((total, n) => { return total + n }), // Get the average by dividing the sum by the total number // received so var (which is 1 more than the zero-based index). //map((sum, index) => sum / (index + 1)) ) val1.subscribe(x => console.log('value of the first scan is', x)) val1.pipe( scan((total, n) => { return total + n }) ).subscribe(console.log);

O puede agregar otro escaneo en la tubería. Pero luego perderá el valor del primer escaneo:

 let numbers$ = from([4, 5, 6]); numbers$ .pipe( // Get the sum of the numbers coming in. scan((total, n) => { return total + n }), scan((total, n) => { return total + n }) // Get the average by dividing the sum by the total number // received so var (which is 1 more than the zero-based index). //map((sum, index) => sum / (index + 1)) ).subscribe(x => console.log('value of the second scan is', x))
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!