Skip to content

Vizel API / svelte/src / createVizelState

Function: createVizelState()

ts
function createVizelState(getEditor): object;

Defined in: packages/svelte/src/runes/createVizelState.svelte.ts:29

Rune that forces a re-render whenever the editor's state changes.

Wraps @vizel/core's createVizelEditorTransactionStore so the subscribe/version-counter mechanics are shared with the React and Vue adapters.

The exposed field is named version (not current) because the value is an opaque monotonic counter, not the editor itself. The Svelte editor accessor (createVizelEditor().current) already owns the current slot for the editor instance; this rune sits next to it as a sibling reactive read, so a distinct name avoids the implication of a "current editor" dual.

Parameters

ParameterTypeDescription
getEditor() => Editor | null | undefinedA function that returns the editor instance

Returns

object

An object with a version getter for the update count

version

ts
readonly version: number;

Example

svelte
<script lang="ts">
const state = createVizelState(() => editor);
// Access state.version to trigger reactivity
</script>
<button class:active={state.version >= 0 && editor.isActive('bold')}>Bold</button>

Released under the MIT License.