🎁 Upgrade to Feathers-Pinia 2.0 🎁
Feathers-Pinia 2.0 is almost ready for final release. Read the new documentation.Module Overview
The main module features the following exports:
Setup & Store Creation
// Setup & Store Creation
export { setupFeathersPinia } from './setup'
export { defineStore } from './service-store'
export { useAuth } from './use-auth'
setupFeathersPinia
allows global configuration ofclients
for all apps. It can also be used to support a common set of options for the returned, wrappeddefineStore
function. Right now it's not that useful for SSR apps, which require an alternative configuration.- defineStore sets up a Pinia store for a Feathers service.
- useAuth is a composition utility which allows you to create a highly-flexible setup stores for auth.
Composition API Utils
New APIs in v1// Composition API Utils
export { useFind, Find } from './use-find'
export { useGet, Get } from './use-get'
export { useClones } from './use-clones'
export { useClone } from './use-clone'
- useFind is a utility that assists you in implementing the Live Query pattern. Give it a set of params and you'll get back live-updating lists of
data
, as well as pagination utilities likenext
, andprev
. It's super versatile, handling declarative and imperative workflows that support both the client- and server-side pagination. It's similar to SWR but far more intelligent, being able to reuse data between different queries. - useGet is similar to
useFind
but for theget
method. - useClones removes boilerplate from the clone and commit pattern. It automatically clones all component props containing a
feathers-pinia
instance. - useClone is like
useClones
but for a single prop.
Data Modeling & Associations
// Data Modeling & Associations
export { BaseModel } from './service-store'
export { associateFind } from './associate-find'
export { associateGet } from './associate-get'
- BaseModel is the base class for working with Data Modeling.
- associateFind creates an array-based relationship with another Model class
- associateGet creates a single-object-based relationship with another Model class
SSR & Storage
// SSR & Storage
export { OFetch } from './feathers-ofetch'
export { syncWithStorage } from './storage-sync'
export { clearStorage } from './clear-storage'
OFetch
is a utility that combines the universal fetch utility called ofetch with the Feathers-Client. It enables compatibility with Nuxt3 with SSR enabled.syncWithStorage
synchronizes specific parts of a store's state intolocalStorage
or any Storage-compatible adapter you provide.clearStorage
clears data stored with the above utilities.
Learn more about these utilities in syncWithStorage
Global Reference Objects
// Global Reference Objects
export { models } from './models'
export { clients, registerClient } from './clients'
clients
stores a reference to every Feathers client provided to eithersetupFeathersPinia
ordefineStore
.- After setup, you can reference a
FeathersClient
at any time as shown below. This might come in handy if you need to fetch data that you don't want to be reactive. That data also won't end up in the store, so it would require refetching if not manually stored somewhere. You could use this with swrv.
tsimport { clients } from 'feathers-pinia' const { api } = clients const result = await api.service('items').find({ query: {} })
- After setup, you can reference a
If you call your default client
api
, you won't have to provide a customclientAlias
option to thedefineStore
function. Learn about setting up FeathersClient instances in Setup.registerClient
adds a client by name to theclients
object.registerClient('api', feathersClientInstance)
.models
stores a reference to every custom model provided todefineStore
.
Feathers-Vuex Migration Utils
// Feathers-Vuex Migration Utils
export { defineAuthStore } from './define-auth-store'
export { useFindWatched } from './use-find-watched'
export { useGetWatched } from './use-get-watched'
export { usePagination } from './use-pagination'
These utilities exist to assist with migration from Feathers-Vuex. Use them for migrating existing Feathers-Vuex code, but not for new development. Use the new useFind
and useGet
utilities for new development.
defineAuthStore
sets up a single Pinia store for an authentication service. See Auth StoresuseFindWatched
is the equivalent to Feathers-Vuex'suseFind
utility. See useFindWatcheduseGetWatched
is the equivalent to Feathers-Vuex'suseGet
utility. See useGetWatched.usePagination
is a composition api utility that handles typical pagination logic. See usePagination