rocicorp / replicache

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

RFE: Add a push() method #1041

Closed aboodman closed 12 months ago

aboodman commented 1 year ago

Sometimes users want to push asap, no rate-limiting, no nothing (ie, if they are going to send some other rest request to their server and do something with data).

They also want to know when all pending mutations have been sent.

It would be nice to have a push() method for this purpose, perhaps with an optional now argument. We could make pull() match.

arv commented 1 year ago

What would the optional argument do?

aboodman commented 1 year ago

I think at the time I was thinking it would be "right now" vs "soon". But I guess that's not needed since by default we push soon.

mashpie commented 1 year ago

I am tracking online and visibility state to replicache.pull() as soon UI is online or gets focus (ie. changed tap from background to foreground).

  /**
   * tracks changes on visibilitychange
   */
  document.addEventListener('visibilitychange', () => {
    if (document.visibilityState === 'visible') replicache.pull()
  })

  /**
   * tracks changes on network events
   */
  const online = useOnline()
  watch(online, (isOnline) => {
    if (isOnline) replicache.pull()
  })

so for a user all remote changes get pulled instantly. Same would apply for replicache.push() to propagate local changes. Waiting a couple of seconds is often confusing users.

aboodman commented 12 months ago

This has been implemented in 14.0.3: https://replicache.notion.site/Replicache-14-0-3-3dce462db565425c846875b488677c07?pvs=4