expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
- storeName: 'main',
storeId: 'main',
type: MutationType.direct,
}),
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({
payload: patch,
- storeName: 'main',
storeId: 'main',
type: MutationType.patchObject,
}),
// useStore could be anything like useUser, useCart
export const useStore = defineStore({
// unique id of the store across your application
- id: 'storeName',
+ id: 'storeId',
})
```
import { defineStore } from 'pinia'
const useStore = defineStore({
- id: 'storeName',
+ id: 'storeId',
// can also be defined with an arrow function if you prefer that syntax
state() {
return {
+++ /dev/null
-import { defineStore } from './store'
-
-/**
- * {@inheritDoc defineStore}
- * @deprecated Use {@link defineStore}
- */
-export const createStore = ((options: any) => {
- console.warn(
- '[🍍]: "createStore" has been deprecated and will be removed on the sable release, use "defineStore" instead.'
- )
- return defineStore(options)
-}) as typeof defineStore
_Spread,
_StoreObject,
} from './mapHelpers'
-
-// TODO: remove in beta
-export { createStore } from './deprecated'
partialStateOrMutator(pinia.state.value[$id] as UnwrapRef<S>)
subscriptionMutation = {
type: MutationType.patchFunction,
- storeName: $id,
storeId: $id,
events: debuggerEvents as DebuggerEvent[],
}
subscriptionMutation = {
type: MutationType.patchObject,
payload: partialStateOrMutator,
- storeName: $id,
storeId: $id,
events: debuggerEvents as DebuggerEvent[],
}
if (isListening) {
callback(
{
- storeName: $id,
storeId: $id,
type: MutationType.direct,
events: debuggerEvents as DebuggerEvent,
*/
type: MutationType
- /**
- * @deprecated use `storeId` instead.
- */
- storeName: string
-
/**
* `id` of the store doing the mutation.
*/
+++ /dev/null
-import { createStore, expectType } from './'
-
-const useDeprecated = createStore({
- id: 'name',
- state: () => ({ a: 'on' as 'on' | 'off', nested: { counter: 0 } }),
- getters: {
- upper: (state) => state.a.toUpperCase(),
- },
-})
-
-const deprecatedStore = useDeprecated()
-
-expectType<{ a: 'on' | 'off' }>(deprecatedStore.$state)
-expectType<number>(deprecatedStore.nested.counter)
-expectType<'on' | 'off'>(deprecatedStore.a)
-
-// @ts-expect-error
-deprecatedStore.nonExistant
-
-// @ts-expect-error
-deprecatedStore.nonExistant.stuff