TinyBase logoTinyBase β

getSynchronizerStatus

The getSynchronizerStatus function returns a reactive object reflecting the status of a Synchronizer, and registers a listener so that any changes will update current.

getSynchronizerStatus(synchronizerOrSynchronizerId?: MaybeGetter<undefined | SynchronizerOrSynchronizerId>): {current: Status}
TypeDescription
synchronizerOrSynchronizerId?MaybeGetter<undefined | SynchronizerOrSynchronizerId>

The Synchronizer to use, or its Id.

returns{current: Status}

A reactive object with a current Status property.

Example

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

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

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

{getSynchronizerStatus().current}
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