rocicorp / replicache

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

A way to filter out "self-inflicted" changes #1058

Open aboodman opened 1 month ago

aboodman commented 1 month ago

Many text editors and canvases that people want to hook Replicache to maintain their own internal state, and they don't have a way to run in "controlled" mode. tldraw is one example of this.

As such, people really want to be able to hear events from tldraw, apply them to Replicache, and then have Replicache sync those changes. Unfortunately Replicache wants to be the source of truth, so it fires a subscription/watch, which the user then replays on tldraw (luckily tldraw considers it a no-op at this point and the madness stops).

To get this to work properly, it seems like there could be a way to write a mutation but specifically opt out of hearing about its changes.

I think the right way to do this would be to apply the mutation and then take the new client view after the mutation is applied as the client's base state. That way any changes from rebase will be detected properly.