Home > @xoram/plugin-panoramique > StoreAsService
StoreAsService type
Turn a Pinia `store` into a xoram `Service`.
Signature:
typescript
export type StoreAsService<store, notifications extends Record<string, unknown> = Record<string, unknown>, storeId extends string = string> = (store extends Store ? store : Store<storeId, _ExtractStateFromSetupStore<store>, _ExtractGettersFromSetupStore<store>, _ExtractActionsFromSetupStore<store>>) & Service<notifications>;
1
References: _ExtractStateFromSetupStore, _ExtractGettersFromSetupStore, _ExtractActionsFromSetupStore, Service
Example 1
ts
// using an inferred store
export const useBlog = defineStore('blog', () => {
// blog store setup
});
defineService<StoreAsService<ReturnType<typeof useBlog>>(() => useBlog())
1
2
3
4
5
2
3
4
5
Example 2
ts
// using a typed store
export interface BlogStore {
// blog store API
}
export const useBlog = defineStore<'blog', BlogStore>('blog', () => {
// blog store setup
});
defineService<StoreAsService<BlogStore>(() => useBlog())
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8