Svelte utility functions

Important! To use these functions, you need to import the "Scripting API Extra" library.

If you happen to use the Svelte framework, the Scripting API Extra package provide some utility functions to easily bind your Svelte components to your WorkAdventure map.

Mapping a WorkAdventure variable to a Svelte store

Use createStoreFromVariable to create a Svelte store that is bound to a WorkAdventure variable.

const myVariableStore = createStoreFromVariable('my_variable');

createStoreFromVariable returns a writable store.

If you already have a Svelte store and you want to bind it to a WorkAdventure variable, use mapVariableToStore.

// Maps a WorkAdventure variable to an existing store.
// The "myVariableStore" must be a Svelte store with a "set" function.
mapVariableToStore('my_variable', myVariableStore);