expect(useStore()).toBe(useStore())
})
+ it('works with id as first argument', () => {
+ setActivePinia(createPinia())
+ const useStore = defineStore('main', {
+ state: () => ({
+ a: true,
+ nested: {
+ foo: 'foo',
+ a: { b: 'string' },
+ },
+ }),
+ })
+ expect(useStore()).toBe(useStore())
+ const useStoreEmpty = defineStore('main', {})
+ expect(useStoreEmpty()).toBe(useStoreEmpty())
+ })
+
it('sets the initial state', () => {
const store = useStore()
expect(store.$state).toEqual({
G extends GettersTree<S>,
A extends ActionsTree
>(
+ id: Id,
options: DefineStoreOptions<Id, S, G, A>,
pinia: Pinia,
hot?: boolean
): Store<Id, S, G, A> {
- const { id, state, actions, getters } = options
+ const { state, actions, getters } = options
function $reset() {
pinia.state.value[id] = state ? state() : {}
}
const isSetupStore = typeof setup === 'function'
if (typeof idOrOptions === 'string') {
id = idOrOptions
- options = setupOptions
+ // the option store setup will contain the actual options in this case
+ options = isSetupStore ? setupOptions : setup
} else {
options = idOrOptions
id = idOrOptions.id
id,
isSetupStore
? createSetupStore(id, setup, options, pinia)
- : createOptionsStore(options as any, pinia)
+ : createOptionsStore(id, options as any, pinia)
)
if (__DEV__) {
const hotId = '__hot:' + id
const newStore = isSetupStore
? createSetupStore(hotId, setup, options, pinia, true)
- : createOptionsStore(
- assign({}, options, { id: hotId }) as any,
- pinia,
- true
- )
+ : createOptionsStore(hotId, assign({}, options) as any, pinia, true)
hot._hotUpdate(newStore)