diff --git a/packages/alpinejs/src/store.js b/packages/alpinejs/src/store.js index dc7bf94f5..60a44dcf5 100644 --- a/packages/alpinejs/src/store.js +++ b/packages/alpinejs/src/store.js @@ -13,11 +13,11 @@ export function store(name, value) { stores[name] = value + initInterceptors(stores[name]) + if (typeof value === 'object' && value !== null && value.hasOwnProperty('init') && typeof value.init === 'function') { stores[name].init() } - - initInterceptors(stores[name]) } export function getStores() { return stores } diff --git a/tests/cypress/integration/plugins/persist.spec.js b/tests/cypress/integration/plugins/persist.spec.js index 0fe1a6c28..32595fdea 100644 --- a/tests/cypress/integration/plugins/persist.spec.js +++ b/tests/cypress/integration/plugins/persist.spec.js @@ -227,6 +227,25 @@ test('can persist using global Alpine.$persist within Alpine.store', }, ) +test('persist in Stores is available in init call', + [html` +