Skip to content

API reference > @kontsedal/olas-svelte

olas-svelte package ​

Functions ​

Function

Description

fieldStore(field)

One store over a field's value and validation state, for an input that also shows its errors: bind:value={$state.value}. For the value alone, bind the field directly: bind:value={$field}.

An object-valued field binds one level down through the store:bind:value={$person.value.first}. Svelte writes that by assigning first on the value object it was handed and passing the state back to set, as a Svelte store treats an object as changed whenever it is set. Each subscriber gets its own shallow copy of a plain-object or array value, so the assignment lands on the copy, and set writes the copy to the field as a new value: validators run, isDirty follows, and the field's initial stays as it was. A member two levels down is still shared with the field's own value; bind that through a Form's leaf field.

getRoot()

The root's api, from the nearest setRoot. Call during a component's initialization.

infiniteQueryStore(subscription)

One store over an infinite query subscription.

mutationStore(mutation)

One store over a mutation's signals. mutate is the call for an on:click.

queryStore(subscription)

One store over a query subscription's signals. $query.data,$query.isLoading and the rest update together, once per change.

svelte
<script>
  const user = queryStore(getRoot().user)
</script>
{#if $user.isLoading}Loading…{:else}{$user.data?.name}{/if}

setRoot(root)

Provide a root to the component tree below. Call during a component's initialization.

Interfaces ​

Interface

Description

Register

Register the app's root type once, and getRoot() returns its api with no type argument. Empty here: the app adds root through declaration merging.

Type Aliases ​

Type Alias

Description

FieldState

A field's state as one store value.

FieldStore

What fieldStore returns: a store of the field's state, plus its actions.

InfiniteQueryState

An infinite query's state as one store value.

InfiniteQueryStore

What infiniteQueryStore returns.

MutateFn

mutationStore's fire-and-forget trigger: run's arguments, no promise.

MutationState

A mutation's state as one store value.

MutationStore

What mutationStore returns: a store of the mutation's state, plus its triggers.

QueryState

A query's state as one store value.

QueryStore

What queryStore returns: a store of the query's state, plus its actions.

RegisteredApi

The api getRoot() returns by default: the registered root's, else unknown.

Released under the MIT License.