Skip to content

API reference > @kontsedal/olas-vue

olas-vue package ​

Functions ​

Function

Description

olasPlugin(root)

The Vue plugin that provides a root to the whole app. The root is built outside Vue, once, and app.use hands it to every component:

ts
const root = createRoot(appController, { deps, queries: queryEngine() })
createApp(App).use(olasPlugin(root)).mount('#app')

useField(field)

Bind a component to a Field. value is a writable ref, so it works withv-model once destructured:

vue
<script setup>
const { value, errors, markTouched } = useField(api.form.fields.name)
</script>
<template><input v-model="value" @blur="markTouched" /></template>

useInfiniteQuery(subscription)

Subscribe a component to an infinite query subscription.

useMutation(mutation)

Subscribe a component to a mutation a controller made. mutate is the call for an event handler; run returns the promise.

useQuery(subscription)

Subscribe a component to a query subscription a controller made. Each field is a ref, so a template reads it unwrapped when destructured:

ts
const { data, isLoading } = useQuery(api.user)

useRoot()

The root's api, from the nearest olasPlugin. Typed by the registered root (Register), or by useRoot<Api>() as an unchecked cast. Throws when no plugin provided a root, and when called outside a component's setup(), where there is no app to ask.

useValue(signal, options)

A read-only ref over any ReadSignal: a signal, a computed, a Field, a Form or a FieldArray. Reading the ref reads the signal's current value, so it never lags a write. With isEqual, a value equal to the one the ref last returned counts as unchanged: the ref keeps returning the earlier value, as React's useValue does. The subscription ends with the component (the current effect scope). Outside any scope nothing ends it, and a development build warns. A server render reads the signal and does not subscribe.

ts
const count = useValue(api.count)   // count.value in script, {{ count }} in a template

Interfaces ​

Interface

Description

Register

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

ts
declare module '@kontsedal/olas-vue' {
  interface Register {
    root: typeof root
  }
}

Type Aliases ​

Type Alias

Description

MutateFn

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

Refs

Each field of T as a read-only ref: the shape the hooks return their state in.

RegisteredApi

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

UseFieldReturn

What useField returns. value is writable, for v-model.

UseInfiniteQueryReturn

What useInfiniteQuery returns: useQuery's fields plus the paging state and actions.

UseMutationReturn

What useMutation returns: the mutation's signals as refs, plus its triggers.

UseQueryReturn

What useQuery returns: each AsyncState signal as a ref, plus the actions.

UseValueOptions

Options for useValue.

Released under the MIT License.