Skip to main content

Adding Mutators

Mutators are how you change data in Replicache.

Mutators are arbitrary functions that run once on the client immediately (aka “optimistically”), and then run again later on the server (”authoritatively”) during sync.

Replicache queues mutations locally until the server acknowledges them during sync. Once the authoritative server result is known, Replicache reverts the optimistic version completely. For a deeper understanding of how the authoritative server works please read about synchronization.

Mutators are fast

Although the methods of tx are marked async, they almost always responds instantly (in the same event, < 1ms after call). The only reason access is async is for the rare case when Replicache must load data from local storage, such as at startup.

Replicache is designed to be memory-fast and you should not need additional layers of caching above it. See performance for more information.

Challenge

Try adding your own multiply mutator.