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

138
Views
`.pipe()` no ejecuta `debounceTime`

Estoy tratando de debounce() un Observable con pipe() y encadenando .subscribe() pero por alguna razón, la función en la suscripción todavía se llama más de una docena de veces de una sola vez.

Lo que estoy tratando de hacer es canalizar withChangesForTables y eliminar el rebote de la llamada de sincronización porque quiero que se llame solo cuando se haya realizado un lote completo de cambios. Así que creé un proveedor para la sincronización y lo envolví en mi RootNavigator

withChangesForTables en el código fuente de WatermelonDB

 const SyncContext = createContext(); function useSync() { return useContext(SyncContext); } function SyncProvider({children}) { const [isSyncing, setIsSyncing] = useState(false); const [hasUnsynced, setHasUnsynced] = useState(false); async function checkUnsyncedChanges() { const hasChanges = await hasUnsyncedChanges({ database }); setHasUnsynced(hasChanges); } async function sync() { await checkUnsyncedChanges(); if (!isSyncing && hasUnsynced) { setIsSyncing(true); await synchronizeWithServer(); setIsSyncing(false); } } database.withChangesForTables([ 'table_name', 'table_name2' ]).pipe( skip(1), // ignore records simply becoming `synced` filter(changes => !changes.every(change => change.record.syncStatus === 'synced')), // debounce to avoid syncing in the middle of related actions - I put 100000 to test only debounceTime(100000), ).subscribe({ //calls API endpoint to sync local DB with server next: () => sync(), error: e => console.log(e) }); const value = { isSyncing, hasUnsynced, checkUnsyncedChanges, sync }; return ( <SyncContext.Provider value={value}> {children} </SyncContext.Provider> ); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tuve que mover withChangesForTables a useEffect y volver a ejecutarlo para cancelar la suscripción, lo que parece haber resuelto el problema. El código ahora se parece a esto:

 useEffect(() => { return database.withChangesForTables([ 'table_name', 'table_name2' ]).pipe( skip(1), filter(changes => !changes.every(change => change.record.syncStatus === 'synced')), debounceTime(500), ).subscribe({ next: () => sync(), error: e => console.log(e) }); }, [])
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!