TinyBase logoTinyBase β

getSynchronizer

The getSynchronizer function returns the default Synchronizer from the current Provider context (or a named one if an Id is provided).

getSynchronizer(id?: string): Synchronizer | undefined
TypeDescription
id?string

An optional Id of a named Synchronizer in the Provider context.

returnsSynchronizer | undefined

The Synchronizer, or undefined if not found.

Example

This example reads a TinyBase object from Svelte context inside a child component.

Child.svelte
<svelte:options runes={true} />

<script>
  import {getSynchronizer} from 'tinybase/ui-svelte';
</script>

{getSynchronizer()?.getStatus()}
App.svelte
<svelte:options runes={true} />

<script>
  import {Provider} from 'tinybase/ui-svelte';
  import Child from './Child.svelte';

  let {synchronizer} = $props();
</script>

<Provider {synchronizer}>
  <Child />
</Provider>
import {flushSync, mount} from 'svelte';
import {createMergeableStore} from 'tinybase';
import {createLocalSynchronizer} from 'tinybase/synchronizers/synchronizer-local';
import App from './App.svelte';

const synchronizer = createLocalSynchronizer(createMergeableStore());
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {synchronizer}}));
console.log(app.textContent);
// -> '0'

Since

v8.1.0