TinyBase logoTinyBase β

stopSync

The stopSync method is used to stop the process of synchronization between this instance and another matching Synchronizer.

stopSync(): this
returnsthis

A reference to the Synchronizer object.

The underlying implementation of a Synchronizer is shared with the Persister framework, and so this startSync method is equivalent to stopping both auto-loading (listening to sync messages from other active Synchronizer instances) and auto-saving (sending sync messages to them).

Example

This example creates two empty MergeableStore objects, creates a LocalSynchronizer for each, and starts - then stops - synchronizing them. Subsequent changes are not merged.

import {createLocalSynchronizer} from 'tinybase/synchronizers/synchronizer-local';
import {createMergeableStore} from 'tinybase';

const store1 = createMergeableStore();
const synchronizer1 = createLocalSynchronizer(store1);
await synchronizer1.startSync();

const store2 = createMergeableStore();
const synchronizer2 = createLocalSynchronizer(store2);
await synchronizer2.startSync();

store1.setTables({pets: {fido: {species: 'dog'}}});
// ...
console.log(store1.getTables());
// -> {pets: {fido: {species: 'dog'}}}
console.log(store2.getTables());
// -> {pets: {fido: {species: 'dog'}}}

synchronizer1.stopSync();
synchronizer2.stopSync();

store1.setCell('pets', 'fido', 'color', 'brown');
// ...
console.log(store1.getTables());
// -> {pets: {fido: {species: 'dog', color: 'brown'}}}
console.log(store2.getTables());
// -> {pets: {fido: {species: 'dog'}}}

synchronizer1.destroy();
synchronizer2.destroy();

Since

v5.0.0