|
@@ -7,9 +7,11 @@ let Vue // bind on install
|
|
|
|
|
|
export class Store {
|
|
|
constructor (options = {}) {
|
|
|
- assert(Vue, `must call Vue.use(Vuex) before creating a store instance.`)
|
|
|
- assert(typeof Promise !== 'undefined', `vuex requires a Promise polyfill in this browser.`)
|
|
|
- assert(this instanceof Store, `Store must be called with the new operator.`)
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(Vue, `must call Vue.use(Vuex) before creating a store instance.`)
|
|
|
+ assert(typeof Promise !== 'undefined', `vuex requires a Promise polyfill in this browser.`)
|
|
|
+ assert(this instanceof Store, `Store must be called with the new operator.`)
|
|
|
+ }
|
|
|
|
|
|
const {
|
|
|
plugins = [],
|
|
@@ -64,7 +66,9 @@ export class Store {
|
|
|
}
|
|
|
|
|
|
set state (v) {
|
|
|
- assert(false, `Use store.replaceState() to explicit replace store state.`)
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(false, `Use store.replaceState() to explicit replace store state.`)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
commit (_type, _payload, _options) {
|
|
@@ -77,7 +81,7 @@ export class Store {
|
|
|
|
|
|
const mutation = { type, payload }
|
|
|
const entry = this._mutations[type]
|
|
|
- if (!entry) {
|
|
|
+ if (process.env.NODE_ENV !== 'production' && !entry) {
|
|
|
console.error(`[vuex] unknown mutation type: ${type}`)
|
|
|
return
|
|
|
}
|
|
@@ -88,7 +92,10 @@ export class Store {
|
|
|
})
|
|
|
this._subscribers.forEach(sub => sub(mutation, this.state))
|
|
|
|
|
|
- if (options && options.silent) {
|
|
|
+ if (
|
|
|
+ process.env.NODE_ENV !== 'production' &&
|
|
|
+ options && options.silent
|
|
|
+ ) {
|
|
|
console.warn(
|
|
|
`[vuex] mutation type: ${type}. Silent option has been removed. ` +
|
|
|
'Use the filter functionality in the vue-devtools'
|
|
@@ -104,7 +111,7 @@ export class Store {
|
|
|
} = unifyObjectStyle(_type, _payload)
|
|
|
|
|
|
const entry = this._actions[type]
|
|
|
- if (!entry) {
|
|
|
+ if (process.env.NODE_ENV !== 'production' && !entry) {
|
|
|
console.error(`[vuex] unknown action type: ${type}`)
|
|
|
return
|
|
|
}
|
|
@@ -127,7 +134,9 @@ export class Store {
|
|
|
}
|
|
|
|
|
|
watch (getter, cb, options) {
|
|
|
- assert(typeof getter === 'function', `store.watch only accepts a function.`)
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(typeof getter === 'function', `store.watch only accepts a function.`)
|
|
|
+ }
|
|
|
return this._watcherVM.$watch(() => getter(this.state, this.getters), cb, options)
|
|
|
}
|
|
|
|
|
@@ -139,8 +148,11 @@ export class Store {
|
|
|
|
|
|
registerModule (path, rawModule) {
|
|
|
if (typeof path === 'string') path = [path]
|
|
|
- assert(Array.isArray(path), `module path must be a string or an Array.`)
|
|
|
- assert(path.length > 0, 'cannot register the root module by using registerModule.')
|
|
|
+
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(Array.isArray(path), `module path must be a string or an Array.`)
|
|
|
+ assert(path.length > 0, 'cannot register the root module by using registerModule.')
|
|
|
+ }
|
|
|
|
|
|
this._modules.register(path, rawModule)
|
|
|
installModule(this, this.state, path, this._modules.get(path))
|
|
@@ -150,7 +162,11 @@ export class Store {
|
|
|
|
|
|
unregisterModule (path) {
|
|
|
if (typeof path === 'string') path = [path]
|
|
|
- assert(Array.isArray(path), `module path must be a string or an Array.`)
|
|
|
+
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(Array.isArray(path), `module path must be a string or an Array.`)
|
|
|
+ }
|
|
|
+
|
|
|
this._modules.unregister(path)
|
|
|
this._withCommit(() => {
|
|
|
const parentState = getNestedState(this.state, path.slice(0, -1))
|
|
@@ -285,7 +301,7 @@ function makeLocalContext (store, namespace, path) {
|
|
|
|
|
|
if (!options || !options.root) {
|
|
|
type = namespace + type
|
|
|
- if (!store._actions[type]) {
|
|
|
+ if (process.env.NODE_ENV !== 'production' && !store._actions[type]) {
|
|
|
console.error(`[vuex] unknown local action type: ${args.type}, global type: ${type}`)
|
|
|
return
|
|
|
}
|
|
@@ -301,7 +317,7 @@ function makeLocalContext (store, namespace, path) {
|
|
|
|
|
|
if (!options || !options.root) {
|
|
|
type = namespace + type
|
|
|
- if (!store._mutations[type]) {
|
|
|
+ if (process.env.NODE_ENV !== 'production' && !store._mutations[type]) {
|
|
|
console.error(`[vuex] unknown local mutation type: ${args.type}, global type: ${type}`)
|
|
|
return
|
|
|
}
|
|
@@ -383,7 +399,7 @@ function registerAction (store, type, handler, local) {
|
|
|
}
|
|
|
|
|
|
function registerGetter (store, type, rawGetter, local) {
|
|
|
- if (store._wrappedGetters[type]) {
|
|
|
+ if (process.env.NODE_ENV !== 'production' && store._wrappedGetters[type]) {
|
|
|
console.error(`[vuex] duplicate getter key: ${type}`)
|
|
|
return
|
|
|
}
|
|
@@ -399,7 +415,9 @@ function registerGetter (store, type, rawGetter, local) {
|
|
|
|
|
|
function enableStrictMode (store) {
|
|
|
store._vm.$watch(function () { return this._data.$$state }, () => {
|
|
|
- assert(store._committing, `Do not mutate vuex store state outside mutation handlers.`)
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(store._committing, `Do not mutate vuex store state outside mutation handlers.`)
|
|
|
+ }
|
|
|
}, { deep: true, sync: true })
|
|
|
}
|
|
|
|
|
@@ -416,13 +434,15 @@ function unifyObjectStyle (type, payload, options) {
|
|
|
type = type.type
|
|
|
}
|
|
|
|
|
|
- assert(typeof type === 'string', `Expects string as the type, but found ${typeof type}.`)
|
|
|
+ if (process.env.NODE_ENV !== 'production') {
|
|
|
+ assert(typeof type === 'string', `Expects string as the type, but found ${typeof type}.`)
|
|
|
+ }
|
|
|
|
|
|
return { type, payload, options }
|
|
|
}
|
|
|
|
|
|
export function install (_Vue) {
|
|
|
- if (Vue) {
|
|
|
+ if (process.env.NODE_ENV !== 'production' && Vue) {
|
|
|
console.error(
|
|
|
'[vuex] already installed. Vue.use(Vuex) should be called only once.'
|
|
|
)
|