🗃️ Centralized State Management for Vue.js.
This major release only breaks backwards compatibility if you use TypeScript.
TypeScript type declarations have been updated to be compatible with Vue core 2.5+ and no longer work with 2.4 and below.
All type declarations are now exported using ES-style exports, and must be imported using ES modules syntax:
import { Store } from 'vuex'
store.registerModule
can now be called while preserving current state if the module is already registered, by passing a 3rd argument as { preserveState: true }
. Useful in server-side rendering.
New method: store.subscribeAction()
- similar to store.subscribe
, but for actions instead.
Namespaced modules can now also register global actions using the following syntax:
const module = {
actions: {
rootAction: {
root: true,
handler: () => {}
}
}
}
The createLogger
function now also accepts a logger
option, allowing the user to provide a custom implementation of the console
object to be used when logging.
New helper method createNamespacedHelpers
: a helper-generator that generates namespaced mapXXX
helpers for you:
const { mapState, mapActions } = createNamespacedHelpers('some/nested/module')
// everything generated by mapState and mapActions are bound to the module.
See docs for more info.
(@riophae via #800)
state
using a function - this allows the same module definition to be reused (e.g. multiple times in the same store, or in multiple stores)