Skip to content
On this page
v2.0.0-pre.18

FeathersModel Stores

Model Functions come with their own built-in stores. The BaseModel store API is a subset of the FeathersModel store.

Related reading:

Creating a FeathersModel Store

FeathersModel stores are created only when you create a FeathersModel Function using useFeathersModel. The default store is found at Model.store:

Note about Feathers Types

Replace my-feathers-api in the below example with the package installed from your Feathers v5 Dove API. You can also provide manual types that describe the shape of your data.

ts
import type { Tasks, TasksData, TasksQuery } from 'my-feathers-api'
import { type ModelInstance, useFeathersModel, useInstanceDefaults } from 'feathers-pinia'
import { api } from '../feathers'

const modelFn = (data: ModelInstance<Tasks>) => {
  const withDefaults = useInstanceDefaults({ description: '', isComplete: false }, data)
  return withDefaults
}
const Task = useFeathersModel<Tasks, TasksData, TasksQuery, typeof modelFn>(
  { name: 'Task', idField: '_id', service },
  modelFn,
)

console.log(Task.store) // --> See API, below

Similar to a Pinia store, the top-level of the store is a reactive, which means nested computed properties will be unwrapped, which means you don't have to access their contents using .value, like you would with a Vue ref or computed, normally.

API

FeathersModel stores use the useService utility under the hood. This means that they implement all of the same APIs as BaseModel and include the full API for communicating with a Feathers service.

For API docs, see useService.

Many thanks go to the Vue, Vuex, Pinia, and FeathersJS communities for keeping software development FUN!