rocicorp / replicache

Realtime Sync for Any Backend Stack
https://doc.replicache.dev
1.04k stars 37 forks source link

It would be nice to have an analog to `scanAll()` but just for keys #292

Closed aboodman closed 3 years ago

aboodman commented 3 years ago

I feel bad pulling out all the values when I'm not using them, but I also don't want to manually iterate the keys asynchronously.

arv commented 3 years ago

Here you go!

async function toArray(it) {
  const res = [];
  for await (const v of it) {
    res.push(v);
  }
  return res;
}
aboodman commented 3 years ago

It would be nice to have it built-in 😀

On Wed, Mar 3, 2021 at 1:02 PM Erik Arvidsson notifications@github.com wrote:

Here you go!

async function toArray(it) { const res = []; for await (const v of it) { res.push(v); } return res;}

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/rocicorp/replicache-sdk-js/issues/292#issuecomment-790134717, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAATUBD3R7PK3ILBKNRLR4TTB25YTANCNFSM4YSBFODQ .

arv commented 3 years ago

Another option would be to add array version to ScanIterator:

const keys = await rep.scan().keysArray();
const values = await rep.scan().valuesArray();
const entries = await rep.scan().entriesArray();

or even...

const keys = await rep.scan().keys().toArray();
const values = await rep.scan().values().toArray();
const entries = await rep.scan().entries().toArray();