Explorar o código

fix env check position to avoid possible breakage of current behavior

ktsn %!s(int64=8) %!d(string=hai) anos
pai
achega
7409d4f6aa
Modificáronse 2 ficheiros con 25 adicións e 18 borrados
  1. 7 8
      src/module/module-collection.js
  2. 18 10
      src/store.js

+ 7 - 8
src/module/module-collection.js

@@ -66,14 +66,13 @@ function update (path, targetModule, newModule) {
   // update nested modules
   if (newModule.modules) {
     for (const key in newModule.modules) {
-      if (
-        process.env.NODE_ENV !== 'production' &&
-        !targetModule.getChild(key)
-      ) {
-        console.warn(
-          `[vuex] trying to add a new module '${key}' on hot reloading, ` +
-          'manual reload is needed'
-        )
+      if (!targetModule.getChild(key)) {
+        if (process.env.NODE_ENV !== 'production') {
+          console.warn(
+            `[vuex] trying to add a new module '${key}' on hot reloading, ` +
+            'manual reload is needed'
+          )
+        }
         return
       }
       update(

+ 18 - 10
src/store.js

@@ -81,8 +81,10 @@ export class Store {
 
     const mutation = { type, payload }
     const entry = this._mutations[type]
-    if (process.env.NODE_ENV !== 'production' && !entry) {
-      console.error(`[vuex] unknown mutation type: ${type}`)
+    if (!entry) {
+      if (process.env.NODE_ENV !== 'production') {
+        console.error(`[vuex] unknown mutation type: ${type}`)
+      }
       return
     }
     this._withCommit(() => {
@@ -111,8 +113,10 @@ export class Store {
     } = unifyObjectStyle(_type, _payload)
 
     const entry = this._actions[type]
-    if (process.env.NODE_ENV !== 'production' && !entry) {
-      console.error(`[vuex] unknown action type: ${type}`)
+    if (!entry) {
+      if (process.env.NODE_ENV !== 'production') {
+        console.error(`[vuex] unknown action type: ${type}`)
+      }
       return
     }
     return entry.length > 1
@@ -399,8 +403,10 @@ function registerAction (store, type, handler, local) {
 }
 
 function registerGetter (store, type, rawGetter, local) {
-  if (process.env.NODE_ENV !== 'production' && store._wrappedGetters[type]) {
-    console.error(`[vuex] duplicate getter key: ${type}`)
+  if (store._wrappedGetters[type]) {
+    if (process.env.NODE_ENV !== 'production') {
+      console.error(`[vuex] duplicate getter key: ${type}`)
+    }
     return
   }
   store._wrappedGetters[type] = function wrappedGetter (store) {
@@ -442,10 +448,12 @@ function unifyObjectStyle (type, payload, options) {
 }
 
 export function install (_Vue) {
-  if (process.env.NODE_ENV !== 'production' && Vue) {
-    console.error(
-      '[vuex] already installed. Vue.use(Vuex) should be called only once.'
-    )
+  if (Vue) {
+    if (process.env.NODE_ENV !== 'production') {
+      console.error(
+        '[vuex] already installed. Vue.use(Vuex) should be called only once.'
+      )
+    }
     return
   }
   Vue = _Vue